Class: Laboratory
- Inherits:
-
Object
- Object
- Laboratory
- Defined in:
- lib/teuton/check/dsl.rb,
lib/teuton/check/show.rb,
lib/teuton/check/builtin.rb,
lib/teuton/check/laboratory.rb
Overview
Show objectives stats from RB script file
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#expect(cond) ⇒ Object
Execute Teuton DSL expect keyword.
-
#expect_none(cond) ⇒ Object
Execute Teuton DSL expect_none keyword.
-
#expect_one(cond) ⇒ Object
Execute Teuton DSL expect_one keyword.
-
#get(varname) ⇒ Object
Execute Teuton DSL get keyword.
-
#gett(option) ⇒ Object
Execute Teuton DSL gett keyword Same as get keyword, but show pretty output when used by readme command.
-
#goto(host = :localhost, args = {}) ⇒ Object
Execute Teuton DSL goto keyword.
-
#initialize(script_path, config_path) ⇒ Laboratory
constructor
A new instance of Laboratory.
-
#log(text = "", type = :info) ⇒ Object
Execute Teuton DSL log keyword.
-
#method_missing(method) ⇒ Object
If a method call is missing, then try to call get(var) rubocop:disable Style/MissingRespondToMissing.
-
#readme(_text) ⇒ Object
Execute Teuton DSL readme keyword.
- #reset ⇒ Object
-
#run(command, args = {}) ⇒ Object
Execute Teuton DSL run keyword.
- #service(param) ⇒ Object
-
#set(key, value) ⇒ Object
Execute Teuton DSL set keyword.
-
#show ⇒ Object
Display DSL checking on screen.
-
#show_panelconfig ⇒ Object
Display config for teuton panel on screen.
-
#target(desc, args = {}) ⇒ Object
(also: #goal)
Execute Teuton DSL target keyword.
-
#unique(key, _value) ⇒ Object
Execute Teuton DSL unique keyword.
Constructor Details
#initialize(script_path, config_path) ⇒ Laboratory
Returns a new instance of Laboratory.
43 44 45 46 47 48 49 50 |
# File 'lib/teuton/check/laboratory.rb', line 43 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 try to call get(var) rubocop:disable Style/MissingRespondToMissing
86 87 88 89 |
# File 'lib/teuton/check/dsl.rb', line 86 def method_missing(method) a = method.to_s instance_eval("get(:#{a[0, a.size - 1]})", __FILE__, __LINE__) if a[a.size - 1] == "?" end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
41 42 43 |
# File 'lib/teuton/check/laboratory.rb', line 41 def result @result end |
Instance Method Details
#expect(cond) ⇒ Object
Execute Teuton DSL expect keyword
48 49 50 51 52 |
# File 'lib/teuton/check/dsl.rb', line 48 def expect(cond) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect #{cond} (#{cond.class})" verboseln "" end |
#expect_none(cond) ⇒ Object
Execute Teuton DSL expect_none keyword
64 65 66 67 68 |
# File 'lib/teuton/check/dsl.rb', line 64 def expect_none(cond) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect_none #{cond} (#{cond.class})" verboseln "" end |
#expect_one(cond) ⇒ Object
Execute Teuton DSL expect_one keyword
56 57 58 59 60 |
# File 'lib/teuton/check/dsl.rb', line 56 def expect_one(cond) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect_one #{cond} (#{cond.class})" verboseln "" end |
#get(varname) ⇒ Object
Execute Teuton DSL get keyword
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/teuton/check/dsl.rb', line 72 def get(varname) @stats[:gets] += 1 if @gets[varname] @gets[varname] += 1 else @gets[varname] = 1 end "get(#{varname})" end |
#gett(option) ⇒ Object
Execute Teuton DSL gett keyword Same as get keyword, but show pretty output when used by readme command.
95 96 97 |
# File 'lib/teuton/check/dsl.rb', line 95 def gett(option) get(option) end |
#goto(host = :localhost, args = {}) ⇒ Object
Execute Teuton DSL goto keyword
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/teuton/check/dsl.rb', line 34 def goto(host = :localhost, args = {}) result.reset args[:on] = host unless args[:on] if @hosts[host] @hosts[host] += 1 else @hosts[host] = 1 end verboseln " run '#{args[:exec]}' on #{args[:on]}" end |
#log(text = "", type = :info) ⇒ Object
Execute Teuton DSL log keyword
110 111 112 113 |
# File 'lib/teuton/check/dsl.rb', line 110 def log(text = "", type = :info) @stats[:logs] += 1 verboseln " log [#{type}]: " + text.to_s end |
#readme(_text) ⇒ Object
Execute Teuton DSL readme keyword
8 9 10 |
# File 'lib/teuton/check/dsl.rb', line 8 def readme(_text) # Usefull for "teuton readme" command action. end |
#reset ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/teuton/check/laboratory.rb', line 52 def reset @result = Result.new @targetid = 0 @stats = {groups: 0, targets: 0, uniques: 0, gets: 0, logs: 0, sets: 0} @gets = {} @sets = {} @hosts = {} @requests = [] # REVISE this @verbose = Application.instance.verbose end |
#run(command, args = {}) ⇒ Object
Execute Teuton DSL run keyword
25 26 27 28 29 30 |
# File 'lib/teuton/check/dsl.rb', line 25 def run(command, args = {}) args[:exec] = command host = :localhost host = args[:on] if args[:on] goto(host, args) end |
#service(param) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/teuton/check/builtin.rb', line 22 def service(param) log "BUILTIN service(#{param})" @builtin ||= Builtin.new(self) @builtin.param = param @builtin end |
#set(key, value) ⇒ Object
Execute Teuton DSL set keyword
117 118 119 120 121 122 123 124 125 |
# File 'lib/teuton/check/dsl.rb', line 117 def set(key, value) @stats[:sets] += 1 key = ":" + key.to_s if key.instance_of? Symbol value = ":" + value.to_s if value.instance_of? Symbol @sets[key] = value "set(#{key},#{value})" end |
#show ⇒ Object
Display DSL checking on screen
14 15 16 17 18 19 |
# File 'lib/teuton/check/show.rb', line 14 def show @verbose = true process_content show_stats revise_config_content end |
#show_panelconfig ⇒ Object
Display config for teuton panel on screen
23 24 25 26 27 28 |
# File 'lib/teuton/check/show.rb', line 23 def show_panelconfig @verbose = false process_content @verbose = true recomended_panelconfig_content end |
#target(desc, args = {}) ⇒ Object Also known as: goal
Execute Teuton DSL target keyword
14 15 16 17 18 19 20 |
# File 'lib/teuton/check/dsl.rb', line 14 def target(desc, args = {}) @stats[:targets] += 1 @targetid += 1 weight = args[:weight] || 1.0 verboseln format("(%03<targetid>d) target %<desc>s", targetid: @targetid, desc: desc) verboseln " weight #{weight}" end |
#unique(key, _value) ⇒ Object
Execute Teuton DSL unique keyword
101 102 103 104 105 106 |
# File 'lib/teuton/check/dsl.rb', line 101 def unique(key, _value) @stats[:uniques] += 1 verboseln " ! Unique value for <#{key}>" verboseln "" end |