Class: Banken::DSL::Proxy
- Inherits:
-
Object
- Object
- Banken::DSL::Proxy
- Defined in:
- lib/banken/dsl/proxy.rb
Constant Summary collapse
- PERMIT_ATTRIBUTES_METHOD_NAME =
"permitted_attributes".freeze
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
Instance Method Summary collapse
- #define_banken_permit_attributes_method(&block) ⇒ Object
- #define_banken_query_method_for(action_name, &block) ⇒ Object
-
#initialize(controller) ⇒ Proxy
constructor
A new instance of Proxy.
Constructor Details
#initialize(controller) ⇒ Proxy
Returns a new instance of Proxy.
8 9 10 |
# File 'lib/banken/dsl/proxy.rb', line 8 def initialize(controller) @controller = controller end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object (private)
36 37 38 39 40 41 42 43 44 |
# File 'lib/banken/dsl/proxy.rb', line 36 def method_missing(method_name, *arguments, &block) if action_method?(method_name) define_banken_query_method_for(method_name, &block) elsif permit_attributes_method?(method_name) define_banken_permit_attributes_method(&block) else raise ::Banken::DSL::UndefinedAction, "#{controller}##{method_name} is undefined" end end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
6 7 8 |
# File 'lib/banken/dsl/proxy.rb', line 6 def controller @controller end |
Instance Method Details
#define_banken_permit_attributes_method(&block) ⇒ Object
18 19 20 21 22 |
# File 'lib/banken/dsl/proxy.rb', line 18 def define_banken_permit_attributes_method(&block) banken_loyalty.class_eval do define_method(PERMIT_ATTRIBUTES_METHOD_NAME, &block) end end |
#define_banken_query_method_for(action_name, &block) ⇒ Object
12 13 14 15 16 |
# File 'lib/banken/dsl/proxy.rb', line 12 def define_banken_query_method_for(action_name, &block) banken_loyalty.class_eval do define_method("#{action_name}?", &block) end end |