environments 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: ef2b073bd88dcb7884c4e9096915efd2fec08974
4
+ data.tar.gz: 24a9a9e1720cea36c17eadc81f2dfc057e6b38bb
5
+ SHA512:
6
+ metadata.gz: 2974df4cb6d33aa9e510e26095e274ee5f2908b41ae58398877aab7de1f96a7dfd1a0544bd71c2f8e8ed5f5fc70d09bf148f592dacf33556c7ce14b7cfe96f25
7
+ data.tar.gz: bdec6e5141ad93eff778b78117926d47844d3ae139358bda6d68ed6c7f21840fb69430f3bcf39313e9b7c0cd26a403e770b9a998d5769bb3bc0230aa6bd6ec37
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in environments.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 TODO: Write your name
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,31 @@
1
+ # Environments
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'environments'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install environments
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/environments/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'environments/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "environments"
8
+ spec.version = Environments::VERSION
9
+ spec.authors = ["Caio Torres"]
10
+ spec.email = ["caio.a.torres@gmail.com"]
11
+ spec.summary = %q{A simple gem to help you check the environment your application is running}
12
+ spec.description = %q{A simple gem which gives you a lot of tools to check and set the current environment of your application}
13
+ spec.homepage = ""
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ spec.add_development_dependency "pry-meta"
25
+ end
@@ -0,0 +1,39 @@
1
+ require "environments/version"
2
+
3
+ module Environments
4
+ @@current_environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
5
+
6
+ def self.current
7
+ @@current_environment
8
+ end
9
+
10
+ def self.current=(value)
11
+ raise ArgumentError.new('Value must be a String') unless value.is_a? String
12
+
13
+ @@current_environment = value
14
+ end
15
+
16
+ def self.production?
17
+ @@current_environment == 'production'
18
+ end
19
+
20
+ def self.staging?
21
+ @@current_environment == 'staging'
22
+ end
23
+
24
+ def self.development?
25
+ @@current_environment == 'development'
26
+ end
27
+
28
+ def self.test?
29
+ @@current_environment == 'test'
30
+ end
31
+
32
+ def self.deployed?
33
+ production? || staging?
34
+ end
35
+
36
+ def self.reload
37
+ @@current_environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Environments
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,191 @@
1
+ require './lib/environments'
2
+
3
+ describe Environments do
4
+ describe '.current' do
5
+ context 'when only RACK_ENV is set' do
6
+ before do
7
+ ENV['RACK_ENV'] = 'rack_env'
8
+ described_class.reload
9
+ end
10
+
11
+ it 'returns the environment set on RACK_ENV var' do
12
+ expect(described_class.current).to eq 'rack_env'
13
+ end
14
+ end
15
+
16
+ context 'when only RAILS_ENV is set' do
17
+ before do
18
+ ENV.delete('RACK_ENV')
19
+ ENV['RAILS_ENV'] = 'rails_env'
20
+ described_class.reload
21
+ end
22
+
23
+ it 'returns the environment set on RAILS_ENV var' do
24
+ expect(described_class.current).to eq 'rails_env'
25
+ end
26
+ end
27
+
28
+ context 'when RACK_ENV and RAILS_ENV are set' do
29
+ before do
30
+ ENV['RACK_ENV'] = 'rack_env'
31
+ ENV['RAILS_ENV'] = 'rails_env'
32
+ described_class.reload
33
+ end
34
+
35
+ it 'returns the environment set on RACK_ENV var' do
36
+ expect(described_class.current).to eq 'rack_env'
37
+ end
38
+ end
39
+
40
+ context 'when none ENV vars are set' do
41
+ before do
42
+ ENV.delete('RACK_ENV')
43
+ ENV.delete('RAILS_ENV')
44
+
45
+ described_class.reload
46
+ end
47
+
48
+ it 'returns development' do
49
+ expect(described_class.current).to eq 'development'
50
+ end
51
+ end
52
+ end
53
+
54
+ describe '.current=' do
55
+ context 'when value is a String' do
56
+ before do
57
+ described_class.current = 'current'
58
+ end
59
+
60
+ it 'returns current' do
61
+ expect(described_class.current).to eq 'current'
62
+ end
63
+ end
64
+
65
+ context 'when value is not a String' do
66
+ it 'returns current' do
67
+ expect{ described_class.current = 1 }.to raise_error ArgumentError
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '.production?' do
73
+ context 'when current environment is production' do
74
+ before do
75
+ described_class.current = 'production'
76
+ end
77
+
78
+ it 'returns true' do
79
+ expect(described_class.production?).to be
80
+ end
81
+ end
82
+
83
+ context 'when current environment is not production' do
84
+ before do
85
+ described_class.current = 'environment'
86
+ end
87
+
88
+ it 'returns false' do
89
+ expect(described_class.production?).not_to be
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '.staging?' do
95
+ context 'when current environment is staging' do
96
+ before do
97
+ described_class.current = 'staging'
98
+ end
99
+
100
+ it 'returns true' do
101
+ expect(described_class.staging?).to be
102
+ end
103
+ end
104
+
105
+ context 'when current environment is not staging' do
106
+ before do
107
+ described_class.current = 'environment'
108
+ end
109
+
110
+ it 'returns false' do
111
+ expect(described_class.staging?).not_to be
112
+ end
113
+ end
114
+ end
115
+
116
+ describe '.development?' do
117
+ context 'when current environment is development' do
118
+ before do
119
+ described_class.current = 'development'
120
+ end
121
+
122
+ it 'returns true' do
123
+ expect(described_class.development?).to be
124
+ end
125
+ end
126
+
127
+ context 'when current environment is not development' do
128
+ before do
129
+ described_class.current = 'environment'
130
+ end
131
+
132
+ it 'returns false' do
133
+ expect(described_class.development?).not_to be
134
+ end
135
+ end
136
+ end
137
+
138
+ describe '.test?' do
139
+ context 'when current environment is test' do
140
+ before do
141
+ described_class.current = 'test'
142
+ end
143
+
144
+ it 'returns true' do
145
+ expect(described_class.test?).to be
146
+ end
147
+ end
148
+
149
+ context 'when current environment is not test' do
150
+ before do
151
+ described_class.current = 'environment'
152
+ end
153
+
154
+ it 'returns false' do
155
+ expect(described_class.test?).not_to be
156
+ end
157
+ end
158
+ end
159
+
160
+ describe '.deployed?' do
161
+ context 'when current environment is production' do
162
+ before do
163
+ described_class.current = 'production'
164
+ end
165
+
166
+ it 'returns true' do
167
+ expect(described_class.deployed?).to be
168
+ end
169
+ end
170
+
171
+ context 'when current environment is staging' do
172
+ before do
173
+ described_class.current = 'staging'
174
+ end
175
+
176
+ it 'returns true' do
177
+ expect(described_class.deployed?).to be
178
+ end
179
+ end
180
+
181
+ context 'when current environment is something else' do
182
+ before do
183
+ described_class.current = 'deployed'
184
+ end
185
+
186
+ it 'returns false' do
187
+ expect(described_class.deployed?).not_to be
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+
4
+ RSpec.configure do |config|
5
+ config.order = :random
6
+
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.syntax = :expect
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.syntax = :expect
13
+
14
+ mocks.verify_partial_doubles = true
15
+ mocks.verify_doubled_constant_names = true
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: environments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Caio Torres
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-11 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-meta
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
+ description: A simple gem which gives you a lot of tools to check and set the current
70
+ environment of your application
71
+ email:
72
+ - caio.a.torres@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - environments.gemspec
84
+ - lib/environments.rb
85
+ - lib/environments/version.rb
86
+ - spec/lib/environments_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A simple gem to help you check the environment your application is running
112
+ test_files:
113
+ - spec/lib/environments_spec.rb
114
+ - spec/spec_helper.rb