class Suzanne::Env

Attributes

config_hash[R]

Public Class Methods

new() click to toggle source
# File lib/suzanne/env.rb, line 19
def initialize
  init_config_hash
end
rails() click to toggle source
# File lib/suzanne/env.rb, line 11
def self.rails
  ::Rails
end
root_relative_config_file_path() click to toggle source
# File lib/suzanne/env.rb, line 15
def self.root_relative_config_file_path
  ['config', 'application.yml'].freeze
end

Public Instance Methods

env() click to toggle source
# File lib/suzanne/env.rb, line 23
def env
  @env ||= Suzanne::EnvReader.new(
    env_config_hash
  )
rescue KeyError
  raise NoSegmentFound, "No segment found for #{rails.env}."
end

Private Instance Methods

check_config_file_exists() click to toggle source
# File lib/suzanne/env.rb, line 57
def check_config_file_exists
  return if config_file_exists?

  raise NoConfigFileFound
end
check_config_hash() click to toggle source
# File lib/suzanne/env.rb, line 63
def check_config_hash
  return if config_hash.is_a?(Hash)

  raise CouldNotParseConfigFile
end
config_file_exists?() click to toggle source
# File lib/suzanne/env.rb, line 69
def config_file_exists?
  File.exist? config_file_path
end
config_file_path() click to toggle source
# File lib/suzanne/env.rb, line 73
def config_file_path
  rails.root.join(*root_relative_config_file_path)
end
env_config_hash() click to toggle source
# File lib/suzanne/env.rb, line 47
def env_config_hash
  return {} if production?

  config_hash.fetch(
    rails.env.to_s
  )
rescue KeyError
  raise NoSegmentFound, "No segment found for #{rails.env}."
end
init_config_hash() click to toggle source
# File lib/suzanne/env.rb, line 35
def init_config_hash
  return if production?

  init_from_file
end
init_from_file() click to toggle source
# File lib/suzanne/env.rb, line 41
def init_from_file
  check_config_file_exists
  @config_hash = YAML.load_file(config_file_path)
  check_config_hash
end
production?() click to toggle source
# File lib/suzanne/env.rb, line 81
def production?
  rails.env.production?
end
rails() click to toggle source
# File lib/suzanne/env.rb, line 85
def rails
  self.class.rails
end
root_relative_config_file_path() click to toggle source
# File lib/suzanne/env.rb, line 77
def root_relative_config_file_path
  self.class.root_relative_config_file_path
end