Class: SimpleService::Organizer

Inherits:
Object
  • Object
show all
Extended by:
ServiceBase::ClassMethods
Includes:
ServiceBase::InstanceMethods
Defined in:
lib/simple_service/organizer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ServiceBase::ClassMethods

expects, returns

Methods included from ServiceBase::InstanceMethods

#expects, #find_specified_return_keys, #returns, #setup_execute_chain

Constructor Details

#initialize(context = {}) ⇒ Organizer

Returns a new instance of Organizer.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/simple_service/organizer.rb', line 9

def initialize(context={})
  @context = context

  ArgumentValidator.new(
    context: context,
    expects: expects,
    returns: returns,
    commands: commands
  ).execute

  setup_execute_chain
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



7
8
9
# File 'lib/simple_service/organizer.rb', line 7

def context
  @context
end

Class Method Details

.commands(*args) ⇒ Object



22
23
24
# File 'lib/simple_service/organizer.rb', line 22

def self.commands(*args)
  @commands = args
end

Instance Method Details

#commandsObject



26
27
28
# File 'lib/simple_service/organizer.rb', line 26

def commands
  self.class.instance_variable_get('@commands')
end

#executeObject



30
31
32
33
34
# File 'lib/simple_service/organizer.rb', line 30

def execute
  commands.each do |command|
    @context.merge!(command.new(context).execute)
  end
end