module Motion::Encodable

Public Class Methods

included(base) click to toggle source
# File lib/motion/encodable.rb, line 3
def self.included(base)
  base.extend ClassMethods
end

Public Instance Methods

encodeWithCoder(encoder) click to toggle source
# File lib/motion/encodable.rb, line 42
def encodeWithCoder(encoder)
  properties.each {|prop|
    encoder.encodeObject(self.instance_variable_get(:"@#{prop}"), forKey: prop.to_s)
  }
end
initWithCoder(decoder) click to toggle source

NSCoding protocol

# File lib/motion/encodable.rb, line 33
def initWithCoder(decoder)
  self.init
  properties.each {|prop|
    v = decoder.decodeObjectForKey(prop.to_s)
    self.instance_variable_set(:"@#{prop}", v) if v
  }
  self
end
properties() click to toggle source
# File lib/motion/encodable.rb, line 20
def properties
  self.class.instance_variable_get(:'@properties')
end
save_to_file(path) click to toggle source
# File lib/motion/encodable.rb, line 28
def save_to_file(path)
  NSKeyedArchiver.archiveRootObject(self, toFile: path)
end
to_data() click to toggle source
# File lib/motion/encodable.rb, line 24
def to_data
  NSKeyedArchiver.archivedDataWithRootObject(self)
end