Module: Simple::Service::ClassMethods
- Defined in:
- lib/simple/service.rb
Instance Method Summary collapse
- #actions ⇒ Object
- #build_service_instance ⇒ Object
- #call(action_name, arguments, params, context: nil) ⇒ Object
- #fetch_action(action_name) ⇒ Object
Instance Method Details
#actions ⇒ Object
27 28 29 |
# File 'lib/simple/service.rb', line 27 def actions @actions ||= Action.build_all(service_module: self) end |
#build_service_instance ⇒ Object
31 32 33 34 35 |
# File 'lib/simple/service.rb', line 31 def build_service_instance service_instance = Object.new service_instance.extend self service_instance end |
#call(action_name, arguments, params, context: nil) ⇒ Object
44 45 46 47 48 |
# File 'lib/simple/service.rb', line 44 def call(action_name, arguments, params, context: nil) ::Simple::Service.with_context(context) do fetch_action(action_name).invoke(arguments, params) end end |
#fetch_action(action_name) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/simple/service.rb', line 37 def fetch_action(action_name) actions.fetch(action_name) do informal = "service #{self} has these actions: #{actions.keys.sort.map(&:inspect).join(", ")}" raise "No such action #{action_name.inspect}; #{informal}" end end |