Sha256: 0f834c5f13eed71ed9585d4be1f6a65f07b4d419368c5e76d179dda283aa1706

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

module Herbert
  module Configurator
    module Prepatch
      def self.registered(app)
        # Enable envs such as development;debug, where debug is herberts debug flag
        env = ENV['RACK_ENV'].split(';')
        ENV['RACK_ENV'], ENV['HERBERT_DEBUG'] = (env[0].empty? ? 'development' :  env[0]), (env[1] == 'debug' ? 1:0).to_s
        app.set :environment, ENV['RACK_ENV'].downcase.to_sym
      end
    end
    
    module Helpers
      def staging?
        ENV['RACK_ENV'] == 'staging'
      end

      def development?
        ENV['RACK_ENV'] == 'development' || (ENV['RACK_ENV'].empty?)
      end

      def debug?
        ENV['HERBERT_DEBUG'] == '1'
      end
    end

    def self.registered(app)
      app.enable :logging if app.development?
      #Assume loading by rackup...
      app.settings.root ||= File.join(Dir.getwd, 'lib')
      path = File.join(app.settings.root, 'config')
      # Load and evaluate common.rb and appropriate settings
      ['common.rb', app.environment.to_s + '.rb'].each do |file|
        cpath = File.join(path, file)
        if File.exists?(cpath) then
          # Ummm, I'm sorry?
          app.instance_eval(IO.read(cpath))
          log.h_debug("Applying #{cpath} onto the application")
        else
          log.h_warn("Configuration file #{cpath} not found")
        end
      end
    # So, we have all our settings... Please note that configure
    # block inside an App can overwrite our settings, but Herbert's
    # services are being created right now, so they only take in account
    # previous declarations
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
herbert-0.0.1 lib/herbert/Configurator.rb