Class: Laboratory
- Inherits:
-
Object
- Object
- Laboratory
- Defined in:
- lib/teuton/project/laboratory/dsl.rb,
lib/teuton/project/laboratory/show.rb,
lib/teuton/project/laboratory/builtin.rb,
lib/teuton/project/laboratory/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, args = {}) ⇒ Object
- #expect_none(_cond, args = {}) ⇒ Object
- #expect_one(_cond, args = {}) ⇒ Object
- #get(varname) ⇒ Object
- #gett(option) ⇒ Object
- #goto(host = :localhost, args = {}) ⇒ Object
-
#initialize(script_path, config_path) ⇒ Laboratory
constructor
A new instance of Laboratory.
- #log(text = '', type = :info) ⇒ Object
-
#method_missing(method) ⇒ Object
If a method call is missing, then delegate to concept parent.
- #readme(_text) ⇒ Object
- #request(text) ⇒ Object
- #reset ⇒ Object
- #run(command, args = {}) ⇒ Object
- #service(param) ⇒ Object
- #set(key, value) ⇒ Object
- #show_config ⇒ Object
- #show_dsl ⇒ Object
- #show_requests ⇒ Object
- #show_stats ⇒ Object
- #target(desc, args = {}) ⇒ Object (also: #goal)
- #tempfile(_tempfile = nil) ⇒ Object
- #unique(key, _value) ⇒ Object
Constructor Details
#initialize(script_path, config_path) ⇒ Laboratory
Returns a new instance of Laboratory.
36 37 38 39 40 41 42 43 |
# File 'lib/teuton/project/laboratory/laboratory.rb', line 36 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/laboratory/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
#result ⇒ Object (readonly)
Returns the value of attribute result.
34 35 36 |
# File 'lib/teuton/project/laboratory/laboratory.rb', line 34 def result @result end |
Instance Method Details
#expect(_cond, args = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 50 def expect(_cond, args = {}) #unless [ String, Array, Regexp].include? _cond.class # verboseln "[ERROR] expect #{_cond} (#{_cond.class})" # return #end verboseln " alter #{result.alterations}" unless result.alterations.empty? #verboseln " expect #{result.expected} (#{result.expected.class})" verboseln " expect #{_cond} (#{_cond.class})" verboseln '' end |
#expect_none(_cond, args = {}) ⇒ Object
67 68 69 70 71 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 67 def expect_none(_cond, args = {}) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect_none #{_cond} (#{_cond.class})" verboseln '' end |
#expect_one(_cond, args = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 61 def expect_one(_cond, args = {}) verboseln " alter #{result.alterations}" unless result.alterations.empty? verboseln " expect_one #{_cond} (#{_cond.class})" verboseln '' end |
#get(varname) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 73 def get(varname) @stats[:gets] += 1 if @gets[varname] @gets[varname] += 1 else @gets[varname] = 1 end "get(#{varname})" end |
#gett(option) ⇒ Object
91 92 93 94 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 91 def gett(option) value = get(option) value end |
#goto(host = :localhost, args = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 34 def goto(host = :localhost, args = {}) result.reset if @hosts[host] @hosts[host] += 1 else @hosts[host] = 1 end verboseln " goto #{host} and #{args}" end |
#log(text = '', type = :info) ⇒ Object
103 104 105 106 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 103 def log(text = '', type = :info) @stats[:logs] += 1 verboseln " log [#{type}]: " + text.to_s end |
#readme(_text) ⇒ Object
13 14 15 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 13 def readme(_text) # Usefull for "teuton reamde" action. end |
#request(text) ⇒ Object
26 27 28 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 26 def request(text) @requests << text.to_s end |
#reset ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/teuton/project/laboratory/laboratory.rb', line 45 def reset @result = Result.new @targetid = 0 @stats = { groups: 0, targets: 0, uniques: 0, gets: 0, logs: 0, sets: 0 } @gets = {} @sets = {} @hosts = {} @requests = [] @verbose = Application.instance.verbose end |
#run(command, args = {}) ⇒ Object
45 46 47 48 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 45 def run(command, args = {}) args[:exec] = command goto(:localhost, args) end |
#service(param) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/teuton/project/laboratory/builtin.rb', line 17 def service(param) log "BUILTIN service(#{param})" @builtin = @builtin || Builtin.new(self) @builtin.param = param @builtin end |
#set(key, value) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 108 def set(key, value) @stats[:sets] += 1 key = ':' + key.to_s if key.class == Symbol value = ':' + value.to_s if value.class == Symbol @sets[key] = value "set(#{key},#{value})" end |
#show_config ⇒ Object
48 49 50 51 52 53 |
# File 'lib/teuton/project/laboratory/show.rb', line 48 def show_config @verbose = false process_content @verbose = true revise_config_content end |
#show_dsl ⇒ Object
12 13 14 15 16 17 |
# File 'lib/teuton/project/laboratory/show.rb', line 12 def show_dsl @verbose = true process_content show_stats show_config end |
#show_requests ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/teuton/project/laboratory/show.rb', line 55 def show_requests @verbose = false process_content @verbose = true my_screen_table = Terminal::Table.new do |st| st.add_row ['Lines', 'REQUEST description'] st.add_separator @requests.each_with_index do |line, index| st.add_row ['%03d' % index, line] end end verboseln my_screen_table end |
#show_stats ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/teuton/project/laboratory/show.rb', line 19 def show_stats @stats[:hosts] = 0 @hosts.each_pair { |_k, v| @stats[:hosts] += v } my_screen_table = Terminal::Table.new do |st| st.add_row ['DSL Stats', 'Count'] st.add_separator st.add_row ['Groups', @stats[:groups]] st.add_row ['Targets', @stats[:targets]] st.add_row ['Goto', @stats[:hosts]] @hosts.each_pair { |k, v| st.add_row [" * #{k}", v] } st.add_row ['Uniques', @stats[:uniques]] st.add_row ['Logs', @stats[:uniques]] st.add_row [' ', ' '] st.add_row ['Gets', @stats[:gets]] if @gets.count > 0 list = @gets.sort_by { |_k, v| v } list.reverse_each { |item| st.add_row [" * #{item[0]}", item[1].to_s] } end st.add_row ['Sets', @stats[:sets]] if @sets.count > 0 @sets.each_pair { |k, v| st.add_row [" * #{k}", v.to_s] } end end verboseln my_screen_table.to_s + "\n" end |
#target(desc, args = {}) ⇒ Object Also known as: goal
17 18 19 20 21 22 23 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 17 def target(desc, args = {}) @stats[:targets] += 1 @targetid += 1 weight = args[:weight] || 1.0 verboseln '(%03d' % @targetid + ") target #{desc}" verboseln " weight #{weight}" end |
#tempfile(_tempfile = nil) ⇒ Object
30 31 32 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 30 def tempfile(_tempfile = nil) 'tempfile' end |
#unique(key, _value) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/teuton/project/laboratory/dsl.rb', line 96 def unique(key, _value) @stats[:uniques] += 1 verboseln " ! Unique value for <#{key}>" verboseln '' end |