Class: KeyVortex::Field

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#limitationLimitation (readonly)



15
16
17
# File 'lib/key_vortex/field.rb', line 15

def limitation
  @limitation
end

#nameSymbol (readonly)



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

def name
  @name
end

Instance Method Details

#accepts?(value) ⇒ Boolean



43
44
45
# File 'lib/key_vortex/field.rb', line 43

def accepts?(value)
  limitation.accepts?(value)
end

#enable_json_additionsObject

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



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