easyconf-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/easyconf-rails.rb +39 -3
- data.tar.gz.sig +2 -5
- metadata +4 -4
- metadata.gz.sig +0 -0
data/lib/easyconf-rails.rb
CHANGED
@@ -12,12 +12,48 @@ class EasyConfRails < Rails::Railtie
|
|
12
12
|
hash.is_a?(Array) ? hash : OpenStruct.new(hash)
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# Merge two hashes recursively, with precedence going to the earliest Hash
|
16
|
+
# with that value defined. For example,
|
17
|
+
# merge_hashes( {a: {b: 1}, c: 2}, {a: {d: 3}, c: {e: 4}} )
|
18
|
+
# will return
|
19
|
+
# {a: {b: 1, d: 3}, c: 2}
|
20
|
+
def merge_hashes(*hashes)
|
21
|
+
merged = {}
|
22
|
+
|
23
|
+
hashes.each do |hash|
|
24
|
+
hash.each do |key, val|
|
25
|
+
if merged.has_key?(key) and merged[key].is_a?(Hash) and val.is_a?(Hash)
|
26
|
+
merged[key] = merge_hashes(merged[key], val)
|
27
|
+
elsif not merged.has_key?(key)
|
28
|
+
merged[key] = val
|
29
|
+
else
|
30
|
+
# merged[key] and val are not both Hashes, and therefore can't be
|
31
|
+
# merged. merged[key] takes precedence over val, and we do nothing.
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
merged
|
37
|
+
end
|
38
|
+
|
39
|
+
# Load the configuration file at Rails.root/config.yml and the defaults file
|
40
|
+
# at Rails.root/config/defaults.yml.
|
16
41
|
def load_config()
|
17
42
|
config_location = Rails.root + 'config.yml'
|
18
|
-
|
43
|
+
if File.exists?(config_location)
|
44
|
+
config_hash = YAML.load_file(config_location)
|
45
|
+
else
|
46
|
+
config_hash = {}
|
47
|
+
end
|
48
|
+
|
49
|
+
defaults_location = Rails.root + 'config' + 'defaults.yml'
|
50
|
+
if File.exists?(defaults_location)
|
51
|
+
defaults_hash = YAML.load_file(defaults_location)
|
52
|
+
else
|
53
|
+
defaults_hash = {}
|
54
|
+
end
|
19
55
|
|
20
|
-
hash_to_openstruct(
|
56
|
+
hash_to_openstruct(merge_hashes(config_hash, defaults_hash))
|
21
57
|
end
|
22
58
|
|
23
59
|
config.before_initialize do
|
data.tar.gz.sig
CHANGED
@@ -1,5 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
�.��
|
4
|
-
-�`11{��{��َ��
|
5
|
-
�S���Ϛ��;�Q!�Efq)�0�8�̖�}�
|
1
|
+
�W}��ǝ�G��h��XS��S�:���[e��|z���2~?�P8��x����k&s�D��˚�F����:�a_��e�c�N�UF�B�2�㏳Ӆ��
|
2
|
+
�!��3���}|\'Ԑ>�R�ȟ���Z��]G������>:�R�J�a ����L�6>�6Iy�Dg����Y�4��h3J0rMê�i3���̌6��·�s���;��M��gK(7+dF��#�A��~����a���g6��kd�] +��
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easyconf-rails
|
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:
|
@@ -50,11 +50,11 @@ cert_chain:
|
|
50
50
|
-----END CERTIFICATE-----
|
51
51
|
|
52
52
|
'
|
53
|
-
date: 2011-12-
|
53
|
+
date: 2011-12-07 00:00:00.000000000 Z
|
54
54
|
dependencies:
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
|
-
requirement: &
|
57
|
+
requirement: &73151190 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
59
|
requirements:
|
60
60
|
- - ! '>='
|
@@ -62,7 +62,7 @@ dependencies:
|
|
62
62
|
version: '0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
|
-
version_requirements: *
|
65
|
+
version_requirements: *73151190
|
66
66
|
description: Configure Rails apps with a simple YAML file.
|
67
67
|
email: the.magical.kat@gmail.com
|
68
68
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|