Module: LightService::Organizer::ClassMethods

Defined in:
lib/light-service/organizer.rb

Overview

In case this module is included

Instance Method Summary collapse

Instance Method Details

#add_aliases(args) ⇒ Object



89
90
91
# File 'lib/light-service/organizer.rb', line 89

def add_aliases(args)
  execute(->(ctx) { ctx.assign_aliases(ctx.aliases.merge(args)) })
end

#add_to_context(args) ⇒ Object

Set the value as a key on the context hash and also create convenience accessors for the keys



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/light-service/organizer.rb', line 76

def add_to_context(args)
  Context::ReservedKeysViaOrganizerVerifier.new(args).verify

  Hash(args).map do |key, value|
    context_key = lambda do |ctx|
      ctx[key.to_sym] = value
      ctx.define_accessor_methods_for_keys(key)
    end

    execute(context_key)
  end
end

#execute(code_block) ⇒ Object



58
59
60
# File 'lib/light-service/organizer.rb', line 58

def execute(code_block)
  Execute.run(code_block)
end

#iterate(collection_key, steps) ⇒ Object



54
55
56
# File 'lib/light-service/organizer.rb', line 54

def iterate(collection_key, steps)
  Iterate.run(self, collection_key, steps)
end

#log_with(logger) ⇒ Object



66
67
68
# File 'lib/light-service/organizer.rb', line 66

def log_with(logger)
  @logger = logger
end

#loggerObject



70
71
72
# File 'lib/light-service/organizer.rb', line 70

def logger
  @logger
end

#reduce(*actions) ⇒ Object



34
35
36
# File 'lib/light-service/organizer.rb', line 34

def reduce(*actions)
  with({}).reduce(actions)
end

#reduce_case(**args) ⇒ Object



50
51
52
# File 'lib/light-service/organizer.rb', line 50

def reduce_case(**args)
  ReduceCase.run(self, **args)
end

#reduce_if(condition_block, steps) ⇒ Object



38
39
40
# File 'lib/light-service/organizer.rb', line 38

def reduce_if(condition_block, steps)
  ReduceIf.run(self, condition_block, steps)
end

#reduce_if_else(condition_block, if_steps, else_steps) ⇒ Object



42
43
44
# File 'lib/light-service/organizer.rb', line 42

def reduce_if_else(condition_block, if_steps, else_steps)
  ReduceIfElse.run(self, condition_block, if_steps, else_steps)
end

#reduce_until(condition_block, steps) ⇒ Object



46
47
48
# File 'lib/light-service/organizer.rb', line 46

def reduce_until(condition_block, steps)
  ReduceUntil.run(self, condition_block, steps)
end

#with(data = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/light-service/organizer.rb', line 17

def with(data = {})
  VerifyCallMethodExists.run(self, caller(1..1).first)
  data[:_aliases] = @aliases if @aliases

  if @before_actions
    data[:_before_actions] = @before_actions.dup
    @before_actions = nil
  end

  if @after_actions
    data[:_after_actions] = @after_actions.dup
    @after_actions = nil
  end

  WithReducerFactory.make(self).with(data)
end

#with_callback(action, steps) ⇒ Object



62
63
64
# File 'lib/light-service/organizer.rb', line 62

def with_callback(action, steps)
  WithCallback.run(self, action, steps)
end