Class: Yema::Virtus::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/yema/virtus/attribute.rb,
lib/yema/virtus/attribute/array.rb,
lib/yema/virtus/attribute/string.rb,
lib/yema/virtus/attribute/numeric.rb

Direct Known Subclasses

Array, Numeric, String

Defined Under Namespace

Classes: Array, Numeric, String

Constant Summary collapse

DEFAULT_BUILDERS =
[ Builder::StrongType, Builder::Required ].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ Attribute

Returns a new instance of Attribute.



8
9
10
# File 'lib/yema/virtus/attribute.rb', line 8

def initialize(attribute)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/yema/virtus/attribute.rb', line 5

def attribute
  @attribute
end

Class Method Details

.build(attribute) ⇒ Object



29
30
31
32
# File 'lib/yema/virtus/attribute.rb', line 29

def self.build(attribute)
  klass = determine_type(attribute)
  klass.new(attribute)
end

.buildersObject



16
17
18
# File 'lib/yema/virtus/attribute.rb', line 16

def self.builders
  DEFAULT_BUILDERS + specific_builders
end

.specific_buildersObject



12
13
14
# File 'lib/yema/virtus/attribute.rb', line 12

def self.specific_builders
  [].freeze
end

Instance Method Details

#rulesObject



20
21
22
23
24
25
26
27
# File 'lib/yema/virtus/attribute.rb', line 20

def rules
  rules = []
  self.class.builders.each do |builder|
    rule = builder.new(attribute).build
    rules << rule if rule
  end
  rules.to_set
end