Module: Controll::Enabler::Macros::ClassMethods
- Defined in:
- lib/controll/enabler/macros.rb
Instance Method Summary collapse
- #assistant(name, options = {}) ⇒ Object
- #assistant_methods(*names) ⇒ Object
-
#commander(name, options = {}) ⇒ Object
TODO: refactor - all use exactly the same pattern - can be generated!.
-
#controll(*artifacts) ⇒ Object
on Controller: - fx Admin::ServicesController -> :services On Focused Controller action: - fx Admin::ServicesController::Update -> :update_services.
- #flow(name, options = {}) ⇒ Object
- #name_of(clazz) ⇒ Object
- #notifier(name, options = {}) ⇒ Object
Instance Method Details
#assistant(name, options = {}) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/controll/enabler/macros.rb', line 58 def assistant name, = {} define_method :assistant do unless instance_variable_get("@assistant") clazz = "Assistants::#{name.to_s.camelize}".constantize instance_variable_set "@assistant", clazz.new(self, ) end end end |
#assistant_methods(*names) ⇒ Object
67 68 69 70 71 |
# File 'lib/controll/enabler/macros.rb', line 67 def assistant_methods *names = names. assistant = [:to] || :assistant delegate names, to: assistant end |
#commander(name, options = {}) ⇒ Object
TODO: refactor - all use exactly the same pattern - can be generated!
31 32 33 34 35 36 37 38 |
# File 'lib/controll/enabler/macros.rb', line 31 def commander name, = {} define_method :commander do instance_variable_get("@commander") || begin clazz = "Commanders::#{name.to_s.camelize}".constantize instance_variable_set "@commander", clazz.new(self, ) end end end |
#controll(*artifacts) ⇒ Object
on Controller:
- fx Admin::ServicesController -> :services
On Focused Controller action:
- fx Admin::ServicesController::Update -> :update_services
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/controll/enabler/macros.rb', line 12 def controll *artifacts def name_of clazz clazz = clazz.to_s if clazz =~ /Controller$/ clazz.sub(/Controller$/, '').split('::').last.underscore else parts = clazz.sub(/Controller/, '').split('::') (parts.pop << parts.last).underscore end end = artifacts. name = name_of self.class artifacts.each do |artifact| send(artifact, name, ) end end |
#flow(name, options = {}) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/controll/enabler/macros.rb', line 49 def flow name, = {} define_method :flow do unless instance_variable_get("@flow") clazz = "Flows::#{name.to_s.camelize}".constantize instance_variable_set "@flow", clazz.new(self, ) end end end |
#name_of(clazz) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/controll/enabler/macros.rb', line 13 def name_of clazz clazz = clazz.to_s if clazz =~ /Controller$/ clazz.sub(/Controller$/, '').split('::').last.underscore else parts = clazz.sub(/Controller/, '').split('::') (parts.pop << parts.last).underscore end end |
#notifier(name, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/controll/enabler/macros.rb', line 40 def notifier name, = {} define_method :notifier do instance_variable_get("@notifier") || begin clazz = "Notifiers::#{name.to_s.camelize}".constantize instance_variable_set "@notifier", clazz.new(self, ) end end end |