Class: Ciesta::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/ciesta/field.rb

Constant Summary collapse

DEFAULT_TYPE =
Ciesta::Types::Any

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Field

Returns a new instance of Field.



7
8
9
10
11
# File 'lib/ciesta/field.rb', line 7

def initialize(name, options)
  self.name = name.to_sym
  self.type = options.delete(:type) || DEFAULT_TYPE
  self.value = options.delete(:default)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ciesta/field.rb', line 5

def name
  @name
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/ciesta/field.rb', line 5

def type
  @type
end

Instance Method Details

#valueObject



13
14
15
# File 'lib/ciesta/field.rb', line 13

def value
  current_value
end

#value=(val) ⇒ Object



17
18
19
20
21
# File 'lib/ciesta/field.rb', line 17

def value=(val)
  self.current_value = type[val]
rescue Dry::Types::ConstraintError
  raise ViolatesConstraints, "#{current_value} is not a #{type.name}"
end