Class: Sufia::Analytics::Config

Inherits:
Object
  • Object
show all
Defined in:
app/services/sufia/analytics.rb

Constant Summary collapse

REQUIRED_KEYS =
%w(app_name app_version privkey_path privkey_secret client_email).freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



33
34
35
# File 'app/services/sufia/analytics.rb', line 33

def initialize(config)
  @config = config
end

Class Method Details

.load_from_yamlObject



21
22
23
24
25
26
27
28
29
# File 'app/services/sufia/analytics.rb', line 21

def self.load_from_yaml
  filename = File.join(Rails.root, 'config', 'analytics.yml')
  yaml = YAML.load(File.read(filename))
  unless yaml
    Rails.logger.error("Unable to fetch any keys from #{filename}.")
    return new({})
  end
  new yaml.fetch('analytics')
end

Instance Method Details

#valid?Boolean

Returns are all the required values present?.

Returns:

  • (Boolean)

    are all the required values present?



38
39
40
41
# File 'app/services/sufia/analytics.rb', line 38

def valid?
  config_keys = @config.keys
  REQUIRED_KEYS.all? { |required| config_keys.include?(required) }
end