Class: SimpleService::Organizer
- Inherits:
-
Object
- Object
- SimpleService::Organizer
- Extended by:
- ServiceBase::ClassMethods
- Includes:
- ServiceBase::InstanceMethods
- Defined in:
- lib/simple_service/organizer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Class Method Summary collapse
-
.call(context = {}) ⇒ Object
allow execution of the service from the class level for those that prefer that style.
- .commands(*args) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
- #commands ⇒ Object
-
#initialize(context = {}) ⇒ Organizer
constructor
A new instance of Organizer.
Methods included from ServiceBase::ClassMethods
expects, returns, skip_validation
Methods included from ServiceBase::InstanceMethods
#all_context_keys, #define_getters_and_setters, #expects, #failure!, #find_specified_return_keys, #return_context_with_success_status, #returns, #setup_call_chain, #skip_validation, #symbolize_context_keys
Constructor Details
#initialize(context = {}) ⇒ Organizer
Returns a new instance of Organizer.
9 10 11 12 13 14 15 |
# File 'lib/simple_service/organizer.rb', line 9 def initialize(context = {}) @context = context symbolize_context_keys setup_call_chain define_getters_and_setters end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/simple_service/organizer.rb', line 7 def context @context end |
Class Method Details
.call(context = {}) ⇒ Object
allow execution of the service from the class level for those that prefer that style
37 38 39 |
# File 'lib/simple_service/organizer.rb', line 37 def self.call(context = {}) self.new(context).call end |
.commands(*args) ⇒ Object
17 18 19 |
# File 'lib/simple_service/organizer.rb', line 17 def self.commands(*args) @commands = args end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_service/organizer.rb', line 25 def call with_validation do |_commands| _commands.each do |command| break if context[:success] == false new_context = command.new(context).call @context.merge!(new_context) end end end |
#commands ⇒ Object
21 22 23 |
# File 'lib/simple_service/organizer.rb', line 21 def commands self.class.instance_variable_get('@commands') end |