Class: Stoor::Config
- Inherits:
-
Object
- Object
- Stoor::Config
- Defined in:
- lib/stoor/config.rb
Instance Method Summary collapse
- #access_logger ⇒ Object
- #dirname ⇒ Object
- #dump_env ⇒ Object
- #env(token) ⇒ Object
- #env_prefix ⇒ Object
-
#initialize(file) ⇒ Config
constructor
A new instance of Config.
- #log(m) ⇒ Object
- #log_frag ⇒ Object
- #log_stream ⇒ Object
- #repo_missing?(path) ⇒ Boolean
Constructor Details
#initialize(file) ⇒ Config
Returns a new instance of Config.
5 6 7 |
# File 'lib/stoor/config.rb', line 5 def initialize(file) @file = file end |
Instance Method Details
#access_logger ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stoor/config.rb', line 33 def access_logger @access_logger ||= begin access_logger = ::Logger.new("#{log_frag}_access.log") access_logger.instance_eval do def write(msg); self.send(:<<, msg); end end access_logger.level = ::Logger::INFO access_logger end end |
#dirname ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/stoor/config.rb', line 9 def dirname @dirname ||= begin dirname = File.dirname(@file) dirname = `pwd`.chomp if dirname == '.' # Probably being run by Apache dirname end end |
#dump_env ⇒ Object
52 53 54 55 56 57 |
# File 'lib/stoor/config.rb', line 52 def dump_env log "#{env_prefix} env" ENV.each_pair do |k, v| log " #{k}: #{v}" if k =~ /\A#{env_prefix}/ end end |
#env(token) ⇒ Object
21 22 23 |
# File 'lib/stoor/config.rb', line 21 def env(token) ENV["#{env_prefix}_#{token}"] end |
#env_prefix ⇒ Object
17 18 19 |
# File 'lib/stoor/config.rb', line 17 def env_prefix @env_prefix ||= dirname.split(File::SEPARATOR).last.upcase end |
#log(m) ⇒ Object
25 26 27 |
# File 'lib/stoor/config.rb', line 25 def log(m) log_stream.write(m + "\n") end |
#log_frag ⇒ Object
29 30 31 |
# File 'lib/stoor/config.rb', line 29 def log_frag @log_frag ||= "#{dirname}/log/#{ENV['RACK_ENV']}" end |
#log_stream ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/stoor/config.rb', line 44 def log_stream @log_stream ||= begin log_stream = File.open("#{log_frag}.log", 'a+') log_stream.sync = true log_stream end end |
#repo_missing?(path) ⇒ Boolean
59 60 61 62 63 64 65 66 |
# File 'lib/stoor/config.rb', line 59 def repo_missing?(path) Gollum::Wiki.new(path) return nil rescue Gollum::InvalidGitRepositoryError, Gollum::NoSuchPathError return "Sorry, #{path} is not a git repository; you might try `cd #{path}; git init .`." rescue NameError return "Sorry, #{path} doesn't exist; set the environment variable STOOR_WIKI_PATH to point to a git repository." end |