Class: Perc::Application
- Inherits:
-
Object
- Object
- Perc::Application
- Defined in:
- lib/perc/application.rb
Overview
Class for holding stuff you might find in a typical application
Defined Under Namespace
Classes: Config
Constant Summary collapse
- LoggerLevels =
{ 'DEBUG' => Logger::DEBUG, 'INFO' => Logger::INFO, 'WARN' => Logger::WARN, 'ERROR' => Logger::ERROR }
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #boot ⇒ Object
- #commands {|cli| ... } ⇒ Object
- #config {|@config| ... } ⇒ Object
- #config_for(thing, required = true) ⇒ Object
-
#initialize(options) ⇒ Application
constructor
A new instance of Application.
- #load_rake ⇒ Object
Constructor Details
#initialize(options) ⇒ Application
Returns a new instance of Application.
34 35 36 37 38 39 40 41 42 |
# File 'lib/perc/application.rb', line 34 def initialize() @root = .fetch(:root) @env = ActiveSupport::StringInquirer.new(.fetch(:env)) config do |c| Dir[root.join('app', '*')].each do |d| c.autoload_paths << d.to_s end end end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
30 31 32 |
# File 'lib/perc/application.rb', line 30 def env @env end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
30 31 32 |
# File 'lib/perc/application.rb', line 30 def logger @logger end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
30 31 32 |
# File 'lib/perc/application.rb', line 30 def root @root end |
Instance Method Details
#boot ⇒ Object
70 71 72 73 74 75 |
# File 'lib/perc/application.rb', line 70 def boot initialize_logging setup_autoload_directories require_environment run_initializers end |
#commands {|cli| ... } ⇒ Object
83 84 85 86 87 88 |
# File 'lib/perc/application.rb', line 83 def commands require 'perc/cli_wrapper' cli = CliWrapper.new yield(cli) if block_given? cli end |
#config {|@config| ... } ⇒ Object
77 78 79 80 81 |
# File 'lib/perc/application.rb', line 77 def config @config ||= Config.new yield(@config) if block_given? @config end |
#config_for(thing, required = true) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/perc/application.rb', line 57 def config_for(thing, required = true) file = root.join('config', "#{thing}.yml") if file.exist? require 'yaml' require 'erb' thing_parsed = (YAML.load(ERB.new(file.read).result) || {})[env] return (thing_parsed and thing_parsed.with_indifferent_access) unless (thing_parsed.nil? && required) raise Config::EnvironmentMissingError, "config_for(#{thing}) nil for env: #{env}" else raise Config::FileMissingError, "Could not load configuration. No such file: #{file}" end end |
#load_rake ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/perc/application.rb', line 48 def load_rake rake_files = Dir[File.('../tasks/*.rake', __FILE__)] + Dir[root.join('lib/tasks/*.rake')] rake_files.each do |f| load(f) end end |