Module: QueryableWith::ClassMethods
- Defined in:
- lib/queryable_with.rb
Instance Method Summary collapse
-
#query_set(set_name, options = {}, &block) ⇒ Object
Defines a query set with the given name.
-
#query_sets ⇒ Object
:nodoc:.
Instance Method Details
#query_set(set_name, options = {}, &block) ⇒ Object
Defines a query set with the given name. This has the effect of defining a method that calls every implicit or explicit scope added to that query set.
When a block is given, that block is evaluated in the context of either a newly-created query set or (in the case of inherited classes) the pre-existing set of that name. See QueryableWith::QuerySet#queryable_with and QueryableWith::QuerySet#add_scope for more details.
When parent
is given as an option, the new query set will inherit all of the scopes from the named parent.
26 27 28 29 30 31 32 33 34 |
# File 'lib/queryable_with.rb', line 26 def query_set(set_name, ={}, &block) # :yields: set = query_set_for(set_name, ).tap { |s| s.instance_eval(&block) if block_given? } class_eval <<-RUBY def self.#{set_name}(params={}) self.query_sets["#{set_name}"].query(self, params) end RUBY end |
#query_sets ⇒ Object
:nodoc:
13 14 15 |
# File 'lib/queryable_with.rb', line 13 def query_sets # :nodoc: read_inheritable_attribute(:query_sets) || write_inheritable_hash(:query_sets, {}) end |