Class: Dtmcli::IdGenerator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_id = nil, branch_id = nil) ⇒ IdGenerator

Returns a new instance of IdGenerator.



15
16
17
18
# File 'lib/dtmcli/id_generator.rb', line 15

def initialize(parent_id=nil, branch_id=nil)
  @parent_id = parent_id || ''
  @branch_id = branch_id || 0
end

Instance Attribute Details

#branch_idObject

Returns the value of attribute branch_id.



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

def branch_id
  @branch_id
end

#id_genObject (readonly)

Returns the value of attribute id_gen.



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

def id_gen
  @id_gen
end

#parent_idObject

Returns the value of attribute parent_id.



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

def parent_id
  @parent_id
end

Class Method Details

.gen_gid(dtmUrl) ⇒ Object



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

def gen_gid(dtmUrl)
  body = Proxy.execute(:get, dtmUrl + '/newGid') do |resp|
    JSON.parse(resp.body)
  end
  return body["gid"]
end

Instance Method Details

#gen_branch_idObject



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

def gen_branch_id
  raise 'branch id is lager than 99' if branch_id >= 99
  raise 'total branch id is longer than 20' if parent_id.size >= 20
  @branch_id = branch_id + 1
  return "#{parent_id}#{branch_id}"
end