Module: CrudMethods

Included in:
RubyZoho::Crm
Defined in:
lib/crud_methods.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/crud_methods.rb', line 3

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

Instance Method Details

#attach_file(file_path, file_name) ⇒ Object



46
47
48
# File 'lib/crud_methods.rb', line 46

def attach_file(file_path, file_name)
  RubyZoho.configuration.api.attach_file(self.class.module_name, self.send(primary_key), file_path, file_name)
end

#create(object_attribute_hash) ⇒ Object



50
51
52
53
# File 'lib/crud_methods.rb', line 50

def create(object_attribute_hash)
  initialize(object_attribute_hash)
  save
end

#saveObject



55
56
57
58
59
60
61
# File 'lib/crud_methods.rb', line 55

def save
  h = {}
  @fields.each { |f| h.merge!({ f => eval("self.#{f.to_s}") }) }
  h.delete_if { |k, v| v.nil? }
  r = RubyZoho.configuration.api.add_record(self.class.module_name, h)
  up_date(r)
end

#save_object(object) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/crud_methods.rb', line 63

def save_object(object)
  h = {}
  object.fields.each { |f| h.merge!({ f => object.send(f) }) }
  h.delete_if { |k, v| v.nil? }
  r = RubyZoho.configuration.api.add_record(object.module_name, h)
  up_date(r)
end

#up_date(object_attribute_hash) ⇒ Object



71
72
73
74
# File 'lib/crud_methods.rb', line 71

def up_date(object_attribute_hash)
  update_or_create_attrs(object_attribute_hash)
  self
end