Class: Yaso::Service

Inherits:
Object
  • Object
show all
Extended by:
Stepable
Defined in:
lib/yaso/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Stepable

failure, steps

Constructor Details

#initialize(context) ⇒ Service

Returns a new instance of Service.



7
8
9
10
# File 'lib/yaso/service.rb', line 7

def initialize(context)
  @context = context
  @success = true
end

Instance Attribute Details

#success=(value) ⇒ Object (writeonly)

Sets the attribute success

Parameters:

  • value

    the value to set the attribute success to.



5
6
7
# File 'lib/yaso/service.rb', line 5

def success=(value)
  @success = value
end

Class Method Details

.call(context = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/yaso/service.rb', line 37

def call(context = {})
  @entry ||= flow.call(self, steps)
  step = @entry
  instance = new(context)
  step = step.call(context, instance) while step
  instance
end

.flow(name = nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/yaso/service.rb', line 45

def flow(name = nil)
  @flow ||= Flows::MAP[:classic] if self == Yaso::Service
  return @flow || Yaso::Service.flow if name.nil?

  @flow = Flows::MAP[name] || raise(UnknownFlowError.new(self, name))
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/yaso/service.rb', line 12

def [](key)
  @context[key]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/yaso/service.rb', line 16

def []=(key, value)
  @context[key] = value
end

#failure?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/yaso/service.rb', line 24

def failure?
  !@success
end

#inspectObject



32
33
34
# File 'lib/yaso/service.rb', line 32

def inspect
  "Result:#{self.class} successful: #{@success}, context: #{@context}"
end

#success?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/yaso/service.rb', line 20

def success?
  @success
end

#to_hObject



28
29
30
# File 'lib/yaso/service.rb', line 28

def to_h
  @context.dup
end