sinatra-env 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinatra-env.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Sinatra Env
2
+
3
+ A few methods for inquiring about the Sinatra/Rack environment a`la Rails.
4
+
5
+ ```ruby
6
+ Sinatra.env
7
+ # => "production"
8
+
9
+ Sinatra.env.production?
10
+ # => true
11
+
12
+ Sinatra.env.development?
13
+ # => false
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ app.rb
19
+
20
+ ```ruby
21
+ require 'bundler/setup'
22
+ require 'sinatra'
23
+ require 'sinatra-env'
24
+
25
+ # ./database.yml
26
+ # production:
27
+ # database: mysql://root@localhost/database_name
28
+ # development:
29
+ # database: sqlite://db/database.sqlite
30
+ database = YAML.load_file("database.yml")[Sinatra.env]
31
+
32
+ get '/' do
33
+ if Sinatra.env.development?
34
+ # do something
35
+ else
36
+ # do something else
37
+ end
38
+ end
39
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Env
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require "sinatra-env/version"
2
+
3
+ module Sinatra
4
+ def self.env
5
+ Env::StringInquirer.new(ENV["RACK_ENV"] || "development")
6
+ end
7
+
8
+ module Env
9
+ # Taken from Rails active_support/string_inquirer.rb
10
+ class StringInquirer < String
11
+ def method_missing(method_name, *arguments)
12
+ if method_name[-1, 1] == "?"
13
+ self == method_name[0..-2]
14
+ else
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "sinatra-env/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "sinatra-env"
8
+ s.version = Sinatra::Env::VERSION
9
+ s.authors = ["Sean Behan"]
10
+ s.email = ["bseanvt@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Sinatra Env}
13
+ s.description = %q{Sinatra.env a`la Rails.env}
14
+
15
+ s.rubyforge_project = "sinatra-env"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
2
+
3
+ require "test/unit"
4
+ require "sinatra-env"
5
+
6
+ class SinatraEnvironment < Test::Unit::TestCase
7
+ def test_sinatra_development_environment
8
+ # default to development
9
+ assert_equal "development", Sinatra.env
10
+ assert Sinatra.env.development?
11
+ end
12
+
13
+ def test_sinatra_production_environment
14
+ ENV["RACK_ENV"] = "production"
15
+ assert_equal "production", Sinatra.env
16
+ assert Sinatra.env.production?
17
+ assert !Sinatra.env.development?
18
+ assert !Sinatra.env.test?
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Behan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Sinatra.env a`la Rails.env
15
+ email:
16
+ - bseanvt@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - lib/sinatra-env.rb
26
+ - lib/sinatra-env/version.rb
27
+ - sinatra-env.gemspec
28
+ - test/sinatra_env_test.rb
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project: sinatra-env
49
+ rubygems_version: 1.8.15
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Sinatra Env
53
+ test_files:
54
+ - test/sinatra_env_test.rb