class StatusPage::API::Component
Constants
- IMMUTABLE_ATTRIBUTES
- MUTABLE_ATTRIBUTES
- STATUSES
- SUCCESS_STATUS
Public Class Methods
new(id, page_id)
click to toggle source
# File lib/status_page/api/component.rb, line 14 def initialize(id, page_id) assign_attributes(id: id, page_id: page_id) end
Public Instance Methods
assign_attributes(attributes)
click to toggle source
# 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?()
click to toggle source
# File lib/status_page/api/component.rb, line 26 def failing? status != SUCCESS_STATUS end
get()
click to toggle source
# File lib/status_page/api/component.rb, line 18 def get assign_attributes(get_resource) end
resource_path()
click to toggle source
# File lib/status_page/api/component.rb, line 35 def resource_path "pages/#{page_id}/components/#{id}.json" end
save()
click to toggle source
# 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)
click to toggle source
# File lib/status_page/api/component.rb, line 30 def status=(status_type) validate_status(status_type) @status = status_type end
Private Instance Methods
mutable_attributes()
click to toggle source
# File lib/status_page/api/component.rb, line 47 def mutable_attributes MUTABLE_ATTRIBUTES.inject({}) do |result, attr_name| result[attr_name] = send(attr_name) if send(attr_name) result end end
validate_status(status_type)
click to toggle source
# File lib/status_page/api/component.rb, line 54 def validate_status(status_type) STATUSES.include?(status_type.to_s) || raise("Status '#{status_type}' not recognized. Valid statuses: #{STATUSES}") end