rails_config 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module RailsConfig
2
2
  module Generators
3
- class InstallGenerator < Rails::Generators::Base
3
+ class InstallGenerator < ::Rails::Generators::Base
4
4
  desc "Generates a custom Rails Config initializer file."
5
5
 
6
6
  def self.source_root
@@ -40,6 +40,19 @@ module RailsConfig
40
40
  reload!
41
41
  end
42
42
 
43
+ def to_hash
44
+ result = {}
45
+ marshal_dump.each do |k, v|
46
+ result[k] = v.instance_of?(RailsConfig::Options) ? v.to_hash : v
47
+ end
48
+ result
49
+ end
50
+
51
+ def to_json(*args)
52
+ require "json" unless defined?(JSON)
53
+ to_hash.to_json(*args)
54
+ end
55
+
43
56
  protected
44
57
 
45
58
  # Recursively converts Hashes to Options (including Hashes inside Arrays)
@@ -48,19 +61,14 @@ module RailsConfig
48
61
 
49
62
  h.each do |k, v|
50
63
  s.new_ostruct_member(k)
64
+
51
65
  if v.is_a?(Hash)
52
- if(v["type"] == "hash")
53
- val = v["contents"]
54
- else
55
- val = __convert(v)
56
- end
57
- s.send( (k+'=').to_sym, val)
66
+ v = v["type"] == "hash" ? v["contents"] : __convert(v)
58
67
  elsif v.is_a?(Array)
59
- converted_array = v.collect { |e| e.instance_of?(Hash) ? __convert(e) : e }
60
- s.send("#{k}=".to_sym, converted_array)
61
- else
62
- s.send("#{k}=".to_sym, v)
68
+ v = v.collect { |e| e.instance_of?(Hash) ? __convert(e) : e }
63
69
  end
70
+
71
+ s.send("#{k}=".to_sym, v)
64
72
  end
65
73
  s
66
74
  end
@@ -9,7 +9,7 @@ if defined?(Rails::Railtie)
9
9
  end
10
10
 
11
11
  # Parse the settings before any of the initializers
12
- ActiveSupport.on_load :before_initialize, :yield => true do
12
+ ActiveSupport.on_load :before_configuration, :yield => true do
13
13
  RailsConfig.load_and_set_settings(
14
14
  Rails.root.join("config", "settings.yml").to_s,
15
15
  Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
@@ -1,3 +1,3 @@
1
1
  module RailsConfig
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -31,6 +31,16 @@ describe RailsConfig do
31
31
  config.should be_empty
32
32
  end
33
33
 
34
+ it "should convert to a hash" do
35
+ config = RailsConfig.load_files(setting_path("development.yml")).to_hash
36
+ config[:section][:servers].should be_a_kind_of(Array)
37
+ end
38
+
39
+ it "should convert to a json" do
40
+ config = RailsConfig.load_files(setting_path("development.yml")).to_json
41
+ JSON.parse(config)["section"]["servers"].should be_a_kind_of(Array)
42
+ end
43
+
34
44
  it "should load an empty config for multiple missing file paths" do
35
45
  files = [setting_path("empty1.yml"), setting_path("empty2.yml")]
36
46
  config = RailsConfig.load_files(files)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_config
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 21
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 0
9
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jacques Crocker
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-16 00:00:00 +11:00
19
+ date: 2010-11-17 00:00:00 -08:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -26,6 +27,7 @@ dependencies:
26
27
  requirements:
27
28
  - - ~>
28
29
  - !ruby/object:Gem::Version
30
+ hash: 7
29
31
  segments:
30
32
  - 3
31
33
  - 0
@@ -40,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ~>
42
44
  - !ruby/object:Gem::Version
45
+ hash: 3
43
46
  segments:
44
47
  - 2
45
48
  - 0
@@ -54,6 +57,7 @@ dependencies:
54
57
  requirements:
55
58
  - - ">="
56
59
  - !ruby/object:Gem::Version
60
+ hash: 3
57
61
  segments:
58
62
  - 0
59
63
  version: "0"
@@ -67,6 +71,7 @@ dependencies:
67
71
  requirements:
68
72
  - - ">="
69
73
  - !ruby/object:Gem::Version
74
+ hash: 3
70
75
  segments:
71
76
  - 0
72
77
  version: "0"
@@ -134,6 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
139
  requirements:
135
140
  - - ">="
136
141
  - !ruby/object:Gem::Version
142
+ hash: 3
137
143
  segments:
138
144
  - 0
139
145
  version: "0"
@@ -142,6 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
148
  requirements:
143
149
  - - ">="
144
150
  - !ruby/object:Gem::Version
151
+ hash: 3
145
152
  segments:
146
153
  - 0
147
154
  version: "0"