Class: MarketoChef::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/marketo_chef/configuration.rb

Overview

Store and validate Marketo client configuration data

Constant Summary collapse

FIELDS =
%i[host client_id client_secret campaign_id].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Configuration

Returns a new instance of Configuration.



25
26
27
28
29
# File 'lib/marketo_chef/configuration.rb', line 25

def initialize(config = {})
  return unless config.any?

  config.map { |k, v| send("#{k}=", v) if FIELDS.include?(k) }
end

Instance Attribute Details

#campaign_idObject

Returns the value of attribute campaign_id.



22
23
24
# File 'lib/marketo_chef/configuration.rb', line 22

def campaign_id
  @campaign_id
end

#client_idObject

Returns the value of attribute client_id.



22
23
24
# File 'lib/marketo_chef/configuration.rb', line 22

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



22
23
24
# File 'lib/marketo_chef/configuration.rb', line 22

def client_secret
  @client_secret
end

#hostObject

Returns the value of attribute host.



23
24
25
# File 'lib/marketo_chef/configuration.rb', line 23

def host
  @host
end

Instance Method Details

#validateObject



39
40
41
42
43
44
# File 'lib/marketo_chef/configuration.rb', line 39

def validate
  missing = ->(f) { !instance_variable_defined?(:"@#{f}") }
  bomb    = ->(f) { raise "Required Marketo configuration undefined: #{f}" }

  FIELDS.select(&missing).map(&bomb)
end