Module: Etna::Application
- Defined in:
- lib/etna/application.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
the application logger is available globally.
Class Method Summary collapse
Instance Method Summary collapse
- #commands ⇒ Object
- #config(type) ⇒ Object
- #configure(opts) ⇒ Object
- #environment ⇒ Object
- #find_descendents(klass) ⇒ Object
- #initialize ⇒ Object
- #run_command(config, cmd = :help, *args) ⇒ Object
- #setup_logger ⇒ Object
- #sign ⇒ Object
Instance Attribute Details
#logger ⇒ Object (readonly)
the application logger is available globally
51 52 53 |
# File 'lib/etna/application.rb', line 51 def logger @logger end |
Class Method Details
.find(klass) ⇒ Object
14 15 16 17 18 |
# File 'lib/etna/application.rb', line 14 def self.find(klass) Kernel.const_get( klass.name.split('::').first ).instance end |
.included(other) ⇒ Object
10 11 12 |
# File 'lib/etna/application.rb', line 10 def self.included(other) other.include Singleton end |
.instance ⇒ Object
24 25 26 |
# File 'lib/etna/application.rb', line 24 def self.instance @instance end |
.register(app) ⇒ Object
20 21 22 |
# File 'lib/etna/application.rb', line 20 def self.register(app) @instance = app end |
Instance Method Details
#commands ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/etna/application.rb', line 81 def commands @commands ||= Hash[ find_descendents(Etna::Command).map do |c| cmd = c.new [ cmd.name, cmd ] end ] end |
#config(type) ⇒ Object
53 54 55 |
# File 'lib/etna/application.rb', line 53 def config(type) @config[environment][type] end |
#configure(opts) ⇒ Object
32 33 34 |
# File 'lib/etna/application.rb', line 32 def configure(opts) @config = opts end |
#environment ⇒ Object
61 62 63 |
# File 'lib/etna/application.rb', line 61 def environment (ENV["#{self.class.name.upcase}_ENV"] || :development).to_sym end |
#find_descendents(klass) ⇒ Object
65 66 67 68 69 |
# File 'lib/etna/application.rb', line 65 def find_descendents(klass) ObjectSpace.each_object(Class).select do |k| k < klass end end |
#initialize ⇒ Object
28 29 30 |
# File 'lib/etna/application.rb', line 28 def initialize Etna::Application.register(self) end |
#run_command(config, cmd = :help, *args) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/etna/application.rb', line 71 def run_command(config, cmd = :help, *args) cmd = cmd.to_sym if commands.key?(cmd) commands[cmd].setup(config) commands[cmd].execute(*args) else commands[:help].execute end end |
#setup_logger ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/etna/application.rb', line 36 def setup_logger @logger = Etna::Logger.new( # The name of the log_file, required. config(:log_file), # Number of old copies of the log to keep. config(:log_copies) || 5, # How large the log can get before overturning. config(:log_size) || 1048576 ) log_level = (config(:log_level) || 'warn').upcase.to_sym @logger.level = Logger.const_defined?(log_level) ? Logger.const_get(log_level) : Logger::WARN end |
#sign ⇒ Object
57 58 59 |
# File 'lib/etna/application.rb', line 57 def sign @sign ||= Etna::SignService.new(self) end |