Class: SupportOps::Slack::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/support_ops_slack/slack/base.rb

Overview

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

Author:

  • Jason Colyer

Since:

  • 1.0.0

Direct Known Subclasses

Messages

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_slack/slack/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_slack/slack/base.rb', line 29

def attributes
  @attributes || []
end

.clientObject

Since:

  • 1.0.0



14
15
16
# File 'lib/support_ops_slack/slack/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_slack/slack/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_slack/slack/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_slack/slack/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



59
60
61
# File 'lib/support_ops_slack/slack/base.rb', line 59

def client=(new_client)
  @client = new_client
end

#save!Object

Since:

  • 1.0.0



54
55
56
57
# File 'lib/support_ops_slack/slack/base.rb', line 54

def save!
  ensure_client_present!
  create_record
end

#store_original_attributesObject

Since:

  • 1.0.0



47
48
49
50
51
52
# File 'lib/support_ops_slack/slack/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