Class: Decouplio::Action

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_railway_flow: nil, parent_ctx: nil, meta_store:, **params) ⇒ Action

Returns a new instance of Action.



19
20
21
22
23
24
25
26
# File 'lib/decouplio/action.rb', line 19

def initialize(
  parent_railway_flow: nil, parent_ctx: nil, meta_store:, **params
)
  @meta_store = meta_store
  @ctx = parent_ctx || params
  @railway_flow = parent_railway_flow || []
  @failure = false
end

Class Attribute Details

.meta_storeObject

Returns the value of attribute meta_store.



61
62
63
# File 'lib/decouplio/action.rb', line 61

def meta_store
  @meta_store
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



15
16
17
# File 'lib/decouplio/action.rb', line 15

def ctx
  @ctx
end

#meta_storeObject (readonly) Also known as: ms

Returns the value of attribute meta_store.



15
16
17
# File 'lib/decouplio/action.rb', line 15

def meta_store
  @meta_store
end

#railway_flowObject (readonly)

Returns the value of attribute railway_flow.



15
16
17
# File 'lib/decouplio/action.rb', line 15

def railway_flow
  @railway_flow
end

Class Method Details

.call(**params) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/decouplio/action.rb', line 67

def call(**params)
  instance = new(
    **{
      meta_store: meta_store.new
    }.merge(**params)
  )
  Decouplio::Processor.call(instance: instance, **@flow)
  instance
end

.call!(**params) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/decouplio/action.rb', line 77

def call!(**params)
  instance = call(**params)
  if instance.failure?
    raise Decouplio::Errors::ExecutionError.new(
      action: instance
    )
  else
    instance
  end
end

.meta_store_class(klass) ⇒ Object



63
64
65
# File 'lib/decouplio/action.rb', line 63

def meta_store_class(klass)
  self.meta_store = klass
end

Instance Method Details

#[](key) ⇒ Object



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

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

#append_railway_flow(stp) ⇒ Object



48
49
50
# File 'lib/decouplio/action.rb', line 48

def append_railway_flow(stp)
  railway_flow << stp
end

#fail_actionObject



40
41
42
# File 'lib/decouplio/action.rb', line 40

def fail_action
  @failure = true
end

#failure?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/decouplio/action.rb', line 36

def failure?
  @failure
end

#inspectObject



52
53
54
# File 'lib/decouplio/action.rb', line 52

def inspect
  Decouplio::ActionStatePrinter.call(self)
end

#pass_actionObject



44
45
46
# File 'lib/decouplio/action.rb', line 44

def pass_action
  @failure = false
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/decouplio/action.rb', line 32

def success?
  !@failure
end

#to_sObject



56
57
58
# File 'lib/decouplio/action.rb', line 56

def to_s
  inspect
end