Class: Frigate::Form::Association
- Inherits:
-
Object
- Object
- Frigate::Form::Association
- Defined in:
- lib/frigate/form/association.rb
Overview
Uses to define a form association with properties as Frigate::Form::Property
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
-
.associations ⇒ Object
gets just options for defined associations.
-
.has_one(name, options = {}, &block) ⇒ Object
defines association (kinda property with properties) for association.
-
.properties ⇒ Object
gets just options for defined properties.
-
.property(name, options = {}) ⇒ Object
defines property for association.
Instance Method Summary collapse
-
#errors ⇒ ActiveModel::Errors
gets errors of association.
-
#initialize(name, root, parent, opts = {}) ⇒ Association
constructor
A new instance of Association.
-
#valid? ⇒ Boolean
checks validness of association properties.
-
#validate ⇒ Object
validates association properties.
Constructor Details
#initialize(name, root, parent, opts = {}) ⇒ Association
Returns a new instance of Association.
41 42 43 44 45 46 47 48 |
# File 'lib/frigate/form/association.rb', line 41 def initialize(name, root, parent, opts = {}) @name, @root, @parent, @opts = name, root, parent, opts @properties, @associations = [], [] exec_opts_block process_properties process_associations end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
38 39 40 |
# File 'lib/frigate/form/association.rb', line 38 def associations @associations end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/frigate/form/association.rb', line 38 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
38 39 40 |
# File 'lib/frigate/form/association.rb', line 38 def opts @opts end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
38 39 40 |
# File 'lib/frigate/form/association.rb', line 38 def parent @parent end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
38 39 40 |
# File 'lib/frigate/form/association.rb', line 38 def properties @properties end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
38 39 40 |
# File 'lib/frigate/form/association.rb', line 38 def root @root end |
Class Method Details
.associations ⇒ Object
gets just options for defined associations
33 34 35 |
# File 'lib/frigate/form/association.rb', line 33 def associations @associations.deep_dup || {} end |
.has_one(name, options = {}, &block) ⇒ Object
defines association (kinda property with properties) for association
18 19 20 21 |
# File 'lib/frigate/form/association.rb', line 18 def has_one(name, ={}, &block) @associations ||= {} @associations[name.to_sym] = .merge({ block: block }) end |
.properties ⇒ Object
gets just options for defined properties
26 27 28 |
# File 'lib/frigate/form/association.rb', line 26 def properties @properties.deep_dup || {} end |
.property(name, options = {}) ⇒ Object
defines property for association
9 10 11 12 |
# File 'lib/frigate/form/association.rb', line 9 def property(name, ={}) @properties ||= {} @properties[name.to_sym] = end |
Instance Method Details
#errors ⇒ ActiveModel::Errors
gets errors of association
52 53 54 |
# File 'lib/frigate/form/association.rb', line 52 def errors @errors ||= ActiveModel::Errors.new(self) end |
#valid? ⇒ Boolean
checks validness of association properties
57 58 59 |
# File 'lib/frigate/form/association.rb', line 57 def valid? errors..empty? end |
#validate ⇒ Object
validates association properties
62 63 64 |
# File 'lib/frigate/form/association.rb', line 62 def validate properties.each { |_prop| errors.add(_prop.name, _prop.errors[:value]) unless _prop.valid? } end |