Class: Readme
- Inherits:
-
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
-
#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
Initialize Readme instance.
-
#log(text = '', type = :info) ⇒ Object
-
#method_missing(method) ⇒ Object
If a method call is missing, then delegate to concept parent.
-
#readme(text) ⇒ Object
-
#run(command, args = {}) ⇒ Object
-
#set(key, value) ⇒ Object
-
#show ⇒ Object
-
#target(desc, args = {}) ⇒ Object
(also: #goal)
-
#unique(_key, _value) ⇒ Object
Constructor Details
#initialize(script_path, config_path) ⇒ Readme
Initialize Readme instance
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) ⇒ Object
If a method call is missing, then delegate to concept parent.
88
89
90
91
|
# File 'lib/teuton/readme/dsl.rb', line 88
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.
31
32
33
|
# File 'lib/teuton/readme/readme.rb', line 31
def data
@data
end
|
#result ⇒ Object
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_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
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/teuton/readme/dsl.rb', line 75
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
93
94
95
96
97
98
99
|
# File 'lib/teuton/readme/dsl.rb', line 93
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
109
110
111
|
# File 'lib/teuton/readme/dsl.rb', line 109
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?
@current[:readme] << text
else
@action[:readme] << text
end
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
101
102
103
|
# File 'lib/teuton/readme/dsl.rb', line 101
def set(key, value)
@setted_params[key] = value
end
|
#show ⇒ Object
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
105
106
107
|
# File 'lib/teuton/readme/dsl.rb', line 105
def unique(_key, _value)
end
|