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_new.rb,
lib/jerakia/datasource/file/json.rb,
lib/jerakia/datasource/file/yaml.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#lookup ⇒ Object
readonly
Returns the value of attribute lookup.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jerakia/datasource.rb', line 13 def initialize(name, lookup, opts) @response = Jerakia::Response.new(lookup) @options = opts @lookup = lookup @name = name begin require "jerakia/datasource/#{name}" eval "extend Jerakia::Datasource::#{name.capitalize}" rescue LoadError => e raise Jerakia::Error, "Cannot load datasource #{name} in lookup #{lookup.name}, #{e.}" end end |
Instance Attribute Details
#lookup ⇒ Object (readonly)
Returns the value of attribute lookup.
10 11 12 |
# File 'lib/jerakia/datasource.rb', line 10 def lookup @lookup end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/jerakia/datasource.rb', line 11 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/jerakia/datasource.rb', line 9 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/jerakia/datasource.rb', line 8 def response @response end |
Instance Method Details
#option(opt, data = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jerakia/datasource.rb', line 31 def option(opt, data = {}) if @options[opt].nil? && data.key?(:default) @options[opt] = data[:default] end Jerakia.log.debug("[#{whoami}]: options[#{opt}] to #{[opt]} [#{[opt].class}]") if @options[opt].nil? raise Jerakia::PolicyError, "#{opt} option must be supplied for datasource #{@name} in lookup #{lookup.name}" if data[:mandatory] else if data[:type] if Array(data[:type]).select { |t| @options[opt].is_a?(t) }.empty? raise Jerakia::PolicyError, "#{opt} is a #{@options[opt].class} but must be a #{data[:type]} for datasource #{@name} in lookup #{lookup.name}" end end end end |
#whoami ⇒ Object
used for verbose logging
27 28 29 |
# File 'lib/jerakia/datasource.rb', line 27 def whoami "datasource=#{@name} lookup=#{@lookup.name}" end |