Module: Babik::QuerySet::Clonable
- Included in:
- AbstractBase
- Defined in:
- lib/babik/queryset/mixins/clonable.rb
Overview
Clone operation for the QuerySet
Instance Method Summary collapse
-
#clone ⇒ QuerySet
Clone the queryset using ruby_deep_clone https://github.com/gmodarelli/ruby-deepclone.
-
#method_missing(name, *args, &_block) ⇒ QuerySet
Check if the called method has a modifying version (a bang method).
-
#mutate_clone(mutator_method, parameters = []) ⇒ QuerySet
Clone this QuerySet and apply the ‘mutator_method’ to it.
-
#respond_to_missing?(name, *_args, &_block) ⇒ Boolean
Check if the called method has a modifying version (a bang method).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &_block) ⇒ QuerySet
Check if the called method has a modifying version (a bang method). If that is the case it will be called on a clone of this instance. Otherwise, super will be called.
36 37 38 39 40 |
# File 'lib/babik/queryset/mixins/clonable.rb', line 36 def method_missing(name, *args, &_block) = "#{name}!" return mutate_clone(.to_sym, args) if self.respond_to?() super end |
Instance Method Details
#clone ⇒ QuerySet
Clone the queryset using ruby_deep_clone https://github.com/gmodarelli/ruby-deepclone.
12 13 14 |
# File 'lib/babik/queryset/mixins/clonable.rb', line 12 def clone DeepClone.clone(self) end |
#mutate_clone(mutator_method, parameters = []) ⇒ QuerySet
Clone this QuerySet and apply the ‘mutator_method’ to it.
20 21 22 23 24 25 26 27 28 |
# File 'lib/babik/queryset/mixins/clonable.rb', line 20 def mutate_clone(mutator_method, parameters = []) clone_ = clone if parameters.empty? clone_.send(mutator_method) else clone_.send(mutator_method, *parameters) end clone_ end |
#respond_to_missing?(name, *_args, &_block) ⇒ Boolean
Check if the called method has a modifying version (a bang method).
45 46 47 48 |
# File 'lib/babik/queryset/mixins/clonable.rb', line 45 def respond_to_missing?(name, *_args, &_block) = "#{name}!" self.respond_to?() end |