Class: Bsm::Constrainable::FilterSet
- Inherits:
-
Hash
- Object
- Hash
- Bsm::Constrainable::FilterSet
- Includes:
- Util
- Defined in:
- lib/bsm/constrainable/filter_set.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#initialize(schema, params = {}) ⇒ FilterSet
constructor
A new instance of FilterSet.
- #merge(scoped) ⇒ Object
- #respond_to?(sym) ⇒ Boolean
Methods included from Util
#normalized_array, #normalized_hash
Constructor Details
#initialize(schema, params = {}) ⇒ FilterSet
Returns a new instance of FilterSet.
6 7 8 9 10 11 12 13 |
# File 'lib/bsm/constrainable/filter_set.rb', line 6 def initialize(schema, params = {}) @schema = schema normalized_hash(params).each do |key, value| name, op = key.split('__') update(key => value) if valid_operation?(name, op) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object (private)
32 33 34 35 36 37 38 39 |
# File 'lib/bsm/constrainable/filter_set.rb', line 32 def method_missing(sym, *args) name, op = sym.to_s.split('__') if valid_operation?(name, op) self[sym.to_s] else super end end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
4 5 6 |
# File 'lib/bsm/constrainable/filter_set.rb', line 4 def schema @schema end |
Instance Method Details
#merge(scoped) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/bsm/constrainable/filter_set.rb', line 15 def merge(scoped) each do |key, value| name, op = key.split('__') schema[name].each do |field| scoped = field.merge(scoped, op, value) end end scoped end |
#respond_to?(sym) ⇒ Boolean
25 26 27 28 |
# File 'lib/bsm/constrainable/filter_set.rb', line 25 def respond_to?(sym, *) name, op = sym.to_s.split('__') super || valid_operation?(name, op) end |