Class: Frigate::Form::Base
- Inherits:
-
Object
- Object
- Frigate::Form::Base
- Defined in:
- lib/frigate/form/base.rb
Overview
Is used for model validation outside of model
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
-
.associations ⇒ Object
gets just options for defined associations.
-
.has_one(name, options = {}, &block) ⇒ Object
defines association (kinda property with properties)(root as well) of form/base.
-
.properties ⇒ Object
gets just options for defined properties.
-
.property(name, options = {}) ⇒ Object
defines property (root) of form/base.
Instance Method Summary collapse
-
#errors ⇒ ActiveModel::Errors
Initializes errors instance variable of ActiveModel::Errors type.
-
#initialize(model, opts = {}) ⇒ Base
constructor
Method of initialization of Frigate::Form class.
-
#valid? ⇒ Boolean
returns true if are there any errors messages in form errors.
-
#validate(*args) ⇒ Object
Validates form with params or model properties.
Constructor Details
#initialize(model, opts = {}) ⇒ Base
Method of initialization of Frigate::Form class
93 94 95 96 97 98 99 |
# File 'lib/frigate/form/base.rb', line 93 def initialize(model, opts={}) @syncronizator = opts[:contract] ? Synchronizer::Contract.new(self) : Synchronizer::Form.new(self) @model, @properties, @associations = model, [], [] process_properties process_associations end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
88 89 90 |
# File 'lib/frigate/form/base.rb', line 88 def associations @associations end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
88 89 90 |
# File 'lib/frigate/form/base.rb', line 88 def model @model end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
88 89 90 |
# File 'lib/frigate/form/base.rb', line 88 def properties @properties end |
Class Method Details
.associations ⇒ Object
gets just options for defined associations
66 67 68 |
# File 'lib/frigate/form/base.rb', line 66 def associations @associations.deep_dup || {} end |
.has_one(name, options = {}, &block) ⇒ Object
defines association (kinda property with properties)(root as well) of form/base
82 83 84 85 |
# File 'lib/frigate/form/base.rb', line 82 def has_one(name, ={}, &block) @associations ||= {} @associations[name.to_sym] = .merge({ block: block }) end |
.properties ⇒ Object
gets just options for defined properties
59 60 61 |
# File 'lib/frigate/form/base.rb', line 59 def properties @properties.deep_dup || {} end |
.property(name, options = {}) ⇒ Object
defines property (root) of form/base
73 74 75 76 |
# File 'lib/frigate/form/base.rb', line 73 def property(name, ={}) @properties ||= {} @properties[name.to_sym] = end |
Instance Method Details
#errors ⇒ ActiveModel::Errors
Initializes errors instance variable of ActiveModel::Errors type
103 104 105 |
# File 'lib/frigate/form/base.rb', line 103 def errors @errors ||= ActiveModel::Errors.new(self) end |
#valid? ⇒ Boolean
returns true if are there any errors messages in form errors
116 117 118 |
# File 'lib/frigate/form/base.rb', line 116 def valid? errors..empty? end |
#validate(*args) ⇒ Object
Validates form with params or model properties
108 109 110 111 112 |
# File 'lib/frigate/form/base.rb', line 108 def validate(*args) sync_properties_with_model_or_params(*args) sync_errors valid? end |