ment 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 978ab4a24e95bd5854bfc78ffa18791ef3905fe8
4
+ data.tar.gz: 44e2ff0cc6f41750e3d0bf3705f5c63579a685b4
5
+ SHA512:
6
+ metadata.gz: ba8bf64c8c9bed7abe4d0a483762e61af6d3dfbbab8dbfe7473d9d07a781253a0125952a019aee48ebe453a47ea909e095ed69e9ddc554debbf1552f5c91b704
7
+ data.tar.gz: d8a6e91c494c2f1eaad9f8e7fe41fda8e331d5a275986640a02e2f4455f1d27e3147d355661d82ff56a53ddf098853904e6ebdf11daa18fba1fd919cb1777c03
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Patricio Mac Adden
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # (environ)ment
2
+
3
+ (environ)ment adds methods for asking what's the value of `ENV['RACK_ENV']`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ment'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install ment
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Ment adds the following methods to your Rack app:
28
+
29
+ * `::environment`/`#environment`: returns the value of `ENV['RACK_ENV']`
30
+ * `::development?`/`#development?`: returns `true` if `ENV['RACK_ENV'] == 'development'`
31
+ * `::production?`/`#production?`: returns `true` if `ENV['RACK_ENV'] == 'production'`
32
+ * `::test?`/`#test?`: returns `true` if `ENV['RACK_ENV'] == 'test'`
33
+
34
+ ### Using [Rack](https://github.com/rack/rack) directly
35
+
36
+ ```ruby
37
+ require 'ment'
38
+
39
+ class App
40
+ include Ment
41
+
42
+ def call(env)
43
+ if production?
44
+ [200, {}, ['This is production']]
45
+ else
46
+ [200, {}, ["The current environment is #{environment}"]]
47
+ end
48
+ end
49
+ end
50
+
51
+ run App.new
52
+ ```
53
+
54
+ ### Using [Cuba](https://github.com/soveran/cuba)
55
+
56
+ ```ruby
57
+ require 'cuba'
58
+ require 'ment'
59
+
60
+ Cuba.plugin Ment
61
+
62
+ Cuba.define do
63
+ on production? do
64
+ res.write 'This is production'
65
+ end
66
+
67
+ on root do
68
+ res.write "The current environment is #{environment}"
69
+ end
70
+ end
71
+ ```
72
+
73
+ ### Using [Hobbit](https://github.com/patriciomacadden/hobbit)
74
+
75
+ ```ruby
76
+ require 'hobbit'
77
+ require 'ment'
78
+
79
+ class App < Hobbit::Base
80
+ include Ment
81
+
82
+ if production?
83
+ get '/' do
84
+ 'This is production'
85
+ end
86
+ end
87
+
88
+ get '/' do
89
+ "The current environment is #{environment}"
90
+ end
91
+ end
92
+ ```
93
+
94
+ ## Contributing
95
+
96
+ 1. Fork it
97
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
98
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
99
+ 4. Push to the branch (`git push origin my-new-feature`)
100
+ 5. Create a new Pull Request
101
+
102
+ ## License
103
+
104
+ See the [LICENSE](https://github.com/patriciomacadden/envi/blob/master/LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task default: :test
data/lib/ment.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Ment
2
+ VERSION = '0.0.1'
3
+
4
+ def self.included(othermod)
5
+ othermod.extend self
6
+ end
7
+
8
+ def environment
9
+ ENV['RACK_ENV'].to_sym
10
+ end
11
+
12
+ %w(development production test).each do |env|
13
+ define_method("#{env}?") { environment == env.to_sym }
14
+ end
15
+ end
data/ment.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ment'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ment'
8
+ spec.version = Ment::VERSION
9
+ spec.authors = ['Patricio Mac Adden']
10
+ spec.email = ['patriciomacadden@gmail.com']
11
+ spec.summary = %q{(environ)ment adds methods for asking what's the value of RACK_ENV.}
12
+ spec.description = %q{(environ)ment adds methods for asking what's the value of RACK_ENV.}
13
+ spec.homepage = 'https://github.com/patriciomacadden/ment'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'cuba'
23
+ spec.add_development_dependency 'hobbit'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'oktobertest'
26
+ spec.add_development_dependency 'oktobertest-contrib'
27
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'cuba'
4
+ require 'hobbit'
5
+ require 'oktobertest'
6
+ require 'oktobertest/contrib'
7
+
8
+ ENV['RACK_ENV'] = 'test'
9
+
10
+ module Oktobertest
11
+ class Test
12
+ def with_env(environment)
13
+ env, ENV['RACK_ENV'] = ENV['RACK_ENV'], environment
14
+ yield
15
+ ENV['RACK_ENV'] = env
16
+ end
17
+ end
18
+ end
19
+
20
+ App = Class.new do
21
+ include Ment
22
+ end
23
+
24
+ Cuba.plugin Ment
25
+
26
+ HobbitApp = Class.new Hobbit::Base do
27
+ include Ment
28
+ end
@@ -0,0 +1,95 @@
1
+ require 'helper'
2
+
3
+ scope 'Cuba integration' do
4
+ setup do
5
+ @app = Cuba.new
6
+ end
7
+
8
+ scope '::environment' do
9
+ test 'returns the current environment' do
10
+ with_env('development') do
11
+ assert_equal :development, Cuba.environment
12
+ end
13
+ end
14
+ end
15
+
16
+ scope '#environment' do
17
+ test 'returns the current environment' do
18
+ with_env('development') do
19
+ assert_equal :development, @app.environment
20
+ end
21
+ end
22
+ end
23
+
24
+ scope '::development?' do
25
+ test "returns true if ENV['RACK_ENV'] = :development" do
26
+ with_env('development') do
27
+ assert Cuba.development?
28
+ end
29
+ end
30
+
31
+ test "returns false if ENV['RACK_ENV'] != :development" do
32
+ assert !Cuba.development?
33
+ end
34
+ end
35
+
36
+ scope '#development?' do
37
+ test "returns true if ENV['RACK_ENV'] = :development" do
38
+ with_env('development') do
39
+ assert @app.development?
40
+ end
41
+ end
42
+
43
+ test "returns false if ENV['RACK_ENV'] != :development" do
44
+ assert !@app.development?
45
+ end
46
+ end
47
+
48
+ scope '::production?' do
49
+ test "returns true if ENV['RACK_ENV'] = :production" do
50
+ with_env('production') do
51
+ assert Cuba.production?
52
+ end
53
+ end
54
+
55
+ test "returns false if ENV['RACK_ENV'] != :production" do
56
+ assert !Cuba.production?
57
+ end
58
+ end
59
+
60
+ scope '#production?' do
61
+ test "returns true if ENV['RACK_ENV'] = :production" do
62
+ with_env('production') do
63
+ assert @app.production?
64
+ end
65
+ end
66
+
67
+ test "returns false if ENV['RACK_ENV'] != :production" do
68
+ assert !@app.production?
69
+ end
70
+ end
71
+
72
+ scope '::test?' do
73
+ test "returns true if ENV['RACK_ENV'] = :test" do
74
+ assert Cuba.test?
75
+ end
76
+
77
+ test "returns false if ENV['RACK_ENV'] != :test" do
78
+ with_env('development') do
79
+ assert !Cuba.test?
80
+ end
81
+ end
82
+ end
83
+
84
+ scope '#test?' do
85
+ test "returns true if ENV['RACK_ENV'] = :test" do
86
+ assert @app.test?
87
+ end
88
+
89
+ test "returns false if ENV['RACK_ENV'] != :test" do
90
+ with_env('development') do
91
+ assert !@app.test?
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,95 @@
1
+ require 'helper'
2
+
3
+ scope 'Hobbit integration' do
4
+ setup do
5
+ @app = HobbitApp.new
6
+ end
7
+
8
+ scope '::environment' do
9
+ test 'returns the current environment' do
10
+ with_env('development') do
11
+ assert_equal :development, HobbitApp.environment
12
+ end
13
+ end
14
+ end
15
+
16
+ scope '#environment' do
17
+ test 'returns the current environment' do
18
+ with_env('development') do
19
+ assert_equal :development, @app.to_app.class.environment
20
+ end
21
+ end
22
+ end
23
+
24
+ scope '::development?' do
25
+ test "returns true if ENV['RACK_ENV'] = :development" do
26
+ with_env('development') do
27
+ assert HobbitApp.development?
28
+ end
29
+ end
30
+
31
+ test "returns false if ENV['RACK_ENV'] != :development" do
32
+ assert !HobbitApp.development?
33
+ end
34
+ end
35
+
36
+ scope '#development?' do
37
+ test "returns true if ENV['RACK_ENV'] = :development" do
38
+ with_env('development') do
39
+ assert @app.to_app.class.development?
40
+ end
41
+ end
42
+
43
+ test "returns false if ENV['RACK_ENV'] != :development" do
44
+ assert !@app.to_app.class.development?
45
+ end
46
+ end
47
+
48
+ scope '::production?' do
49
+ test "returns true if ENV['RACK_ENV'] = :production" do
50
+ with_env('production') do
51
+ assert HobbitApp.production?
52
+ end
53
+ end
54
+
55
+ test "returns false if ENV['RACK_ENV'] != :production" do
56
+ assert !HobbitApp.production?
57
+ end
58
+ end
59
+
60
+ scope '#production?' do
61
+ test "returns true if ENV['RACK_ENV'] = :production" do
62
+ with_env('production') do
63
+ assert @app.to_app.class.production?
64
+ end
65
+ end
66
+
67
+ test "returns false if ENV['RACK_ENV'] != :production" do
68
+ assert !@app.to_app.class.production?
69
+ end
70
+ end
71
+
72
+ scope '::test?' do
73
+ test "returns true if ENV['RACK_ENV'] = :test" do
74
+ assert HobbitApp.test?
75
+ end
76
+
77
+ test "returns false if ENV['RACK_ENV'] != :test" do
78
+ with_env('development') do
79
+ assert !HobbitApp.test?
80
+ end
81
+ end
82
+ end
83
+
84
+ scope '#test?' do
85
+ test "returns true if ENV['RACK_ENV'] = :test" do
86
+ assert @app.to_app.class.test?
87
+ end
88
+
89
+ test "returns false if ENV['RACK_ENV'] != :test" do
90
+ with_env('development') do
91
+ assert !@app.to_app.class.test?
92
+ end
93
+ end
94
+ end
95
+ end
data/test/ment_test.rb ADDED
@@ -0,0 +1,95 @@
1
+ require 'helper'
2
+
3
+ scope Ment do
4
+ setup do
5
+ @app = App.new
6
+ end
7
+
8
+ scope '::environment' do
9
+ test 'returns the current environment' do
10
+ with_env('development') do
11
+ assert_equal :development, App.environment
12
+ end
13
+ end
14
+ end
15
+
16
+ scope '#environment' do
17
+ test 'returns the current environment' do
18
+ with_env('development') do
19
+ assert_equal :development, @app.environment
20
+ end
21
+ end
22
+ end
23
+
24
+ scope '::development?' do
25
+ test "returns true if ENV['RACK_ENV'] = :development" do
26
+ with_env('development') do
27
+ assert App.development?
28
+ end
29
+ end
30
+
31
+ test "returns false if ENV['RACK_ENV'] != :development" do
32
+ assert !App.development?
33
+ end
34
+ end
35
+
36
+ scope '#development?' do
37
+ test "returns true if ENV['RACK_ENV'] = :development" do
38
+ with_env('development') do
39
+ assert @app.development?
40
+ end
41
+ end
42
+
43
+ test "returns false if ENV['RACK_ENV'] != :development" do
44
+ assert !@app.development?
45
+ end
46
+ end
47
+
48
+ scope '::production?' do
49
+ test "returns true if ENV['RACK_ENV'] = :production" do
50
+ with_env('production') do
51
+ assert App.production?
52
+ end
53
+ end
54
+
55
+ test "returns false if ENV['RACK_ENV'] != :production" do
56
+ assert !App.production?
57
+ end
58
+ end
59
+
60
+ scope '#production?' do
61
+ test "returns true if ENV['RACK_ENV'] = :production" do
62
+ with_env('production') do
63
+ assert @app.production?
64
+ end
65
+ end
66
+
67
+ test "returns false if ENV['RACK_ENV'] != :production" do
68
+ assert !@app.production?
69
+ end
70
+ end
71
+
72
+ scope '::test?' do
73
+ test "returns true if ENV['RACK_ENV'] = :test" do
74
+ assert App.test?
75
+ end
76
+
77
+ test "returns false if ENV['RACK_ENV'] != :test" do
78
+ with_env('development') do
79
+ assert !App.test?
80
+ end
81
+ end
82
+ end
83
+
84
+ scope '#test?' do
85
+ test "returns true if ENV['RACK_ENV'] = :test" do
86
+ assert @app.test?
87
+ end
88
+
89
+ test "returns false if ENV['RACK_ENV'] != :test" do
90
+ with_env('development') do
91
+ assert !@app.test?
92
+ end
93
+ end
94
+ end
95
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Patricio Mac Adden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cuba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hobbit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: oktobertest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: oktobertest-contrib
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: "(environ)ment adds methods for asking what's the value of RACK_ENV."
98
+ email:
99
+ - patriciomacadden@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - lib/ment.rb
110
+ - ment.gemspec
111
+ - test/helper.rb
112
+ - test/ment/cuba_test.rb
113
+ - test/ment/hobbit_test.rb
114
+ - test/ment_test.rb
115
+ homepage: https://github.com/patriciomacadden/ment
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.2.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: "(environ)ment adds methods for asking what's the value of RACK_ENV."
139
+ test_files:
140
+ - test/helper.rb
141
+ - test/ment/cuba_test.rb
142
+ - test/ment/hobbit_test.rb
143
+ - test/ment_test.rb