Class: SupportOps::Calendly::Base
- Inherits:
-
Object
- Object
- SupportOps::Calendly::Base
show all
- Defined in:
- lib/support_ops_calendly/calendly/base.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}, client = nil) ⇒ Base
Returns a new instance of Base.
40
41
42
43
44
45
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 40
def initialize(attributes = {}, client = nil)
@client = client
@original_attributes = {}
set_attributes(attributes)
store_original_attributes
end
|
Class Method Details
.attributes ⇒ Object
29
30
31
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 29
def attributes
@attributes || []
end
|
.client ⇒ Object
14
15
16
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 14
def client
Configuration.config.client
end
|
18
19
20
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 18
def configure
yield Configuration.config
end
|
.define_attributes(*attrs) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 22
def define_attributes(*attrs)
@attributes = attrs
attrs.each do |attr|
attr_accessor attr
end
end
|
.readonly_attributes(*attrs) ⇒ Object
33
34
35
36
37
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 33
def readonly_attributes(*attrs)
return @readonly_attributes || [] if attrs.empty?
@readonly_attributes = attrs
end
|
Instance Method Details
#client=(new_client) ⇒ Object
100
101
102
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 100
def client=(new_client)
@client = new_client
end
|
#delete! ⇒ Object
95
96
97
98
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 95
def delete!
ensure_client_present!
delete_record
end
|
#find ⇒ Object
63
64
65
66
67
68
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 63
def find
ensure_client_present!
set_attributes(get_record)
store_original_attributes
self
end
|
#find! ⇒ Object
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 70
def find!
ensure_client_present!
attrs = get_record
if attrs == nil
raise "Unable to locate #{self.class.name.demodulize.singularize.downcase} '#{self.uri}'"
end
set_attributes(attrs)
store_original_attributes
self
end
|
#members ⇒ Object
58
59
60
61
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 58
def members
ensure_client_present!
members_record
end
|
#save! ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 81
def save!
ensure_client_present!
new_data = if id.nil?
create_record
else
update_record
end
new_data.each do |key, value|
self.instance_variable_set("@#{key}", value) if self.respond_to?("#{key}=")
end
store_original_attributes
self
end
|
#store_original_attributes ⇒ Object
47
48
49
50
51
52
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 47
def store_original_attributes
@original_attributes = {}
self.class.attributes.each do |attr|
@original_attributes[attr] = instance_variable_get("@#{attr}")
end
end
|
#uuid ⇒ Object
54
55
56
|
# File 'lib/support_ops_calendly/calendly/base.rb', line 54
def uuid
uuid_record
end
|