Class: Zen::Query::ApiBlock
- Inherits:
-
Object
- Object
- Zen::Query::ApiBlock
- Defined in:
- lib/zen/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.
11 12 13 14 15 16 17 18 |
# File 'lib/zen/query/api_block.rb', line 11 def initialize(presence_fields:, value_fields:, block:, force: false) @options = (value_fields) @presence_fields = presence_fields @value_fields = value_fields @block = block @force = force end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
9 10 11 |
# File 'lib/zen/query/api_block.rb', line 9 def block @block end |
#force ⇒ Object (readonly)
Returns the value of attribute force.
9 10 11 |
# File 'lib/zen/query/api_block.rb', line 9 def force @force end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/zen/query/api_block.rb', line 9 def @options end |
#presence_fields ⇒ Object (readonly)
Returns the value of attribute presence_fields.
9 10 11 |
# File 'lib/zen/query/api_block.rb', line 9 def presence_fields @presence_fields end |
#value_fields ⇒ Object (readonly)
Returns the value of attribute value_fields.
9 10 11 |
# File 'lib/zen/query/api_block.rb', line 9 def value_fields @value_fields end |
Instance Method Details
#fits?(query) ⇒ Boolean
20 21 22 23 24 25 26 |
# File 'lib/zen/query/api_block.rb', line 20 def fits?(query) return false unless conditions_met_by?(query) return true if force (presence_fields.empty? && value_fields.empty?) || values_for(query.params).all? { |value| present?(value) } end |
#index ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/zen/query/api_block.rb', line 36 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
32 33 34 |
# File 'lib/zen/query/api_block.rb', line 32 def present?(value) value.respond_to?(:empty?) ? !value.empty? : !!value end |
#values_for(params) ⇒ Object
28 29 30 |
# File 'lib/zen/query/api_block.rb', line 28 def values_for(params) params.values_at(*presence_fields) + valued_values_for(params) end |