Module: Motion::Encodable

Defined in:
lib/motion/encodable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/motion/encodable.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#encodeWithCoder(encoder) ⇒ Object



42
43
44
45
46
# 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) ⇒ Object

NSCoding protocol



33
34
35
36
37
38
39
40
# 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

#propertiesObject



20
21
22
# File 'lib/motion/encodable.rb', line 20

def properties
  self.class.instance_variable_get(:'@properties')
end

#save_to_file(path) ⇒ Object



28
29
30
# File 'lib/motion/encodable.rb', line 28

def save_to_file(path)
  NSKeyedArchiver.archiveRootObject(self, toFile: path)
end

#to_dataObject



24
25
26
# File 'lib/motion/encodable.rb', line 24

def to_data
  NSKeyedArchiver.archivedDataWithRootObject(self)
end