Module: DirtySeed::MethodMissingHelper
- Included in:
- Association, Attribute, Model
- Defined in:
- lib/dirty_seed/method_missing_helper.rb
Overview
Forwards missing method to another object if it matches
Instance Method Summary collapse
-
#define_addressee(addressee_key) ⇒ void
Defines addressee method.
-
#define_method_missing ⇒ void
Defines missing_method method so it returns the adressee or calls super.
-
#define_respond_to_missing? ⇒ void
Defines respond_to_missing? method to matches the method_missing behavior.
-
#forward_missing_methods_to(addressee_key) ⇒ Object
Defines missing_method and respond_to_missing? methods.
Instance Method Details
#define_addressee(addressee_key) ⇒ void
This method returns an undefined value.
Defines addressee method
19 20 21 22 23 |
# File 'lib/dirty_seed/method_missing_helper.rb', line 19 def define_addressee(addressee_key) define_method :addressee do public_send(addressee_key) end end |
#define_method_missing ⇒ void
This method returns an undefined value.
Defines missing_method method so it returns the adressee or calls super
29 30 31 32 33 34 35 |
# File 'lib/dirty_seed/method_missing_helper.rb', line 29 def define_method_missing define_method :method_missing do |method_name, *args, &block| return super(method_name, *args, &block) unless addressee.respond_to?(method_name) addressee.public_send(method_name, *args, &block) end end |
#define_respond_to_missing? ⇒ void
This method returns an undefined value.
Defines respond_to_missing? method to matches the method_missing behavior
39 40 41 42 43 44 45 46 47 |
# File 'lib/dirty_seed/method_missing_helper.rb', line 39 def define_respond_to_missing? define_method :respond_to_missing? do |method_name, _include_private = false| # :nocov: return super(method_name, _include_private = false) unless addressee.respond_to?(method_name) true # :nocov: end end |
#forward_missing_methods_to(addressee_key) ⇒ Object
Defines missing_method and respond_to_missing? methods
10 11 12 13 14 |
# File 'lib/dirty_seed/method_missing_helper.rb', line 10 def forward_missing_methods_to(addressee_key) define_addressee(addressee_key) define_method_missing define_respond_to_missing? end |