class Configureasy::ConfigParser
Load and parse content of config (YAML). Raise exception if config file not found
parser = Configureasy::ConfigParser.new('./config/config.yml') # => <# Configureasy::ConfigParser ... > parser.parse # => {:hash => :content}
Set environment to load specific part of config
parser = Configureasy::ConfigParser.new('./config/environments.yml', 'development') # => <# Configureasy::ConfigParser ... > parser.parse # => {:development => :content}
Attributes
environment[R]
Get environment to load data
filename[R]
Get config filename
Public Class Methods
new(filename, environment = nil)
click to toggle source
Initialize ConfigParser
instance. Params:
[+filename+]:: name of config file. [+environment+]:: load specific environment config (*optional*).
If config file not found raise an exeception.
Returns instance of [Configureasy::ConfigParser]
# File lib/configureasy/config_parser.rb, line 31 def initialize(filename, environment = nil) raise "Config #{filename} not found" unless File.exist? filename @filename = filename @environment = environment || current_environment end
Public Instance Methods
as_config()
click to toggle source
Returns config content as [Configureasy::Config]
# File lib/configureasy/config_parser.rb, line 46 def as_config Configureasy::Config.new self.parse end
parse()
click to toggle source
Returns config content
# File lib/configureasy/config_parser.rb, line 38 def parse content = YAML.load_file(filename) content.has_key?(self.environment) ? content[self.environment] : content rescue raise "Invalid config content for #{filename}" end
Private Instance Methods
current_environment()
click to toggle source
Gets the current environment. Returns current environment as string. If environment is not set returns 'development'
# File lib/configureasy/config_parser.rb, line 54 def current_environment ENV['RUBY_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end