README.md in bitmask_enum-1.0.0 vs README.md in bitmask_enum-1.1.0
- old
+ new
@@ -8,10 +8,12 @@
Supporting Ruby 2.4+ and Rails 4.2+.
Credit is due to Joel Moss' gem [bitmask_attributes](https://github.com/joelmoss/bitmask_attributes). I came across it while considering if I should write a gem for this. It's great work and some elements of it inspired this gem, I just had my own thoughts about how I'd like the gem to operate, and wanted some more end-to-end experience on gem production so I decided to create this rather than pick up the torch on that repo.
+This gem attempts to improve performance by precomputing the integer values for the enum rather than using bitwise operations in the SQL.
+
## Installation
Add this line to your application's Gemfile:
```ruby
@@ -26,10 +28,12 @@
$ gem install bitmask_enum
## Usage
+[RubyDocs for BitmaskEnum](https://www.rubydoc.info/github/lucygilbert/bitmask_enum/master)
+
In the model, the bitmask enum is added in a similar way to enums. Given an integer attribute called `attribs`, flags of `flag` and `flag2`, adding the `flag_prefix` option with the value `type`, the following line would be used:
```ruby
bitmask_enum attribs: [:flag, :flag2], flag_prefix: 'type'
```
@@ -127,12 +131,14 @@
**Return value:** `array` - array of enabled flags. E.g. `[:flag_one, :flag_two]`
### `{attribute}=` (_Override_)
-**No params**
+**Params**
+- value [Integer, Symbol, String, Array\<Symbol, String\>] - An integer, a defined flag or array of defined flags
+
This method will be created once on the instance.
The method sets the attribute to the provided value - either an integer, a symbol or string representing a flag or an array of symbols or strings. This is the attribute setter.
This method will raise an ArgumentError if one of the flag values passed is not one that was defined.
@@ -158,9 +164,57 @@
**No params**
For each flag, this method will be created on the class.
The method is a scope of all records for which the flag is disabled.
+
+**Return value:** `ActiveRecord::Relation` - a collection of all records for which the flag is disabled.
+
+### `any_{attribute}_enabled`
+
+**Params**
+
+- flags [Symbol, String, Array\<Symbol, String\>] - A defined flag or array of defined flags
+
+This method will be created once on the class.
+
+The method is a scope of all records for which any of the provided flags are enabled.
+
+**Return value:** `ActiveRecord::Relation` - a collection of all records for which the flag is enabled.
+
+### `any_{attribute}_disabled`
+
+**Params**
+
+- flags [Symbol, String, Array\<Symbol, String\>] - A defined flag or array of defined flags
+
+This method will be created once on the class.
+
+The method is a scope of all records for which any of the provided flags are disabled.
+
+**Return value:** `ActiveRecord::Relation` - a collection of all records for which the flag is disabled.
+
+### `all_{attribute}_enabled`
+
+**Params**
+
+- flags [Symbol, String, Array\<Symbol, String\>] - A defined flag or array of defined flags
+
+This method will be created once on the class.
+
+The method is a scope of all records for which all of the provided flags are enabled.
+
+**Return value:** `ActiveRecord::Relation` - a collection of all records for which the flag is enabled.
+
+### `all_{attribute}_disabled`
+
+**Params**
+
+- flags [Symbol, String, Array\<Symbol, String\>] - A defined flag or array of defined flags
+
+This method will be created once on the class.
+
+The method is a scope of all records for which all of the provided flags are disabled.
**Return value:** `ActiveRecord::Relation` - a collection of all records for which the flag is disabled.
### `{attribute}`