rails_environment 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## v 0.0.1
4
+
5
+ Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) Steve Downey <steve.downtown@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # rails_environment
2
+
3
+ [![Build Status](https://travis-ci.org/stevedowney/rails_environment.png)](https://travis-ci.org/stevedowney/rails_environment)
4
+ [![Code Climate](https://codeclimate.com/github/stevedowney/rails_environment.png)](https://codeclimate.com/github/stevedowney/rails_environment)
5
+ [![Coverage Status](https://coveralls.io/repos/stevedowney/rails_environment/badge.png)](https://coveralls.io/r/stevedowney/rails_environment)
6
+
7
+ This class facilitates code like:
8
+ ```ruby
9
+ if RailsEnvironment.production?
10
+ # do stuff only in production environment
11
+ end
12
+ ```
13
+
14
+ This prevent typos like:
15
+
16
+ ```ruby
17
+ if Rails.env == 'productoin' ...
18
+ if Rails.env.productoin? ...
19
+ ```
20
+ so we get a runtime error if we misspell an environment (v. a bug)
21
+
22
+ For standard Rails applications with `development`, `test` and `production` environments you get:
23
+
24
+ ## Available methods
25
+
26
+ **Predicate method for each environment**
27
+
28
+ * `RailsEnvironment.development?`
29
+ * `RailsEnvironment.test?`
30
+ * `RailsEnvironment.production?`
31
+
32
+ **Negated predicate methods**
33
+
34
+ * `RailsEnvironment.not_development?`
35
+ * `RailsEnvironment.not_test?`
36
+ * `RailsEnvironment.not_production?`
37
+
38
+ **You can also "or" the environments, and negate the "or"'s**
39
+
40
+ * `RailsEnvironment.test_or_production?`
41
+ * `RailsEnvironment.not_test_or_production?`
42
+ * etc.
43
+
44
+ The methods available are based on the actual environments, i.e., `../config/environments/*.rb`
45
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # require 'rake'
2
+ # require 'rake/testtask'
3
+ #
4
+ # Rake::TestTask.new do |t|
5
+ # t.libs << 'lib'
6
+ # t.pattern = 'test/**/*_test.rb'
7
+ # t.verbose = false
8
+ # end
9
+ #
10
+ # task :default => :test
11
+
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new('spec')
14
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ module RailsEnvironment
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ module RailsEnvironment
2
+
3
+ @@environments = nil
4
+
5
+ class << self
6
+
7
+ def rails_env
8
+ Rails.env
9
+ end
10
+
11
+ def load_environments
12
+ Dir[Rails.root.join('config/environments/*.rb')].map { |f| File.basename(f, '.rb') }
13
+ end
14
+
15
+ def environments
16
+ @@environments ||= load_environments
17
+ end
18
+
19
+ def method_missing(method, *args)
20
+ if method =~ /^(.*)\?/ && environments.include?($1)
21
+ rails_env == $1
22
+ elsif method.to_s =~ /^not_(.*)$/
23
+ ! send($1)
24
+ elsif method.to_s =~ /(.*_or_.*)\?/
25
+ methods = $1.split("_or_")
26
+ methods.any? { |m| self.send("#{m}?") }
27
+ else
28
+ super(method, *args)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_environment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Downey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: coveralls
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Eliminate silent errors in envionment detection due to typos.
47
+ email:
48
+ - steve.downtown@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/rails_environment/version.rb
54
+ - lib/rails_environment.rb
55
+ - MIT-LICENSE
56
+ - CHANGELOG.md
57
+ - Rakefile
58
+ - README.md
59
+ homepage: https://github.com/stevedowney/rails_environment
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.25
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Convenience methods for deciding what Rails environment you are in.
83
+ test_files: []