rails_environment 0.0.2 → 0.0.3
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/README.md +13 -2
- data/lib/rails_environment.rb +41 -5
- data/lib/rails_environment/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -23,10 +23,10 @@ if Rails.env.productoin? ...
|
|
23
23
|
```
|
24
24
|
So we get a runtime error if we misspell an environment instead of a silent bug.
|
25
25
|
|
26
|
-
For standard Rails applications with `development`, `test` and `production` environments you get:
|
27
|
-
|
28
26
|
## Available methods
|
29
27
|
|
28
|
+
For standard Rails applications with `development`, `test` and `production` environments you get:
|
29
|
+
|
30
30
|
**Predicate method for each environment**
|
31
31
|
|
32
32
|
* `RailsEnvironment.development?`
|
@@ -45,6 +45,17 @@ For standard Rails applications with `development`, `test` and `production` envi
|
|
45
45
|
* `RailsEnvironment.not_test_or_production?`
|
46
46
|
* etc.
|
47
47
|
|
48
|
+
**Short and Long environment names**
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
RailsEnvironment.short #=> 'DEV'
|
52
|
+
RailsEnvironment.long #=> 'Development'
|
53
|
+
|
54
|
+
# customize the short/long names
|
55
|
+
RailsEnvironment.environment_strings['development']['short'] = 'DVL'
|
56
|
+
RailsEnvironment.short #=> 'DVL'
|
57
|
+
```
|
58
|
+
|
48
59
|
## Notes
|
49
60
|
|
50
61
|
* The methods available are based on the actual environments, i.e., `../config/environments/*.rb`
|
data/lib/rails_environment.rb
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
module RailsEnvironment
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
@mutex = Mutex.new
|
4
|
+
@environments = nil
|
5
|
+
@environment_strings = {
|
6
|
+
'development' => {
|
7
|
+
'short' => 'DEV',
|
8
|
+
'long' => 'Development'
|
9
|
+
},
|
10
|
+
'test' => {
|
11
|
+
'short' => 'TST',
|
12
|
+
'long' => 'Test'
|
13
|
+
},
|
14
|
+
'staging' => {
|
15
|
+
'short' => 'STG',
|
16
|
+
'long' => 'Staging'
|
17
|
+
},
|
18
|
+
'quality_assurance' => {
|
19
|
+
'short' => 'QA',
|
20
|
+
'long' => 'Quality Assurance'
|
21
|
+
},
|
22
|
+
'production' => {
|
23
|
+
'short' => 'PRD',
|
24
|
+
'long' => 'Production'
|
25
|
+
},
|
26
|
+
}
|
5
27
|
|
6
28
|
class << self
|
7
29
|
|
@@ -9,14 +31,28 @@ module RailsEnvironment
|
|
9
31
|
Rails.env
|
10
32
|
end
|
11
33
|
|
34
|
+
def short
|
35
|
+
strings = @environment_strings[rails_env]
|
36
|
+
(strings && strings['short']) || rails_env
|
37
|
+
end
|
38
|
+
|
39
|
+
def long
|
40
|
+
strings = @environment_strings[rails_env]
|
41
|
+
(strings && strings['long']) || rails_env
|
42
|
+
end
|
43
|
+
|
12
44
|
def load_environments
|
13
|
-
|
14
|
-
|
45
|
+
@mutex.synchronize do
|
46
|
+
@environments = Dir[Rails.root.join('config/environments/*.rb')].map { |f| File.basename(f, '.rb') }
|
15
47
|
end
|
16
48
|
end
|
17
49
|
|
18
50
|
def environments
|
19
|
-
|
51
|
+
@environments ||= load_environments
|
52
|
+
end
|
53
|
+
|
54
|
+
def environment_strings
|
55
|
+
@environment_strings
|
20
56
|
end
|
21
57
|
|
22
58
|
def method_missing(method, *args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_environment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
description: Eliminate silent errors in
|
78
|
+
description: Eliminate silent errors in Rails environment detection due to typos.
|
79
79
|
email:
|
80
80
|
- steve.downtown@gmail.com
|
81
81
|
executables: []
|
@@ -111,6 +111,6 @@ rubyforge_project:
|
|
111
111
|
rubygems_version: 1.8.25
|
112
112
|
signing_key:
|
113
113
|
specification_version: 3
|
114
|
-
summary: Convenience methods for
|
114
|
+
summary: Convenience methods for detecting Rails environment.
|
115
115
|
test_files: []
|
116
116
|
has_rdoc:
|