Module: Contactually::Models::Model
- Included in:
- Address, Bucket, Contact, EmailAddress, Interaction, Participant, PhoneNumber, SocialMediaProfile, Tag, Task, User, Website
- Defined in:
- lib/contactually/models/model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/contactually/models/model.rb', line 73
def method_missing(method, *args, **kwargs)
string_method = method.to_s
if .has_key?(string_method)
[string_method]
else
super
end
end
|
Class Method Details
.included(base) ⇒ Object
4
5
6
|
# File 'lib/contactually/models/model.rb', line 4
def self.included(base)
base.send :extend, ClassMethods
end
|
Instance Method Details
#attributes ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/contactually/models/model.rb', line 18
def attributes
self.class.field_list.inject({}) do |acc, field_name|
value = send(field_name)
if Array === value
if value.first.respond_to?(:attributes)
value = value.map(&:attributes)
else
value
end
end
acc.merge(field_name.to_s => value)
end
end
|
#initialize(params = {}) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/contactually/models/model.rb', line 8
def initialize(params={})
params.each do |attr, _value|
self.send("#{attr}=", params.delete(attr)) if respond_to?(attr)
end if params
@_extra_attributes = params
super()
end
|
#inspect ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/contactually/models/model.rb', line 34
def inspect
inspection = attributes.map {|name, value|
"#{name}: #{value.inspect}"
}.join(", ")
"#<#{self.class} #{inspection}>"
end
|