Module: Rhosync::Resource::ClassMethods

Defined in:
lib/rhosync/resource.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) get_partition



18
19
20
# File 'lib/rhosync/resource.rb', line 18

def get_partition
  @partition.is_a?(Proc) ? @partition.call : @partition
end

- (Object) partition(p)



14
15
16
# File 'lib/rhosync/resource.rb', line 14

def partition(p)
  @partition = p
end

- (Object) rhosync_receive_create(partition, attributes)



22
23
24
25
26
27
28
# File 'lib/rhosync/resource.rb', line 22

def rhosync_receive_create(partition, attributes)
  instance = self.send(:new)
  instance.send(:rhosync_apply_attributes, partition, attributes)
  instance.skip_rhosync_callbacks = true
  instance.save
  instance.id #=> return object id
end

- (Object) rhosync_receive_delete(partition, attributes)



39
40
41
42
43
44
45
# File 'lib/rhosync/resource.rb', line 39

def rhosync_receive_delete(partition, attributes)
  object_id = attributes['id']
  instance = self.send(is_datamapper? ? :get : :find, object_id)      
  instance.skip_rhosync_callbacks = true
  instance.destroy
  object_id
end

- (Object) rhosync_receive_update(partition, attributes)



30
31
32
33
34
35
36
37
# File 'lib/rhosync/resource.rb', line 30

def rhosync_receive_update(partition, attributes)
  object_id = attributes.delete('id')
  instance = self.send(is_datamapper? ? :get : :find, object_id)
  instance.send(:rhosync_apply_attributes, partition, attributes)
  instance.skip_rhosync_callbacks = true
  instance.save
  object_id
end