Class: Altair::Field
- Inherits:
-
Object
- Object
- Altair::Field
- Defined in:
- lib/altair/field.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(options) ⇒ Field
constructor
A new instance of Field.
- #parse!(value, args = {}) ⇒ Object
- #validate!(value, args = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Field
Returns a new instance of Field.
9 10 11 12 |
# File 'lib/altair/field.rb', line 9 def initialize() @type = [:type] @options = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/altair/field.rb', line 7 def @options end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/altair/field.rb', line 7 def type @type end |
Instance Method Details
#parse!(value, args = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/altair/field.rb', line 14 def parse!(value, args = {}) begin resolve_proc(Altair.converter[value.class][type], value) rescue raise ConversionError.new(type, value) end end |
#validate!(value, args = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/altair/field.rb', line 22 def validate!(value, args = {}) Altair.validators.each do |name, validator| if .has_key? name raise ValidationError.new(name, value) unless validator.call(resolve_proc([name]), value) end end value end |