Sha256: 7b61bd5507ba7e263885c0b37b9826fb9edc5bb472fb3f12bb237ee51e87ba1e

Contents?: true

Size: 1021 Bytes

Versions: 12

Compression:

Stored size: 1021 Bytes

Contents

require 'logger'
require 'pathname'

module Snails
  class Environment
    include Comparable

    def initialize(str); @str = str.to_s.freeze; end
    def to_s; @str; end
    def <=>(str); @str <=> str.to_s; end
    def inspect; @str.inspect; end

    %w(production staging development test).each do |key|
      define_method("#{key}?") { @str == key }
    end

    alias_method :dev?, :development?
    alias_method :prod?, :production?
    alias_method :testing?, :test?
  end

  def self.env
    @env ||= Environment.new(ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development')
  end

  def self.root
    @root ||= Pathname.new(Dir.pwd)
  end

  def self.apps
    @apps ||= []
  end

  def self.app
    puts "Warning: There's more than one Snail app defined!" if @apps.count > 1
    @apps.first
  end

  def self.logger
    @logged ||= Logger.new(File.exist?(root.join('log')) ? root.join('log', "#{Snails.env}.log") : nil)
  end
end

require 'snails/app' unless Snails.env.test?
puts "Loaded #{Snails.env} environment."

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
snails-0.3.7 lib/snails.rb
snails-0.3.6 lib/snails.rb
snails-0.3.5 lib/snails.rb
snails-0.3.4 lib/snails.rb
snails-0.3.3 lib/snails.rb
snails-0.3.2 lib/snails.rb
snails-0.3.1 lib/snails.rb
snails-0.3.0 lib/snails.rb
snails-0.2.9 lib/snails.rb
snails-0.2.8 lib/snails.rb
snails-0.2.7 lib/snails.rb
snails-0.2.6 lib/snails.rb