Class: Kludge::One
Instance Attribute Summary
Attributes inherited from Part
#children, #errors, #name, #parent, #value
Instance Method Summary collapse
Methods inherited from Part
#dependency, #dependent?, #initialize, #many?, #one?, #valid?
Constructor Details
This class inherits a constructor from Kludge::Part
Instance Method Details
#save ⇒ Object
4 5 6 7 |
# File 'lib/kludge/one.rb', line 4 def save value.save super end |
#validate ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kludge/one.rb', line 9 def validate if !value.valid? value.errors.each do |attribute, errors_array| errors_array.each do |msg| errors.add(attribute, msg) unless errors.added?(attribute, msg) end end false else true end end |
#value=(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kludge/one.rb', line 22 def value=(value) p value @value = if value.kind_of?(Hash) if value[:id] @name.to_s.classify.constantize.find(value.delete(:id)).tap { |v| v.assign_attributes(value) } else @name.to_s.classify.constantize.new(value) end else value end end |