Module: Pluckr::Schema::Conditions
Overview
where: on an aggregate or existence node.
A Hash is validated once, when the schema is defined, and is therefore
frozen at load time - where: { created_at: 1.week.ago.. } would keep
asking about the week before boot, forever.
A callable is invoked on every compilation instead, so runtime values stay runtime values:
count :recent_orders, from: Order, where: -> { { created_at: 1.week.ago.. } }
Instance Method Summary collapse
- #dynamic_where? ⇒ Boolean
-
#resolved_where ⇒ Hash?
The conditions to apply to this compilation.
Instance Method Details
#dynamic_where? ⇒ Boolean
16 17 18 |
# File 'lib/pluckr/schema/conditions.rb', line 16 def dynamic_where? where.respond_to?(:call) end |
#resolved_where ⇒ Hash?
Returns the conditions to apply to this compilation.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pluckr/schema/conditions.rb', line 21 def resolved_where return where unless dynamic_where? conditions = where.call unless conditions.is_a?(Hash) raise ConfigurationError, "`#{output}`: a `where:` lambda must return a Hash of column => value, " \ "got #{conditions.inspect}" end conditions.each_key { |key| validate_column!(key) } conditions end |