Class: StatusPage::API::Component

Inherits:
Base
  • Object
show all
Defined in:
lib/status_page/api/component.rb

Constant Summary collapse

MUTABLE_ATTRIBUTES =
%i[name description status]
IMMUTABLE_ATTRIBUTES =
%i[id page_id group_id created_at updated_at position]
STATUSES =
%w[operational degraded_performance partial_outage major_outage]
SUCCESS_STATUS =
'operational'

Instance Method Summary collapse

Methods inherited from Base

#execute, #get_resource, #patch_resource

Constructor Details

#initialize(id, page_id) ⇒ Component

Returns a new instance of Component.



14
15
16
# File 'lib/status_page/api/component.rb', line 14

def initialize(id, page_id)
  assign_attributes(id: id, page_id: page_id)
end

Instance Method Details

#assign_attributes(attributes) ⇒ Object



39
40
41
42
43
# File 'lib/status_page/api/component.rb', line 39

def assign_attributes(attributes)
  attributes.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

#failing?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/status_page/api/component.rb', line 26

def failing?
  status != SUCCESS_STATUS
end

#getObject



18
19
20
# File 'lib/status_page/api/component.rb', line 18

def get
  assign_attributes(get_resource)
end

#resource_pathObject



35
36
37
# File 'lib/status_page/api/component.rb', line 35

def resource_path
  "pages/#{page_id}/components/#{id}.json"
end

#saveObject



22
23
24
# File 'lib/status_page/api/component.rb', line 22

def save
  assign_attributes(patch_resource({component: mutable_attributes})) if mutable_attributes.any?
end

#status=(status_type) ⇒ Object



30
31
32
33
# File 'lib/status_page/api/component.rb', line 30

def status=(status_type)
  validate_status(status_type)
  @status = status_type
end