Class: AuxiliaryRails::Application::Query Abstract
- Inherits:
-
Object
- Object
- AuxiliaryRails::Application::Query
- Extended by:
- Dry::Core::ClassAttributes, Dry::Initializer
- Includes:
- Concerns::Callable, Concerns::Errorable
- Defined in:
- lib/auxiliary_rails/application/query.rb
Overview
This class is abstract.
Instance Method Summary collapse
- #call ⇒ Object
-
#ensure_proper_relation_types! ⇒ Object
private
rubocop:disable Style/GuardClause.
- #method_missing(method_name, *args, &block) ⇒ Object
- #perform ⇒ Object abstract
-
#queriable_object?(object) ⇒ Boolean
private
rubocop:enable Style/GuardClause.
- #query(scoped_query = nil) ⇒ Object private
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Methods included from Concerns::Errorable
Methods included from Concerns::Callable
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
36 37 38 39 40 |
# File 'lib/auxiliary_rails/application/query.rb', line 36 def method_missing(method_name, *args, &block) super unless query.respond_to?(method_name) query.send(method_name, *args, &block) end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/auxiliary_rails/application/query.rb', line 19 def call ensure_proper_relation_types! perform if !queriable_object?(query) error!('Invalid class of resulted query') end query end |
#ensure_proper_relation_types! ⇒ Object (private)
rubocop:disable Style/GuardClause
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/auxiliary_rails/application/query.rb', line 49 def ensure_proper_relation_types! if self.class.default_relation.nil? error!('Undefined `default_relation`') end if !queriable_object?(self.class.default_relation) error!('Invalid class of `default_relation`') end if !relation.nil? && !queriable_object?(relation) error!('Invalid class of `relation` option') end end |
#perform ⇒ Object
This method is abstract.
32 33 34 |
# File 'lib/auxiliary_rails/application/query.rb', line 32 def perform raise NotImplementedError end |
#queriable_object?(object) ⇒ Boolean (private)
rubocop:enable Style/GuardClause
62 63 64 |
# File 'lib/auxiliary_rails/application/query.rb', line 62 def queriable_object?(object) object.is_a?(ActiveRecord::Relation) end |
#query(scoped_query = nil) ⇒ Object (private)
66 67 68 69 70 71 72 |
# File 'lib/auxiliary_rails/application/query.rb', line 66 def query(scoped_query = nil) @query ||= (relation || self.class.default_relation) @query = scoped_query unless scoped_query.nil? @query end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
42 43 44 |
# File 'lib/auxiliary_rails/application/query.rb', line 42 def respond_to_missing?(method_name, include_private = false) query.respond_to?(method_name) || super end |