Class: Jerakia::Datasource
- Inherits:
-
Object
- Object
- Jerakia::Datasource
- Defined in:
- lib/jerakia/datasource.rb,
lib/jerakia/datasource/file.rb,
lib/jerakia/datasource/http.rb,
lib/jerakia/datasource/dummy.rb,
lib/jerakia/datasource/file/yaml.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#lookup ⇒ Object
readonly
Returns the value of attribute lookup.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(name, lookup, opts) ⇒ Datasource
constructor
A new instance of Datasource.
- #option(opt, data = {}) ⇒ Object
-
#whoami ⇒ Object
used for verbose logging.
Constructor Details
#initialize(name, lookup, opts) ⇒ Datasource
Returns a new instance of Datasource.
9 10 11 12 13 14 15 16 17 |
# File 'lib/jerakia/datasource.rb', line 9 def initialize(name, lookup, opts) @response = Jerakia::Response.new(lookup) @options = opts @lookup = lookup @name = name require "jerakia/datasource/#{name.to_s}" # rescue loaderrer eval "extend Jerakia::Datasource::#{name.to_s.capitalize}" end |
Instance Attribute Details
#lookup ⇒ Object (readonly)
Returns the value of attribute lookup.
7 8 9 |
# File 'lib/jerakia/datasource.rb', line 7 def lookup @lookup end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/jerakia/datasource.rb', line 6 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/jerakia/datasource.rb', line 5 def response @response end |
Instance Method Details
#option(opt, data = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jerakia/datasource.rb', line 25 def option(opt, data={}) @options[opt] ||= data[:default] || nil Jerakia.log.debug("[#{whoami}]: options[#{opt}] to #{[opt]} [#{[opt].class}]") if @options[opt].nil? Jerakia.crit "#{opt} must be configured in #{whoami}" if data[:mandatory] else if data[:type] unless Array(data[:type]).include?(@options[opt].class) Jerakia.crit "#{opt} is a #{opt.class} but must be a #{data[:type].to_s} in #{whoami}" end end end end |
#whoami ⇒ Object
used for verbose logging
21 22 23 |
# File 'lib/jerakia/datasource.rb', line 21 def whoami "datasource=#{@name} lookup=#{@lookup.name}" end |