Class: Readme

Inherits:
Object
  • Object
show all
Defined in:
lib/teuton/readme/dsl.rb,
lib/teuton/readme/readme.rb

Overview

Creates README.md file from RB script file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script_path, config_path) ⇒ Readme

Initialize Readme instance

Parameters:

  • script_path (String)

    Path to main rb file (start.rb)

  • config_path (String)

    Path to main config file (config.yaml)



37
38
39
40
41
42
43
44
# File 'lib/teuton/readme/readme.rb', line 37

def initialize(script_path, config_path)
  @path = {}
  @path[:script] = script_path
  @path[:dirname] = File.dirname(script_path)
  @path[:filename] = File.basename(script_path, ".rb")
  @path[:config] = config_path
  reset
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, args = {}) ⇒ Object

If a method call is missing, then delegate to concept parent.



90
91
92
93
94
95
# File 'lib/teuton/readme/dsl.rb', line 90

def method_missing(method, args = {})
  m = method.to_s
  if m[0] == "_"
    instance_eval("get(:#{m[1, m.size - 1]})", __FILE__, __LINE__)
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



31
32
33
# File 'lib/teuton/readme/readme.rb', line 31

def data
  @data
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

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



67
68
69
70
# File 'lib/teuton/readme/dsl.rb', line 67

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

#get(value) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/teuton/readme/dsl.rb', line 77

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



101
102
103
104
105
106
107
# File 'lib/teuton/readme/dsl.rb', line 101

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

  "[#{a}](\#global-params)" if @global_params.include? value
end

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/teuton/readme/dsl.rb', line 30

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



117
118
119
# File 'lib/teuton/readme/dsl.rb', line 117

def log(text = "", type = :info)
  @data[:logs] << "[#{type}]: " + text.to_s
end

#readme(text) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/teuton/readme/dsl.rb', line 11

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

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/teuton/readme/dsl.rb', line 97

def respond_to_missing?(method_name, include_private = false)
  true
end

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



60
61
62
63
64
65
# File 'lib/teuton/readme/dsl.rb', line 60

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

#set(key, value) ⇒ Object



109
110
111
# File 'lib/teuton/readme/dsl.rb', line 109

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

#showObject



46
47
48
49
50
51
# File 'lib/teuton/readme/readme.rb', line 46

def show
  process_content
  show_head
  show_content
  show_tail
end

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



21
22
23
24
25
26
27
# File 'lib/teuton/readme/dsl.rb', line 21

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



113
114
115
# File 'lib/teuton/readme/dsl.rb', line 113

def unique(_key, _value)
  # don't do nothing
end