Module: MotionModel::Model
- Defined in:
- lib/motion_model/model/persistence.rb,
lib/motion_model/model/transaction.rb
Defined Under Namespace
Modules: Transactions
Instance Method Summary collapse
-
#encodeWithCoder(coder) ⇒ Object
Follow Apple’s recommendation not to encode missing values.
- #initWithCoder(coder) ⇒ Object
Instance Method Details
#encodeWithCoder(coder) ⇒ Object
Follow Apple’s recommendation not to encode missing values.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/motion_model/model/persistence.rb', line 89 def encodeWithCoder(coder) columns.each do |attr| # Serialize attributes except the proxy has_many and belongs_to ones. unless [:belongs_to, :has_many].include? column_named(attr).type value = self.send(attr) unless value.nil? coder.encodeObject(value, forKey: attr.to_s) end end end end |
#initWithCoder(coder) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/motion_model/model/persistence.rb', line 63 def initWithCoder(coder) self.init new_tag_id = 1 columns.each do |attr| next if self.class.has_relation?(attr) # If a model revision has taken place, don't try to decode # something that's not there. if coder.containsValueForKey(attr.to_s) value = coder.decodeObjectForKey(attr.to_s) self.send("#{attr}=", value) else self.send("#{attr}=", nil) end # re-issue tags to make sure they are unique @tag = new_tag_id new_tag_id += 1 end save self end |