magiconf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/{README.markdown → README.md} +10 -8
- data/lib/magiconf/railtie.rb +1 -2
- data/lib/magiconf/version.rb +1 -1
- data/lib/magiconf.rb +36 -10
- data/magiconf.gemspec +1 -1
- metadata +6 -5
data/CHANGELOG.md
ADDED
@@ -16,13 +16,15 @@ Installation
|
|
16
16
|
|
17
17
|
3. Add your configuration variables:
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
```yaml
|
20
|
+
# config/application.yml
|
21
|
+
username: 'seth'
|
22
|
+
password: 'aj29slda'
|
23
|
+
development:
|
24
|
+
pusher_url: 'http://github.com/pusher'
|
25
|
+
production:
|
26
|
+
pusher_url: 'http://google.com/pusher'
|
27
|
+
```
|
26
28
|
|
27
29
|
Usage
|
28
30
|
-----
|
@@ -34,7 +36,7 @@ gem 'magiconf'
|
|
34
36
|
gem 'rails'
|
35
37
|
```
|
36
38
|
|
37
|
-
```
|
39
|
+
```yaml
|
38
40
|
# config/application.yml
|
39
41
|
username: 'seth'
|
40
42
|
development:
|
data/lib/magiconf/railtie.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Magiconf
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer 'magiconf.initialize', before: 'load_environment_config' do |app|
|
4
|
-
|
5
|
-
Magiconf.setup! unless namespace.const_defined?('Config')
|
4
|
+
Magiconf.setup! unless Magiconf.setup?
|
6
5
|
end
|
7
6
|
end
|
8
7
|
end
|
data/lib/magiconf/version.rb
CHANGED
data/lib/magiconf.rb
CHANGED
@@ -1,22 +1,48 @@
|
|
1
1
|
module Magiconf
|
2
2
|
extend self
|
3
3
|
|
4
|
+
# For each configuration key, define a method inside the module
|
4
5
|
def setup!
|
5
|
-
|
6
|
-
namespace = Rails.application.class.parent_name.constantize
|
7
|
-
nodule = namespace.const_set('Config', Module.new)
|
6
|
+
configuration = config
|
8
7
|
|
9
|
-
|
10
|
-
config = YAML::load( ERB.new( File.read('config/application.yml') ).result )
|
11
|
-
config.merge!( config.fetch(Rails.env, {}) )
|
12
|
-
config.symbolize_keys!
|
13
|
-
|
14
|
-
config.keys.each do |key|
|
8
|
+
configuration.keys.each do |key|
|
15
9
|
nodule.define_singleton_method key do
|
16
|
-
return
|
10
|
+
return configuration[key]
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
14
|
+
|
15
|
+
# Have we already loaded the magiconf config?
|
16
|
+
# @return [Boolean] true if we have been loaded, false otherwise
|
17
|
+
def setup?
|
18
|
+
namespace.constants.include?('Config') # Note: We cannot use const_defined?('Config')
|
19
|
+
# here because that will recursively search up
|
20
|
+
# Object and find RbConfig
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
# Get the namespace for the current application
|
25
|
+
# @return [Module] the namespace of the Rails app
|
26
|
+
def namespace
|
27
|
+
@namespace ||= Rails.application.class.parent_name.constantize
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create a new Config module in the current namespace
|
31
|
+
# @return [Module] the created module
|
32
|
+
def nodule
|
33
|
+
@nodule ||= namespace.const_set('Config', Module.new)
|
34
|
+
end
|
35
|
+
|
36
|
+
# The configuration yaml file
|
37
|
+
# @return [Hash] the parsed yaml data
|
38
|
+
def config
|
39
|
+
@config ||= begin
|
40
|
+
config = YAML::load( ERB.new( File.read('config/application.yml') ).result )
|
41
|
+
config.merge!( config.fetch(Rails.env, {}) )
|
42
|
+
config.symbolize_keys!
|
43
|
+
config
|
44
|
+
end
|
45
|
+
end
|
20
46
|
end
|
21
47
|
|
22
48
|
require 'magiconf/railtie' if defined?(Rails)
|
data/magiconf.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = 'sethvargo@gmail.com'
|
11
11
|
gem.description = %q{Magiconf is a tiny gem for managing a Rails application configuration file}
|
12
12
|
gem.summary = %q{Manage a single Rails application config file with Magiconf}
|
13
|
-
gem.homepage = ''
|
13
|
+
gem.homepage = 'https://github.com/sethvargo/magiconf'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magiconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,15 +36,16 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
38
|
- .rvmrc
|
39
|
+
- CHANGELOG.md
|
39
40
|
- Gemfile
|
40
41
|
- LICENSE.txt
|
41
|
-
- README.
|
42
|
+
- README.md
|
42
43
|
- Rakefile
|
43
44
|
- lib/magiconf.rb
|
44
45
|
- lib/magiconf/railtie.rb
|
45
46
|
- lib/magiconf/version.rb
|
46
47
|
- magiconf.gemspec
|
47
|
-
homepage:
|
48
|
+
homepage: https://github.com/sethvargo/magiconf
|
48
49
|
licenses: []
|
49
50
|
post_install_message:
|
50
51
|
rdoc_options: []
|
@@ -58,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
59
|
version: '0'
|
59
60
|
segments:
|
60
61
|
- 0
|
61
|
-
hash:
|
62
|
+
hash: 740543136545878292
|
62
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
64
|
none: false
|
64
65
|
requirements:
|
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
68
|
version: '0'
|
68
69
|
segments:
|
69
70
|
- 0
|
70
|
-
hash:
|
71
|
+
hash: 740543136545878292
|
71
72
|
requirements: []
|
72
73
|
rubyforge_project:
|
73
74
|
rubygems_version: 1.8.24
|