Module: ReadmeDSL

Included in:
Readme
Defined in:
lib/teuton/readme/dsl/all.rb,
lib/teuton/readme/dsl/run.rb,
lib/teuton/readme/dsl/expect.rb,
lib/teuton/readme/dsl/getset.rb

Instance Method Summary collapse

Instance Method Details

#expect(_cond, _args = {}) ⇒ Object Also known as: expect_any, expect_exit, expect_first, expect_last, expect_one



4
5
6
7
# File 'lib/teuton/readme/dsl/expect.rb', line 4

def expect(_cond, _args = {})
  @current[:actions] << @action
  result.reset
end

#expect_failObject Also known as: expect_ok



14
15
16
17
# File 'lib/teuton/readme/dsl/expect.rb', line 14

def expect_fail
  @current[:actions] << @action
  result.reset
end

#expect_none(cond = nil) ⇒ Object Also known as: expect_nothing



20
21
22
# File 'lib/teuton/readme/dsl/expect.rb', line 20

def expect_none(cond = nil)
  expect(cond)
end

#expect_sequence(&block) ⇒ Object



25
26
27
28
# File 'lib/teuton/readme/dsl/expect.rb', line 25

def expect_sequence(&block)
  @current[:actions] << @action
  result.reset
end

#get(value) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/teuton/readme/dsl/getset.rb', line 2

def get(value)
  unless @config[:global][value].nil?
    @global_params[value] = @config[:global][value]
    return @config[:global][value]
  end

  return value.to_s.upcase if @setted_params.include? value

  @cases_params << value
  value.to_s.upcase
end

#gett(value) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/teuton/readme/dsl/getset.rb', line 14

def gett(value)
  a = get(value)
  if @cases_params.include? value
    "[#{value}](#required-params)"
  elsif @setted_params[value]
    "[#{value}](#created-params)"
  elsif @global_params.include? value
    "[#{a}](#global-params)"
  end
  a
end

#goto(host = :localhost, args = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/teuton/readme/dsl/run.rb', line 2

def goto(host = :localhost, args = {})
  unless host == :localhost
    b = {}
    a = "#{host}_ip".to_sym
    if @config[:global][a].nil? && !@setted_params.include?(a)
      @cases_params << a
    end
    b[:ip] = @config[:global][a] if @config[:global][a]
    b[:ip] = @setted_params[a] if @setted_params[a]

    a = "#{host}_username".to_sym
    if @config[:global][a].nil? && !@setted_params.include?(a)
      @cases_params << a
    end
    b[:username] = @config[:global][a] if @config[:global][a]
    b[:username] = @setted_params[a] if @setted_params[a]

    a = "#{host}_password".to_sym
    if @config[:global][a].nil? && !@setted_params.include?(a)
      @cases_params << a
    end
    b[:password] = @config[:global][a] if @config[:global][a]
    b[:password] = @setted_params[a] if @setted_params[a]

    @required_hosts[host.to_s] = b
  end
  @action[:host] = host
  @action[:exec] = args[:exec] || "noexec"
end

#log(text = "", type = :info) ⇒ Object



29
30
31
# File 'lib/teuton/readme/dsl/all.rb', line 29

def log(text = "", type = :info)
  # Nothing to do
end

#readme(text) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/teuton/readme/dsl/all.rb', line 8

def readme(text)
  if @action[:target].nil?
    @current[:readme] << text # It's a group readme
  else
    @action[:readme] << text # It's a target readme
  end
end

#run(command, args = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/teuton/readme/dsl/run.rb', line 32

def run(command, args = {})
  args[:exec] = command
  host = :localhost
  host = args[:on] if args[:on]
  goto(host, args)
end

#run_script(command, args = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/teuton/readme/dsl/run.rb', line 39

def run_script(command, args = {})
  host = :localhost
  host = args[:on] if args[:on]
  filename = command.split[1]
  upload filename, on: host
  run command, args = {}
  goto(host, args)
end

#set(key, value) ⇒ Object



26
27
28
# File 'lib/teuton/readme/dsl/getset.rb', line 26

def set(key, value)
  @setted_params[key] = value
end

#target(desc, args = {}) ⇒ Object Also known as: goal



16
17
18
19
20
21
22
# File 'lib/teuton/readme/dsl/all.rb', line 16

def target(desc, args = {})
  previous_host = @action[:host]
  @action = {target: desc, host: previous_host, readme: []}
  weight = 1.0
  weight = args[:weight].to_f if args[:weight]
  @action[:weight] = weight
end

#unique(_key, _value) ⇒ Object



25
26
27
# File 'lib/teuton/readme/dsl/all.rb', line 25

def unique(_key, _value)
  # Nothing to do
end

#unset(_key) ⇒ Object



30
31
32
# File 'lib/teuton/readme/dsl/getset.rb', line 30

def unset(_key)
  # Nothing to do
end

#upload(filename, args = {}) ⇒ Object



48
49
50
# File 'lib/teuton/readme/dsl/run.rb', line 48

def upload(filename, args = {})
  # Nothing to do
end