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 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`
@@ -1,7 +1,29 @@
1
1
  module RailsEnvironment
2
2
 
3
- @@environments = nil
4
- @@mutex = Mutex.new
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
- @@mutex.synchronize do
14
- @@environments = Dir[Rails.root.join('config/environments/*.rb')].map { |f| File.basename(f, '.rb') }
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
- @@environments ||= load_environments
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)
@@ -1,3 +1,3 @@
1
1
  module RailsEnvironment
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-05-24 00:00:00.000000000 Z
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 envionment detection due to typos.
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 deciding what Rails environment you are in.
114
+ summary: Convenience methods for detecting Rails environment.
115
115
  test_files: []
116
116
  has_rdoc: