Class: RubyScriptExporter::ScriptLoader
- Inherits:
-
Object
- Object
- RubyScriptExporter::ScriptLoader
- Defined in:
- lib/ruby_script_exporter/script_loader.rb
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
Returns the value of attribute services.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ScriptLoader
constructor
A new instance of ScriptLoader.
- #service(name, &block) ⇒ Object
- #type(name, type, help = nil) ⇒ Object
Constructor Details
#initialize ⇒ ScriptLoader
Returns a new instance of ScriptLoader.
6 7 8 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 6 def initialize @services = [] end |
Instance Attribute Details
#services ⇒ Object (readonly)
Returns the value of attribute services.
4 5 6 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 4 def services @services end |
Class Method Details
.load_directory(directory) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 31 def self.load_directory(directory) unless directory.start_with?('/') directory = File.join(Dir.pwd, directory) end directory = File.join(directory, '/*.rb') service_files = Dir[directory] puts "Loading service definitions ..." services = service_files.map { load_file(_1) }.flatten probe_count = services.map(&:probes).flatten.count puts "Loaded #{Util.counterize('service', services.count)} with a total of #{Util.counterize('probe', probe_count)}" services end |
.load_file(file) ⇒ Object
27 28 29 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 27 def self.load_file(file) load_string File.open(file).read end |
.load_string(string) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 20 def self.load_string(string) loader = ScriptLoader.new Type.reset_types loader.instance_eval string loader.services end |
Instance Method Details
#service(name, &block) ⇒ Object
10 11 12 13 14 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 10 def service(name, &block) service_builder = RubyScriptExporter::Service::Builder.new(name) service_builder.instance_eval(&block) @services << service_builder.service end |
#type(name, type, help = nil) ⇒ Object
16 17 18 |
# File 'lib/ruby_script_exporter/script_loader.rb', line 16 def type(name, type, help = nil) Type.register_type(name, type, help) end |