Class: Parascope::Query::ApiBlock
- Inherits:
-
Object
- Object
- Parascope::Query::ApiBlock
- Defined in:
- lib/parascope/query/api_block.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#presence_fields ⇒ Object
readonly
Returns the value of attribute presence_fields.
-
#value_fields ⇒ Object
readonly
Returns the value of attribute value_fields.
Instance Method Summary collapse
- #fits?(query) ⇒ Boolean
- #index ⇒ Object
-
#initialize(presence_fields:, value_fields:, block:, force: false) ⇒ ApiBlock
constructor
A new instance of ApiBlock.
- #present?(value) ⇒ Boolean
- #values_for(params) ⇒ Object
Constructor Details
#initialize(presence_fields:, value_fields:, block:, force: false) ⇒ ApiBlock
Returns a new instance of ApiBlock.
8 9 10 11 12 13 |
# File 'lib/parascope/query/api_block.rb', line 8 def initialize(presence_fields:, value_fields:, block:, force: false) = (value_fields) @presence_fields, @value_fields, @block, @force = presence_fields, value_fields, block, force end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/parascope/query/api_block.rb', line 6 def block @block end |
#force ⇒ Object (readonly)
Returns the value of attribute force.
6 7 8 |
# File 'lib/parascope/query/api_block.rb', line 6 def force @force end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/parascope/query/api_block.rb', line 6 def end |
#presence_fields ⇒ Object (readonly)
Returns the value of attribute presence_fields.
6 7 8 |
# File 'lib/parascope/query/api_block.rb', line 6 def presence_fields @presence_fields end |
#value_fields ⇒ Object (readonly)
Returns the value of attribute value_fields.
6 7 8 |
# File 'lib/parascope/query/api_block.rb', line 6 def value_fields @value_fields end |
Instance Method Details
#fits?(query) ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/parascope/query/api_block.rb', line 15 def fits?(query) return false unless conditions_met_by?(query) return true if force (presence_fields.size == 0 && value_fields.size == 0) || values_for(query.params).all?{ |value| present?(value) } end |
#index ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/parascope/query/api_block.rb', line 31 def index case [:index] when :first then -Float::INFINITY when :last then Float::INFINITY when Numeric then [:index] else 0 end end |
#present?(value) ⇒ Boolean
27 28 29 |
# File 'lib/parascope/query/api_block.rb', line 27 def present?(value) value.respond_to?(:empty?) ? !value.empty? : !!value end |
#values_for(params) ⇒ Object
23 24 25 |
# File 'lib/parascope/query/api_block.rb', line 23 def values_for(params) params.values_at(*presence_fields) + valued_values_for(params) end |