Module: Etna::Application
- Included in:
- EtnaApp
- 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
- #config(type, env = environment) ⇒ Object
- #configure(opts) ⇒ Object
-
#dev_route ⇒ Object
Used to find the application in development recorded vcr tests.
- #env_config(env = environment) ⇒ Object
- #environment ⇒ Object
- #find_descendents(klass) ⇒ Object
- #id ⇒ Object
- #initialize ⇒ Object
- #run_command(config, *args, &block) ⇒ Object
- #setup_logger ⇒ Object
- #sign ⇒ Object
Instance Attribute Details
#logger ⇒ Object (readonly)
the application logger is available globally
76 77 78 |
# File 'lib/etna/application.rb', line 76 def logger @logger end |
Class Method Details
.find(klass) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/etna/application.rb', line 21 def self.find(klass) namespace = klass.name.split('::').first if (namespace_klass = Kernel.const_get(namespace)) && (namespace_klass.respond_to? :instance) return namespace_klass.instance end if @@application return @@application.instance end raise "Could not find application instance from #{namespace}, and not subclass of Application found." end |
.included(other) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/etna/application.rb', line 13 def self.included(other) other.include Singleton other.include Etna::CommandExecutor @@application = other other.const_set(:GenerateCompletionScript, Class.new(Etna::GenerateCompletionScript)) end |
.instance ⇒ Object
44 45 46 |
# File 'lib/etna/application.rb', line 44 def self.instance @instance end |
.register(app) ⇒ Object
40 41 42 |
# File 'lib/etna/application.rb', line 40 def self.register(app) @instance = app end |
Instance Method Details
#config(type, env = environment) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/etna/application.rb', line 78 def config(type, env = environment) return nil if @config.nil? return nil if @config[env].nil? return nil unless @config[env].is_a?(Hash) @config[env][type] end |
#configure(opts) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/etna/application.rb', line 52 def configure(opts) @config = opts if ( = config(:rollbar)) && [:access_token] .configure do |config| config.access_token = [:access_token] end end end |
#dev_route ⇒ Object
Used to find the application in development recorded vcr tests. see spec/vcr.rb
36 37 38 |
# File 'lib/etna/application.rb', line 36 def dev_route "#{self.class.name.split('::').first.downcase}.development.local" end |
#env_config(env = environment) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/etna/application.rb', line 85 def env_config(env = environment) return nil if @config.nil? return nil if @config[env].nil? return nil unless @config[env].is_a?(Hash) @config[env] end |
#environment ⇒ Object
96 97 98 |
# File 'lib/etna/application.rb', line 96 def environment (ENV["#{self.class.name.upcase}_ENV"] || :development).to_sym end |
#find_descendents(klass) ⇒ Object
104 105 106 107 108 |
# File 'lib/etna/application.rb', line 104 def find_descendents(klass) ObjectSpace.each_object(Class).select do |k| k < klass end end |
#id ⇒ Object
100 101 102 |
# File 'lib/etna/application.rb', line 100 def id ENV["APP_NAME"] || self.class.name.snake_case.split(/::/).last end |
#initialize ⇒ Object
48 49 50 |
# File 'lib/etna/application.rb', line 48 def initialize Etna::Application.register(self) end |
#run_command(config, *args, &block) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/etna/application.rb', line 110 def run_command(config, *args, &block) cmd, cmd_args, cmd_kwds = find_command(*args) cmd.setup(config) if block_given? return unless yield [cmd, cmd_args] end cmd.execute(*cmd.fill_in_missing_params(cmd_args), **cmd_kwds) rescue => e .error(e) raise end |
#setup_logger ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/etna/application.rb', line 62 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
92 93 94 |
# File 'lib/etna/application.rb', line 92 def sign @sign ||= Etna::SignService.new(self) end |