Class: Isomer::Sources::Base
- Inherits:
-
Object
- Object
- Isomer::Sources::Base
- Defined in:
- lib/isomer/sources/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
- #for(parameter) ⇒ Object
-
#initialize(parameters) ⇒ Base
constructor
A new instance of Base.
- #load ⇒ Object
- #load_and_validate ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(parameters) ⇒ Base
Returns a new instance of Base.
4 5 6 7 |
# File 'lib/isomer/sources/base.rb', line 4 def initialize(parameters) @parameters = parameters @errors = [] end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
2 3 4 |
# File 'lib/isomer/sources/base.rb', line 2 def configuration @configuration end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
2 3 4 |
# File 'lib/isomer/sources/base.rb', line 2 def errors @errors end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
2 3 4 |
# File 'lib/isomer/sources/base.rb', line 2 def parameters @parameters end |
Instance Method Details
#for(parameter) ⇒ Object
29 30 31 |
# File 'lib/isomer/sources/base.rb', line 29 def for(parameter) configuration.has_key?(parameter.name) ? configuration[parameter.name] : parameter.default end |
#load ⇒ Object
14 15 16 |
# File 'lib/isomer/sources/base.rb', line 14 def load raise NotImplementedError, "You must implement 'load' in #{self.class.name}" end |
#load_and_validate ⇒ Object
9 10 11 12 |
# File 'lib/isomer/sources/base.rb', line 9 def load_and_validate load validate end |
#validate ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/isomer/sources/base.rb', line 18 def validate parameters.each do |parameter| if parameter.required? value = configuration[parameter.name] @errors << "#{parameter.name} is required" if valid(value) end end raise Isomer::RequiredParameterError, errors.join(', ') if !errors.empty? end |