Module: ClassAction::ClassMethods
- Defined in:
- lib/class_action.rb
Instance Attribute Summary collapse
-
#action_load_path ⇒ Object
Returns the value of attribute action_load_path.
Instance Method Summary collapse
- #class_action(*actions, klass: nil) ⇒ Object
-
#class_action_delegate(*methods) ⇒ Object
Delegates the given method to the current class action.
Instance Attribute Details
#action_load_path ⇒ Object
Returns the value of attribute action_load_path.
26 27 28 |
# File 'lib/class_action.rb', line 26 def action_load_path @action_load_path end |
Instance Method Details
#class_action(*actions, klass: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/class_action.rb', line 28 def class_action(*actions, klass: nil) actions.each do |action| action_class = klass || find_action_class(action) raise ArgumentError, "ClassAction does not support anonymous classes" if action_class.name.nil? class_eval " def _\#{action}_action_class\n @_class_action ||= \#{action_class.name}.new self\n end\n private :_\#{action}_action_class\n\n def \#{action}\n _\#{action}_action_class._execute\n end\n RUBY\n\n inject_class_action_mimes action.to_s, action_class\n end\nend\n", __FILE__, __LINE__+1 |
#class_action_delegate(*methods) ⇒ Object
Delegates the given method to the current class action.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/class_action.rb', line 49 def class_action_delegate(*methods) file, line = caller.first.split(':', 2) line = line.to_i methods.each do |method| definition = (method =~ /[^\]]=$/) ? 'arg' : '*args, &block' module_eval(" def \#{method}(\#{definition})\n _class_action.send :\#{method}, \#{definition}\n end\n RUBY\n end\nend\n", file, line) |