Module: ClassAction::ClassMethods
- Defined in:
- lib/class_action.rb
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 Method Details
#class_action(*actions, klass: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/class_action.rb', line 25 def class_action(*actions, klass: nil) actions.each do |action| action_class = klass || const_get("#{action.to_s.camelize}Action") raise ArgumentError, "ClassAction does not support anonymous classes" if action_class.name.nil? class_eval <<-RUBY, __FILE__, __LINE__+1 def _#{action}_action_class @_class_action ||= #{action_class.name}.new self end private :_#{action}_action_class def #{action} _#{action}_action_class._execute end RUBY inject_class_action_mimes action.to_s, action_class end end |
#class_action_delegate(*methods) ⇒ Object
Delegates the given method to the current class action.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/class_action.rb', line 46 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(<<-RUBY, file, line) def #{method}(#{definition}) _class_action.send :#{method}, #{definition} end RUBY end end |