Class: Jerakia::Datasource::Instance
- Inherits:
-
Object
- Object
- Jerakia::Datasource::Instance
- Defined in:
- lib/jerakia/datasource.rb
Class Attribute Summary collapse
-
.features ⇒ Object
readonly
Returns the value of attribute features.
-
.options ⇒ Object
Returns the value of attribute options.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .feature(name) ⇒ Object
- .option(name, arguments = {}, &block) ⇒ Object
- .set_options(args) ⇒ Object
- .validate_options(args) ⇒ Object
Instance Method Summary collapse
- #answer(data = nil) ⇒ Object
- #features?(name) ⇒ Boolean
-
#initialize(lookup, opts) ⇒ Instance
constructor
A new instance of Instance.
Constructor Details
Class Attribute Details
.features ⇒ Object (readonly)
Returns the value of attribute features.
9 10 11 |
# File 'lib/jerakia/datasource.rb', line 9 def features @features end |
.options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/jerakia/datasource.rb', line 10 def @options end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/jerakia/datasource.rb', line 13 def @options end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
14 15 16 |
# File 'lib/jerakia/datasource.rb', line 14 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
15 16 17 |
# File 'lib/jerakia/datasource.rb', line 15 def response @response end |
Class Method Details
.feature(name) ⇒ Object
34 35 36 |
# File 'lib/jerakia/datasource.rb', line 34 def self.feature(name) @features << name.to_sym unless @features.include?(name.to_sym) end |
.option(name, arguments = {}, &block) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jerakia/datasource.rb', line 42 def self.option(name, arguments = {}, &block) self.={} if self..nil? @options[name] = Proc.new do |opt| if arguments[:default] opt = arguments[:default] if opt.nil? end if arguments[:required] raise Jerakia::DatasourceArgumentError, "Must specify #{name} parameter" if opt.nil? end if arguments[:type] unless opt.is_a?(arguments[:type]) || opt.nil? raise Jerakia::DatasourceArgumentError, "#{name} must be a #{arguments[:type].to_s}, got #{opt.class.to_s}" end end if block_given? unless opt.nil? raise Jerakia::DatasourceArgumentError, "Validation failed for #{name}" unless yield opt end end opt end end |
.set_options(args) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/jerakia/datasource.rb', line 67 def self.(args) opts = {} .keys.each do |k| opts[k] = [k].call(args[k]) end (args) opts end |
.validate_options(args) ⇒ Object
76 77 78 79 80 |
# File 'lib/jerakia/datasource.rb', line 76 def self.(args) args.keys.each do |k| raise Jerakia::DatasourceArgumentError, "Unknown option #{k}" unless .keys.include?(k) end end |
Instance Method Details
#answer(data = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/jerakia/datasource.rb', line 24 def answer(data=nil) if block_given? while @response.want? yield @response end else @response.submit(data) if response.want? and not data.nil? end end |
#features?(name) ⇒ Boolean
38 39 40 |
# File 'lib/jerakia/datasource.rb', line 38 def features?(name) @features.include?(name) end |