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



54
55
56
# File 'lib/crud_methods.rb', line 54

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



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

def create(object_attribute_hash)
  initialize(object_attribute_hash)
  save
end

#saveObject



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

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



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

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



79
80
81
82
# File 'lib/crud_methods.rb', line 79

def up_date(object_attribute_hash)
  update_or_create_attrs(object_attribute_hash)
  self
end