Class: SupportOps::Calendly::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/support_ops_calendly/calendly/base.rb

Overview

Defines the class Base within the module SupportOps::Calendly.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, client = nil) ⇒ Base

Returns a new instance of Base.

Since:

  • 1.0.0



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

.attributesObject

Since:

  • 1.0.0



29
30
31
# File 'lib/support_ops_calendly/calendly/base.rb', line 29

def attributes
  @attributes || []
end

.clientObject

Since:

  • 1.0.0



14
15
16
# File 'lib/support_ops_calendly/calendly/base.rb', line 14

def client
  Configuration.config.client
end

.configure {|Configuration.config| ... } ⇒ Object

Yields:

Since:

  • 1.0.0



18
19
20
# File 'lib/support_ops_calendly/calendly/base.rb', line 18

def configure
  yield Configuration.config
end

.define_attributes(*attrs) ⇒ Object

Since:

  • 1.0.0



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

Since:

  • 1.0.0



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

Since:

  • 1.0.0



100
101
102
# File 'lib/support_ops_calendly/calendly/base.rb', line 100

def client=(new_client)
  @client = new_client
end

#delete!Object

Since:

  • 1.0.0



95
96
97
98
# File 'lib/support_ops_calendly/calendly/base.rb', line 95

def delete!
  ensure_client_present!
  delete_record
end

#findObject

Since:

  • 1.0.0



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

Since:

  • 1.0.0



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

#membersObject

Since:

  • 1.0.0



58
59
60
61
# File 'lib/support_ops_calendly/calendly/base.rb', line 58

def members
  ensure_client_present!
  members_record
end

#save!Object

Since:

  • 1.0.0



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_attributesObject

Since:

  • 1.0.0



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

#uuidObject

Since:

  • 1.0.0



54
55
56
# File 'lib/support_ops_calendly/calendly/base.rb', line 54

def uuid
  uuid_record
end