Class: Dtmcli::Saga

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

Constant Summary collapse

TRANS_TYPE =
'saga'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dtm_url) ⇒ Saga

Returns a new instance of Saga.



8
9
10
11
12
# File 'lib/dtmcli/saga.rb', line 8

def initialize(dtm_url)
  @dtm_url = dtm_url
  @dtm = Dtm.new(dtm_url)
  @steps = []
end

Instance Attribute Details

#dtmObject (readonly)

Returns the value of attribute dtm.



4
5
6
# File 'lib/dtmcli/saga.rb', line 4

def dtm
  @dtm
end

#dtm_urlObject (readonly)

Returns the value of attribute dtm_url.



4
5
6
# File 'lib/dtmcli/saga.rb', line 4

def dtm_url
  @dtm_url
end

#gidObject

Returns the value of attribute gid.



3
4
5
# File 'lib/dtmcli/saga.rb', line 3

def gid
  @gid
end

#stepsObject

Returns the value of attribute steps.



3
4
5
# File 'lib/dtmcli/saga.rb', line 3

def steps
  @steps
end

Instance Method Details

#add(action, compensate, post_data) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/dtmcli/saga.rb', line 18

def add(action, compensate, post_data)
  step = {
    action:     action,
    compensate: compensate,
    data:       post_data.to_json,
  }
  @steps << step
end

#gen_gidObject



14
15
16
# File 'lib/dtmcli/saga.rb', line 14

def gen_gid
  @gid = IdGenerator.gen_gid(dtm_url)
end

#submitObject



27
28
29
30
31
32
33
34
# File 'lib/dtmcli/saga.rb', line 27

def submit
  tbody = {
    gid: gid,
    trans_type: TRANS_TYPE,
    steps: steps
  }
  dtm.submit(tbody)
end