Class: FlapjackConfigurator::FlapjackSubObjectBase

Inherits:
FlapjackObjectBase show all
Defined in:
lib/flapjack_configurator/flapjack_sub_object_base.rb

Overview

Class representing a Flapjack sub-object (media, pagerduty creds, etc…)

Instance Attribute Summary

Attributes inherited from FlapjackObjectBase

#config, #obj_exists

Instance Method Summary collapse

Methods inherited from FlapjackObjectBase

#_load_from_api, #_reload_config, #_update, #delete, #id, #initialize

Constructor Details

This class inherits a constructor from FlapjackConfigurator::FlapjackObjectBase

Instance Method Details

#_create(contact_id, config) ⇒ Object

Create the object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/flapjack_configurator/flapjack_sub_object_base.rb', line 9

def _create(contact_id, config)
  fail("Object #{id} exists") if @obj_exists
  # AFAIK there is not an easy way to convert hash keys to symbols outside of Rails
  sym_config = {}
  config.each { |k, v| sym_config[k.to_sym] = v }

  msg_id = id.nil? ? sym_config[:type] : id
  @logger.info("Creating #{@log_name} #{msg_id} for contact #{contact_id}")
  @logger.debug("#{@log_name} #{id} config: #{sym_config}")
  fail "Failed to create #{@log_name} #{id}" unless @create_method.call(contact_id, sym_config)
  _reload_config
end

#_filter_config(config) ⇒ Object



22
23
24
25
26
# File 'lib/flapjack_configurator/flapjack_sub_object_base.rb', line 22

def _filter_config(config)
  filtered_config = config.select { |k, _| @allowed_config_keys.include? k.to_sym }
  @logger.debug("#{@log_name} #{id}: Config keys filtered out: #{config.keys - filtered_config.keys}")
  return filtered_config
end

#update(config) ⇒ Object

Update the media from a config hash of updated values



29
30
31
# File 'lib/flapjack_configurator/flapjack_sub_object_base.rb', line 29

def update(config)
  return _update(_filter_config(config))
end