Class: Bitmasker::BitmaskScope
- Inherits:
-
Object
- Object
- Bitmasker::BitmaskScope
- Includes:
- ActiveModel::AttributeMethods
- Defined in:
- lib/bitmasker/bitmask_scope.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bitmask(mask = 0) ⇒ Object
- #with_any_attribute(_, *attributes) ⇒ Object
-
#with_attribute(_, *attributes) ⇒ Object
REVIEW: This (the unused _ attribute) tells me I have the design wrong.
- #without_attribute(_, *attributes) ⇒ Object
Class Method Details
.make(model_class, field_name, mask_name, bitmask_attributes) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bitmasker/bitmask_scope.rb', line 14 def self.make(model_class, field_name, mask_name, bitmask_attributes) klass = Class.new(self) do define_attribute_methods [mask_name] def self.to_s "#{superclass}(#{model_class}##{field_name})" end end klass.model_class = model_class klass.table_name = model_class.table_name klass.field_name = field_name klass.mask_name = mask_name klass.bitmask_attributes = bitmask_attributes.stringify_keys klass end |
Instance Method Details
#bitmask(mask = 0) ⇒ Object
32 33 34 |
# File 'lib/bitmasker/bitmask_scope.rb', line 32 def bitmask(mask = 0) Bitmask.new(bitmask_attributes, mask) end |
#with_any_attribute(_, *attributes) ⇒ Object
42 43 44 45 |
# File 'lib/bitmasker/bitmask_scope.rb', line 42 def with_any_attribute(_, *attributes) # TODO: Test lots of databases bitmask_query attributes, "#{table_name}.#{field_name} & :mask <> 0" end |
#with_attribute(_, *attributes) ⇒ Object
REVIEW: This (the unused _ attribute) tells me I have the design wrong
37 38 39 40 |
# File 'lib/bitmasker/bitmask_scope.rb', line 37 def with_attribute(_, *attributes) # TODO: Test lots of databases bitmask_query attributes, "#{table_name}.#{field_name} & :mask = :mask" end |
#without_attribute(_, *attributes) ⇒ Object
47 48 49 50 |
# File 'lib/bitmasker/bitmask_scope.rb', line 47 def without_attribute(_, *attributes) # TODO: Test lots of databases bitmask_query attributes, "#{table_name}.#{field_name} & :mask = 0 OR #{table_name}.#{field_name} IS NULL" end |