Class: DirtySeed::Attribute
- Inherits:
-
Object
- Object
- DirtySeed::Attribute
- Extended by:
- MethodMissingHelper
- Defined in:
- lib/dirty_seed/attribute.rb
Overview
Represents an Active Record attribute
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#assigner ⇒ DirtySeed::Assigners::Assigner
Returns the attribute assigner.
-
#initialize(model, column) ⇒ DirtySeed::Attribute
constructor
Initializes an instance.
-
#name ⇒ Symbol
Returns attribute name.
-
#type ⇒ Symbol
Returns attribute type.
-
#validators ⇒ Array<ActiveModel::Validations::EachValidators>
Returns an validators related to the current attribute.
-
#value ⇒ Object?
Returns a value matching type and validators.
Methods included from MethodMissingHelper
define_addressee, define_method_missing, define_respond_to_missing?, forward_missing_methods_to
Constructor Details
#initialize(model, column) ⇒ DirtySeed::Attribute
Initializes an instance
23 24 25 26 |
# File 'lib/dirty_seed/attribute.rb', line 23 def initialize(model, column) @model = model @column = column end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
9 10 11 |
# File 'lib/dirty_seed/attribute.rb', line 9 def column @column end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
9 10 11 |
# File 'lib/dirty_seed/attribute.rb', line 9 def model @model end |
Instance Method Details
#assigner ⇒ DirtySeed::Assigners::Assigner
Returns the attribute assigner
36 37 38 |
# File 'lib/dirty_seed/attribute.rb', line 36 def assigner @assigner ||= DirtySeed::Assigners::Base.new(self) end |
#name ⇒ Symbol
Returns attribute name
42 43 44 |
# File 'lib/dirty_seed/attribute.rb', line 42 def name @name ||= column.name.to_sym end |
#type ⇒ Symbol
Returns attribute type
48 49 50 51 |
# File 'lib/dirty_seed/attribute.rb', line 48 def type @type ||= TYPE_SYMMETRIES[column..type] || column..type end |
#validators ⇒ Array<ActiveModel::Validations::EachValidators>
Returns an validators related to the current attribute
55 56 57 58 59 60 |
# File 'lib/dirty_seed/attribute.rb', line 55 def validators @validators ||= model.validators.select do |validator| validator.attributes.include? name end end |
#value ⇒ Object?
Returns a value matching type and validators
30 31 32 |
# File 'lib/dirty_seed/attribute.rb', line 30 def value assigner.value end |