Module: CrudMethods::ClassMethods

Defined in:
lib/crud_methods.rb

Instance Method Summary collapse

Instance Method Details

#allObject

TODO Refactor into low level API



14
15
16
17
18
19
20
21
22
# File 'lib/crud_methods.rb', line 14

def all #TODO Refactor into low level API
  max_records = 200
  result = []
  begin
    batch = RubyZoho.configuration.api.some(self.module_name, result.count + 1, max_records)
    result.concat(batch) unless batch.nil?
  end until batch.nil? || (batch.length < max_records)
  result.collect { |r| new(r) }
end

#delete(id) ⇒ Object



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

def delete(id)
  RubyZoho.configuration.api.delete_record(self.module_name, id)
end

#find(id) ⇒ Object



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

def find(id)
  self.find_by_id(id)
end

#firstObject



9
10
11
12
# File 'lib/crud_methods.rb', line 9

def first
  r = RubyZoho.configuration.api.first(self.module_name)
  new(r[0])
end

#update(object_attribute_hash) ⇒ Object

Raises:

  • (RuntimeError)


32
33
34
35
36
37
38
# File 'lib/crud_methods.rb', line 32

def update(object_attribute_hash)
  raise(RuntimeError, 'No ID found', object_attribute_hash.to_s) if object_attribute_hash[:id].nil?
  id = object_attribute_hash[:id]
  object_attribute_hash.delete(:id)
  r = RubyZoho.configuration.api.update_record(self.module_name, id, object_attribute_hash)
  new(object_attribute_hash.merge!(r))
end

Raises:

  • (RuntimeError)


40
41
42
43
44
45
46
# File 'lib/crud_methods.rb', line 40

def update_related(object_attribute_hash)
  raise(RuntimeError, 'No ID found', object_attribute_hash.to_s) if object_attribute_hash[:id].nil?
  id = object_attribute_hash[:id]
  object_attribute_hash.delete(:id)
  RubyZoho.configuration.api.update_related_records(self.module_name, id, object_attribute_hash)
  find(id)
end