Class: SimpleLogicStep::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_logic_step.rb

Overview

Copy from here

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**ctx) ⇒ Service

Returns a new instance of Service.



14
15
16
17
18
19
# File 'lib/simple_logic_step.rb', line 14

def initialize(**ctx)
  @success = true
  @semantic = nil
  @ctx = ctx
  @message = nil
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



8
9
10
# File 'lib/simple_logic_step.rb', line 8

def ctx
  @ctx
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/simple_logic_step.rb', line 8

def message
  @message
end

#semanticObject (readonly)

Returns the value of attribute semantic.



8
9
10
# File 'lib/simple_logic_step.rb', line 8

def semantic
  @semantic
end

Class Method Details

.call(**ctx) ⇒ Object



10
11
12
# File 'lib/simple_logic_step.rb', line 10

def self.call(**ctx)
  new(**ctx).call
end

Instance Method Details

#callObject



21
22
23
24
25
# File 'lib/simple_logic_step.rb', line 21

def call
  prepare
  process
  self
end

#failure?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/simple_logic_step.rb', line 32

def failure?
  if block_given?
    yield(self) unless success
  else
    !success
  end
end

#processObject

Implement business logic here



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

def process
  raise 'Not implemented'
end

#success?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/simple_logic_step.rb', line 40

def success?
  if block_given?
    yield(self) if success
  else
    success
  end
end