Class: KeyVortex::Field
- Inherits:
-
Object
- Object
- KeyVortex::Field
- Defined in:
- lib/key_vortex/field.rb
Overview
Defines a value that can be set on a Record. This generally isn’t built directly, you should use the Record.field directive most of the time. This class ties a name to a Limitation, and delegates most questions on to the latter.
Instance Attribute Summary collapse
-
#limitation ⇒ Limitation
readonly
The restrictions placed upon this field.
-
#name ⇒ Symbol
readonly
The name of the field.
Instance Method Summary collapse
-
#accepts?(value) ⇒ Boolean
True if the value is valid for #limitation.
-
#enable_json_additions ⇒ Object
Enable JSON additions for the class used for this field.
-
#initialize(name, type, *constraints_array, **constraints_hash) ⇒ Field
constructor
Creates an instance of this class and converts any attribute/limit constraint pairs into Constraint objects.
-
#within?(adapter) ⇒ Boolean
True if the limitations for this field fit within the corresponding limitations for the adapter.
Constructor Details
#initialize(name, type, *constraints_array, **constraints_hash) ⇒ Field
Creates an instance of this class and converts any attribute/limit constraint pairs into Constraint objects.
24 25 26 27 28 29 30 31 32 |
# File 'lib/key_vortex/field.rb', line 24 def initialize(name, type, *constraints_array, **constraints_hash) @name = name @limitation = KeyVortex::Limitation.new(type) @limitation.add_constraint(*constraints_array) @limitation.add_constraint(*constraints_hash.map do |attribute, value| KeyVortex::Constraint.build(attribute, value) end) end |
Instance Attribute Details
#limitation ⇒ Limitation (readonly)
Returns the restrictions placed upon this field.
15 16 17 |
# File 'lib/key_vortex/field.rb', line 15 def limitation @limitation end |
#name ⇒ Symbol (readonly)
Returns the name of the field.
13 14 15 |
# File 'lib/key_vortex/field.rb', line 13 def name @name end |
Instance Method Details
#accepts?(value) ⇒ Boolean
Returns true if the value is valid for #limitation.
43 44 45 |
# File 'lib/key_vortex/field.rb', line 43 def accepts?(value) limitation.accepts?(value) end |
#enable_json_additions ⇒ Object
Enable JSON additions for the class used for this field.
48 49 50 |
# File 'lib/key_vortex/field.rb', line 48 def enable_json_additions @limitation.enable_json_additions end |
#within?(adapter) ⇒ Boolean
Returns true if the limitations for this field fit within the corresponding limitations for the adapter.
36 37 38 39 |
# File 'lib/key_vortex/field.rb', line 36 def within?(adapter) limitation = adapter.limitation_for(self) !limitation || self.limitation.within?(limitation) end |