env_rails 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: 7b6aa1e293c8661aecec09f06f5a84acbbaa1fa3
4
+ data.tar.gz: b4709cd91ec8c465f2943dc9fca3d0097793c4e7
5
+ SHA512:
6
+ metadata.gz: bdcfbc6ddd74a93af15c60d0e4dc4035d45679b66f95892304ef57d0482ebda6dcffaa5308858d7c4f50d26aefb2e57f3da93ef3d000a370017d11c279d1ea51
7
+ data.tar.gz: e5c61c31ddeb39d10f7979f0807a0284578c940900f85163b579c3431aaacfb9c05899866897614a1a84e1c5bb62e1d4088ebfce09f9d021cca7e221c13f04a5
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in env_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Juan Wajnerman
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,35 @@
1
+ # EnvRails
2
+
3
+ Set Rails configuration parameters using environment variables
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Rails application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'env_rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ This gem is a Railtie plugin. It doesn't require any special configuration.
20
+
21
+ When the Rails application starts it will pick up any environment variable matching a name like __RAILS_CONFIG.foo.bar__ and apply the value to the corresponding Rails configuration.
22
+
23
+ For example:
24
+
25
+ ```
26
+ RAILS_CONFIG.action_mailer.smtp_settings.address=smtpserver.yourdomain.com
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/manastech/env_rails/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/env_rails.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'env_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "env_rails"
8
+ spec.version = EnvRails::VERSION
9
+ spec.authors = ["Juan Wajnerman"]
10
+ spec.email = ["jwajnerman@manas.com.ar"]
11
+ spec.summary = %q{Set Rails configuration parameters using environment variables}
12
+ spec.homepage = "https://github.com/manastech/env_rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
data/lib/env_rails.rb ADDED
@@ -0,0 +1,51 @@
1
+ require "env_rails/version"
2
+
3
+ module EnvRails
4
+ class Railtie < Rails::Railtie
5
+ config.after_initialize do
6
+ ENV.each do |key, value|
7
+ if key =~ /\ARAILS_CONFIG((\.[a-z_]+)+)\Z/
8
+ config_path = $1.split('.')[1 .. -1]
9
+ parameter_name = config_path.pop
10
+
11
+ # Find or create the parameter container
12
+ config_container = config
13
+ while config_path.any?
14
+ selector = config_path.shift
15
+ unless sub_container = EnvRails.get_value(config_container, selector)
16
+ # If it doesn't exist, a new hash is created
17
+ sub_container = {}
18
+ EnvRails.set_value(config_container, selector, sub_container)
19
+ end
20
+ config_container = sub_container
21
+ end
22
+
23
+ # Assume integer values it they look like one
24
+ if value =~ /\A[0-9]+\Z/
25
+ value = value.to_i
26
+ end
27
+
28
+ EnvRails.set_value(config_container, parameter_name, value)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def self.get_value(object, key)
37
+ if object.respond_to?(:[])
38
+ object[key.to_sym]
39
+ else
40
+ object.send(key)
41
+ end
42
+ end
43
+
44
+ def self.set_value(object, key, value)
45
+ if object.respond_to?(:[]=)
46
+ object[key.to_sym] = value
47
+ else
48
+ object.send("#{key}=", value)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module EnvRails
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Juan Wajnerman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-29 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
+ description:
42
+ email:
43
+ - jwajnerman@manas.com.ar
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - env_rails.gemspec
54
+ - lib/env_rails.rb
55
+ - lib/env_rails/version.rb
56
+ homepage: https://github.com/manastech/env_rails
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.14
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Set Rails configuration parameters using environment variables
80
+ test_files: []