Class: RubyZoho::Crm
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#attr_writers, #create_accessor, included, #run_create_accessor, #update_or_create_attrs
#attach_file, #create, included, #save, #save_object, #up_date
Constructor Details
#initialize(object_attribute_hash = {}) ⇒ Crm
Returns a new instance of Crm.
15
16
17
18
19
20
21
22
23
|
# File 'lib/crm.rb', line 15
def initialize(object_attribute_hash = {})
@fields = object_attribute_hash == {} ? RubyZoho.configuration.api.fields(self.class.module_name) :
object_attribute_hash.keys
create_accessor(self.class, @fields)
create_accessor(self.class, [:module_name])
public_send(:module_name=, self.class.module_name)
update_or_create_attrs(object_attribute_hash)
self
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/crm.rb', line 33
def method_missing(meth, *args, &block)
if [:seid=, :semodule=].index(meth)
run_create_accessor(self.class, meth)
self.send(meth, args[0])
else
super
end
end
|
Class Attribute Details
.module_name ⇒ Object
Returns the value of attribute module_name.
8
9
10
|
# File 'lib/crm.rb', line 8
def module_name
@module_name
end
|
Class Method Details
.method_missing(meth, *args, &block) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/crm.rb', line 25
def self.method_missing(meth, *args, &block)
if meth.to_s =~ /^find_by_(.+)$/
run_find_by_method($1, *args, &block)
else
super
end
end
|
.run_find_by_method(attrs, *args, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/crm.rb', line 42
def self.run_find_by_method(attrs, *args, &block)
attrs = attrs.split('_and_')
conditions = Array.new(args.size, '=')
h = RubyZoho.configuration.api.find_records(
self.module_name, ApiUtils.string_to_symbol(attrs[0]), conditions[0], args[0]
)
return h.collect { |r| new(r) } unless h.nil?
nil
end
|
.setup_classes ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/crm.rb', line 64
def self.setup_classes
RubyZoho.configuration.crm_modules.each do |module_name|
klass_name = module_name.chop
c = Class.new(self) do
include RubyZoho
include ActiveModel
extend ActiveModel::Naming
attr_reader :fields
@module_name = module_name
end
const_set(klass_name, c)
end
end
|
Instance Method Details
#<<(object) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/crm.rb', line 52
def << object
object.semodule = self.module_name
object.seid = self.id
object.fields << :seid
object.fields << :semodule
save_object(object)
end
|
#primary_key ⇒ Object
60
61
62
|
# File 'lib/crm.rb', line 60
def primary_key
RubyZoho.configuration.api.primary_key(self.class.module_name)
end
|