Module: ZohoCrmUtils
- Included in:
- RubyZoho::Crm
- Defined in:
- lib/zoho_crm_utils.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #attr_writers ⇒ Object
- #create_accessor(klass, names) ⇒ Object
- #run_create_accessor(klass, meth) ⇒ Object
- #update_or_create_attrs(object_attribute_hash) ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 |
# File 'lib/zoho_crm_utils.rb', line 3 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#attr_writers ⇒ Object
71 72 73 |
# File 'lib/zoho_crm_utils.rb', line 71 def attr_writers self.methods.grep(/\w=$/) end |
#create_accessor(klass, names) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zoho_crm_utils.rb', line 48 def create_accessor(klass, names) names.each do |name| n = name.class == Symbol ? name.to_s : name n.gsub!(/[()]*/, '') raise(RuntimeError, "Bad field name: #{name}") unless self.class.method_name?(n) self.class.create_getter(klass, n) self.class.create_setter(klass, n) end names end |
#run_create_accessor(klass, meth) ⇒ Object
75 76 77 78 79 |
# File 'lib/zoho_crm_utils.rb', line 75 def run_create_accessor(klass, meth) method = meth.to_s.chop.to_sym RubyZoho::Crm.create_accessor(klass, [method]) nil end |
#update_or_create_attrs(object_attribute_hash) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/zoho_crm_utils.rb', line 59 def update_or_create_attrs(object_attribute_hash) retry_counter = object_attribute_hash.count begin object_attribute_hash.map { |(k, v)| public_send("#{k}=", v) } rescue NoMethodError => e m = e..slice(/`(.*?)=/) create_accessor(self.class, [m.gsub(/[`()]*/, '').chop]) unless m.nil? retry_counter -= 1 retry if retry_counter > 0 end end |