class Shanty::Env

Constants

CONFIG_FILE
DEFAULT_CONFIG

Public Class Methods

new() click to toggle source
# File lib/shanty/env.rb, line 10
def initialize
  Dir.chdir(root) do
    (config['require'] || {}).each do |requirement|
      requirement = "#{requirement}/**/*.rb" unless requirement.include?('.rb')
      Dir[requirement].each { |f| require(File.join(root, f)) }
    end
  end
end

Public Instance Methods

environment() click to toggle source
# File lib/shanty/env.rb, line 19
def environment
  @environment = ENV['SHANTY_ENV'] || 'local'
end
root() click to toggle source
# File lib/shanty/env.rb, line 23
def root
  @root ||= find_root
end

Private Instance Methods

config() click to toggle source
# File lib/shanty/env.rb, line 29
def config
  return @config unless @config.nil?

  file_config = YAML.load_file("#{root}/#{CONFIG_FILE}") || {}
  @config = DEFAULT_CONFIG.deep_merge!(file_config[environment])
end
find_root() click to toggle source
# File lib/shanty/env.rb, line 36
def find_root
  if root_dir.nil?
    fail "Could not find a #{CONFIG_FILE} file in this or any parent directories. \
    Please run `shanty init` in the directory you want to be the root of your project structure."
  end

  root_dir
end
root_dir() click to toggle source
# File lib/shanty/env.rb, line 45
def root_dir
  Pathname.new(Dir.pwd).ascend do |d|
    return d if d.join(CONFIG_FILE).exist?
  end
end