Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

act_with_booleans

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

act_with_booleans

  • 0.0.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ActWithBooleans

Gem Version GEM Downloads rake Ruby Style Guide MIT License

A Ruby gem handling booleans placed in an integer.

Defines setters and getters to access the booleans.

Installation

As usual:

# Gemfile
gem "act_with_booleans"

and run "bundle install".

Examples

Simple Example

#require "act_with_booleans"

class Foo
  include ActWithBooleans
  attr_accessor :booleans

  add_to_booleans :x, :y
end

foo = Foo.new
foo.x    # --> false
foo.x = true
foo.x    # --> true
foo.x?   # --> true
Foo.booleans_mask(:x, :y) # 3 (0x03)

Example Using Position

class Foo
  add_to_booleans z: 10
end

Foo.booleans_mask(:z) # 1024 (0x400 or 2 ** 10)

Additional Functions

foo.x = true
foo.y = false
foo.booleans_any?(:x, :y)  # true
foo.booleans_all?(:x, :y)  # false
foo.booleans_none?(:x, :y) # false

Using a Non Default Origin

#require "act_with_booleans"

class Foo
  include ActWithBooleans
  attr_accessor :flags

  add_to_booleans :x, :y, origin: :flags
end

foo = Foo.new
foo.x    # --> false

Internals

Foo.act_with_booleans.size # 11
Foo.act_with_booleans.position(:y) # 1
Foo.act_with_booleans.to_s

Rails

ActWithBooleans is PORO, i.e. it can and, usually, will be used in Rails.

The "origin" (default :booleans) is an integer containing the booleans.

Ruby supports pretty large integers, but your database has limitations. Therefore, it is strongly recommended to validate accordingly the "origin" in the model.

Testing

As "Best Practice" a test coverage of 100% has been achieved (and should be kept).

GitHub workflow enable tests for several configurations. Please, feel free to inspect the corresponding file.

Further reading:

Miscellaneous

Copyright (c) 2023-2024 Dittmar Krall (www.matiq.com), released under the MIT license.

FAQs

Package last updated on 19 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc