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
23
24
25
26
# File 'lib/crud_methods.rb', line 14

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

#delete(id) ⇒ Object



32
33
34
# File 'lib/crud_methods.rb', line 32

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

#find(id) ⇒ Object



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

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)


36
37
38
39
40
41
42
# File 'lib/crud_methods.rb', line 36

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)


44
45
46
47
48
49
50
# File 'lib/crud_methods.rb', line 44

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