Class: Whiteprint::AttributeScope
- Inherits:
-
Object
- Object
- Whiteprint::AttributeScope
- Defined in:
- lib/whiteprint/attributes.rb
Instance Method Summary collapse
- #filter ⇒ Object
-
#initialize(scope, model: nil) ⇒ AttributeScope
constructor
A new instance of AttributeScope.
- #not(*keys, **conditions) ⇒ Object
- #where(*keys, **conditions) ⇒ Object
Constructor Details
#initialize(scope, model: nil) ⇒ AttributeScope
Returns a new instance of AttributeScope.
75 76 77 78 79 80 |
# File 'lib/whiteprint/attributes.rb', line 75 def initialize(scope, model: nil) @scope = scope @model = model @selects = [] @rejects = [] end |
Instance Method Details
#filter ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/whiteprint/attributes.rb', line 96 def filter select = proc { |scope, condition| scope.select(&condition) } reject = proc { |scope, condition| scope.reject(&condition) } scope = @selects.inject(@scope, &select) @rejects.inject(scope, &reject) end |
#not(*keys, **conditions) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/whiteprint/attributes.rb', line 89 def not(*keys, **conditions) @rejects << proc do |_, attribute| attribute.has?(*keys, **conditions) end Attributes.new(filter, model: @model) end |
#where(*keys, **conditions) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/whiteprint/attributes.rb', line 82 def where(*keys, **conditions) @selects << proc do |_, attribute| attribute.has?(*keys, **conditions) end Attributes.new(filter, model: @model) end |