Class: Cfror::Field
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cfror::Field
- Defined in:
- app/models/cfror/field.rb
Instance Attribute Summary collapse
-
#value_object ⇒ Object
Returns the value of attribute value_object.
Instance Method Summary collapse
- #save_option!(model, value) ⇒ Object
- #save_value!(model, value) ⇒ Object
- #set_value_for(model) ⇒ Object
- #value ⇒ Object
Instance Attribute Details
#value_object ⇒ Object
Returns the value of attribute value_object.
5 6 7 |
# File 'app/models/cfror/field.rb', line 5 def value_object @value_object end |
Instance Method Details
#save_option!(model, value) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/models/cfror/field.rb', line 37 def save_option!(model, value) option_data = self..find_by(dataable: model) if option_data option_data.update_attribute(:select_option, SelectOption.find(value)) else .create!(dataable: model, select_option: SelectOption.find(value)) end end |
#save_value!(model, value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/cfror/field.rb', line 22 def save_value!(model, value) type = field_type.to_sym if type == :option save_option!(model, value) else data = send("#{field_type}s").find_by(dataable: model) if data data.update_attribute(:body, value) else send("#{field_type}s").create!(dataable: model, body: value) end end end |
#set_value_for(model) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'app/models/cfror/field.rb', line 46 def set_value_for(model) type = field_type.to_sym self.value_object = if type == :option self..find_by(dataable: model).try(:select_option) else send("#{field_type}s").find_by(dataable: model) end end |
#value ⇒ Object
56 57 58 |
# File 'app/models/cfror/field.rb', line 56 def value self.value_object.try(:body) end |