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.
-
#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:) ⇒ ApiBlock
constructor
A new instance of ApiBlock.
- #present?(value) ⇒ Boolean
- #values_for(params) ⇒ Object
Constructor Details
#initialize(presence_fields:, value_fields:, block:) ⇒ 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:) = (value_fields) @presence_fields, @value_fields, @block = presence_fields, value_fields, block 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 |
#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 |
# File 'lib/parascope/query/api_block.rb', line 15 def fits?(query) return false unless conditions_met_by?(query) (presence_fields.size == 0 && value_fields.size == 0) || values_for(query.params).all?{ |value| present?(value) } end |
#index ⇒ Object
30 31 32 |
# File 'lib/parascope/query/api_block.rb', line 30 def index [:index] || 0 end |
#present?(value) ⇒ Boolean
26 27 28 |
# File 'lib/parascope/query/api_block.rb', line 26 def present?(value) value.respond_to?(:empty?) ? !value.empty? : !!value end |
#values_for(params) ⇒ Object
22 23 24 |
# File 'lib/parascope/query/api_block.rb', line 22 def values_for(params) params.values_at(*presence_fields) + valued_values_for(params) end |