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
- #attach_file(file_path, file_name) ⇒ Object
- #create(object_attribute_hash) ⇒ Object
- #save ⇒ Object
- #save_object(object) ⇒ Object
- #up_date(object_attribute_hash) ⇒ Object
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
50 51 52 |
# File 'lib/crud_methods.rb', line 50 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
54 55 56 57 |
# File 'lib/crud_methods.rb', line 54 def create(object_attribute_hash) initialize(object_attribute_hash) save end |
#save ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/crud_methods.rb', line 59 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
67 68 69 70 71 72 73 |
# File 'lib/crud_methods.rb', line 67 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
75 76 77 78 |
# File 'lib/crud_methods.rb', line 75 def up_date(object_attribute_hash) update_or_create_attrs(object_attribute_hash) self end |