Class: Readme
- Inherits:
-
Object
show all
- Defined in:
- lib/teuton/project/readme/dsl.rb,
lib/teuton/project/readme/readme.rb
Overview
Creates README.md file from RB script file
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#expect(_cond, args = {}) ⇒ Object
(also: #expect_any, #expect_none, #expect_one)
-
#get(value) ⇒ Object
-
#gett(value) ⇒ Object
-
#goto(host = :localhost, args = {}) ⇒ Object
-
#initialize(script_path, config_path) ⇒ Readme
constructor
A new instance of Readme.
-
#log(text = '', type = :info) ⇒ Object
-
#method_missing(method) ⇒ Object
If a method call is missing, then delegate to concept parent.
-
#process_content ⇒ Object
-
#readme(text) ⇒ Object
-
#reset ⇒ Object
-
#reset_action ⇒ Object
-
#run(command, args = {}) ⇒ Object
-
#set(key, value) ⇒ Object
-
#show ⇒ Object
-
#show_content ⇒ Object
-
#show_head ⇒ Object
-
#show_tail ⇒ Object
-
#target(desc, args = {}) ⇒ Object
(also: #goal)
-
#unique(_key, _value) ⇒ Object
Constructor Details
#initialize(script_path, config_path) ⇒ Readme
Returns a new instance of Readme.
34
35
36
37
38
39
40
41
|
# File 'lib/teuton/project/readme/readme.rb', line 34
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) ⇒ Object
If a method call is missing, then delegate to concept parent.
86
87
88
89
|
# File 'lib/teuton/project/readme/dsl.rb', line 86
def method_missing(method)
a = method.to_s
instance_eval("get(:#{a[0, a.size - 1]})") if a[a.size - 1] == '?'
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
32
33
34
|
# File 'lib/teuton/project/readme/readme.rb', line 32
def data
@data
end
|
#result ⇒ Object
Returns the value of attribute result.
31
32
33
|
# File 'lib/teuton/project/readme/readme.rb', line 31
def result
@result
end
|
Instance Method Details
#expect(_cond, args = {}) ⇒ Object
Also known as:
expect_any, expect_none, expect_one
65
66
67
68
|
# File 'lib/teuton/project/readme/dsl.rb', line 65
def expect(_cond, args = {})
@current[:actions] << @action
result.reset
end
|
#get(value) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/teuton/project/readme/dsl.rb', line 73
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
91
92
93
94
95
96
|
# File 'lib/teuton/project/readme/dsl.rb', line 91
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/project/readme/dsl.rb', line 30
def goto(host = :localhost, args = {})
unless host == :localhost
b = {}
a = "#{host}_ip".to_sym
if @config[:global][a].nil? && (not @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? && (not @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? && (not @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
106
107
108
|
# File 'lib/teuton/project/readme/dsl.rb', line 106
def log(text = '', type = :info)
@data[:logs] << "[#{type}]: " + text.to_s
end
|
#process_content ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/teuton/project/readme/readme.rb', line 59
def process_content
Application.instance.groups.each do |g|
@current = { name: g[:name], readme: [], actions: [] }
@data[:groups] << @current
reset_action
instance_eval(&g[:block])
end
end
|
#readme(text) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/teuton/project/readme/dsl.rb', line 11
def readme(text)
if @action[:target].nil?
@current[:readme] << text
else
@action[:readme] << text
end
end
|
#reset ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/teuton/project/readme/readme.rb', line 43
def reset
app = Application.instance
@config = ConfigFileReader.read(app.config_path)
@verbose = app.verbose
@result = Result.new
@data = {}
@data[:logs] = []
@data[:groups] = []
@data[:play] = []
reset_action
@setted_params = {}
@cases_params = []
@global_params = {}
@required_hosts = {}
end
|
#reset_action ⇒ Object
68
69
70
|
# File 'lib/teuton/project/readme/readme.rb', line 68
def reset_action
@action = { readme: [] }
end
|
#run(command, args = {}) ⇒ Object
60
61
62
63
|
# File 'lib/teuton/project/readme/dsl.rb', line 60
def run(command, args = {})
args[:exec] = command
goto(:localhost, args)
end
|
#set(key, value) ⇒ Object
98
99
100
|
# File 'lib/teuton/project/readme/dsl.rb', line 98
def set(key, value)
@setted_params[key] = value
end
|
#show ⇒ Object
72
73
74
75
76
77
|
# File 'lib/teuton/project/readme/readme.rb', line 72
def show
process_content
show_head
show_content
show_tail
end
|
#show_content ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/teuton/project/readme/readme.rb', line 79
def show_content
@data[:groups].each do |group|
next if group[:actions].empty?
puts "\n## #{group[:name]}\n\n"
group[:readme].each { |line| puts "#{line}\n" }
previous_host = nil
group[:actions].each_with_index do |item, index|
if item[:host].nil? && index.positive?
item[:host] = group[:actions][0][:host]
end
if previous_host.nil? || item[:host] != previous_host
previous_host = item[:host] || 'null'
puts format(Lang::get(:goto), previous_host.upcase)
end
weight = ''
weight = "(x#{item[:weight]}) " if item[:weight] != 1.0
puts "* #{weight}#{item[:target]}"
item[:readme].each { |line| puts " * #{line}\n" }
end
end
end
|
#show_head ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/teuton/project/readme/readme.rb', line 103
def show_head
app = Application.instance
puts '```'
puts format(Lang::get(:testname), app.test_name)
puts format(Lang::get(:date), Time.now)
puts format(Lang::get(:version), Application::VERSION)
puts '```'
puts "# README.md\n"
i = 1
unless @required_hosts.empty?
puts Lang::get(:hosts)
puts "\n"
puts '| ID | Host | Configuration |'
puts '| -- | ---- | ------------- |'
@required_hosts.each_pair do |k, v|
c = []
v.each_pair { |k2,v2| c << "#{k2}=#{v2}" }
puts "|#{i}|#{k.upcase}|#{c.join(', ')}|"
i += 1
end
puts "\n> NOTE: SSH Service installation is required on every host."
end
unless @cases_params.empty?
@cases_params.uniq!.sort!
puts Lang::get(:params)
@cases_params.uniq.each { |i| puts format('* %s', i) }
puts "\n> NOTE:"
puts "> * Teuton software must known this information!"
puts "> * Save every ':param: value' into config file."
end
end
|
#show_tail ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/teuton/project/readme/readme.rb', line 137
def show_tail
return if @global_params.empty?
app = Application.instance
puts "\n---"
puts "# ANEXO"
puts "\n\#\# Global params"
puts Lang::get(:global)
puts "\n"
puts '| Global param | Value |'
puts '| ------------ | ----- |'
@global_params.each_pair { |k,v| puts "|#{k}|#{v}|" }
puts "\n\#\# Created params"
puts Lang::get(:created)
puts "\n"
puts '| Created params | Value |'
puts '| -------------- | ----- |'
@setted_params.each_pair { |k,v| puts "|#{k}|#{v}|" }
end
|
#target(desc, args = {}) ⇒ Object
Also known as:
goal
21
22
23
24
25
26
27
|
# File 'lib/teuton/project/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
102
103
104
|
# File 'lib/teuton/project/readme/dsl.rb', line 102
def unique(_key, _value)
end
|