configoro 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ group :development do
10
10
 
11
11
  # DOCS
12
12
  gem 'yard'
13
- gem 'RedCloth'
13
+ gem 'redcarpet'
14
14
 
15
15
  # LIBRARIES
16
16
  gem 'bundler'
data/Gemfile.lock CHANGED
@@ -1,75 +1,80 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- RedCloth (4.2.9)
5
- abstract (1.0.0)
6
- actionmailer (3.0.8)
7
- actionpack (= 3.0.8)
8
- mail (~> 2.2.19)
9
- actionpack (3.0.8)
10
- activemodel (= 3.0.8)
11
- activesupport (= 3.0.8)
12
- builder (~> 2.1.2)
13
- erubis (~> 2.6.6)
14
- i18n (~> 0.5.0)
15
- rack (~> 1.2.1)
16
- rack-mount (~> 0.6.14)
17
- rack-test (~> 0.5.7)
18
- tzinfo (~> 0.3.23)
19
- activemodel (3.0.8)
20
- activesupport (= 3.0.8)
21
- builder (~> 2.1.2)
22
- i18n (~> 0.5.0)
23
- activerecord (3.0.8)
24
- activemodel (= 3.0.8)
25
- activesupport (= 3.0.8)
26
- arel (~> 2.0.10)
27
- tzinfo (~> 0.3.23)
28
- activeresource (3.0.8)
29
- activemodel (= 3.0.8)
30
- activesupport (= 3.0.8)
31
- activesupport (3.0.8)
32
- arel (2.0.10)
33
- builder (2.1.2)
4
+ actionmailer (3.2.13)
5
+ actionpack (= 3.2.13)
6
+ mail (~> 2.5.3)
7
+ actionpack (3.2.13)
8
+ activemodel (= 3.2.13)
9
+ activesupport (= 3.2.13)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.5)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.13)
18
+ activesupport (= 3.2.13)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.13)
21
+ activemodel (= 3.2.13)
22
+ activesupport (= 3.2.13)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.13)
26
+ activemodel (= 3.2.13)
27
+ activesupport (= 3.2.13)
28
+ activesupport (3.2.13)
29
+ i18n (= 0.6.1)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.4)
34
33
  diff-lcs (1.2.4)
35
- erubis (2.6.6)
36
- abstract (>= 1.0.0)
34
+ erubis (2.7.0)
37
35
  git (1.2.5)
38
- i18n (0.5.0)
36
+ hike (1.2.2)
37
+ i18n (0.6.1)
39
38
  jeweler (1.8.4)
40
39
  bundler (~> 1.0)
41
40
  git (>= 1.2.5)
42
41
  rake
43
42
  rdoc
43
+ journey (1.0.4)
44
44
  json (1.7.7)
45
- mail (2.2.19)
46
- activesupport (>= 2.3.6)
45
+ mail (2.5.3)
47
46
  i18n (>= 0.4.0)
48
47
  mime-types (~> 1.16)
49
48
  treetop (~> 1.4.8)
50
49
  mime-types (1.23)
50
+ multi_json (1.7.2)
51
51
  polyglot (0.3.3)
52
- rack (1.2.8)
53
- rack-mount (0.6.14)
54
- rack (>= 1.0.0)
55
- rack-test (0.5.7)
52
+ rack (1.4.5)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.3)
56
+ rack
57
+ rack-test (0.6.2)
56
58
  rack (>= 1.0)
57
- rails (3.0.8)
58
- actionmailer (= 3.0.8)
59
- actionpack (= 3.0.8)
60
- activerecord (= 3.0.8)
61
- activeresource (= 3.0.8)
62
- activesupport (= 3.0.8)
59
+ rails (3.2.13)
60
+ actionmailer (= 3.2.13)
61
+ actionpack (= 3.2.13)
62
+ activerecord (= 3.2.13)
63
+ activeresource (= 3.2.13)
64
+ activesupport (= 3.2.13)
63
65
  bundler (~> 1.0)
64
- railties (= 3.0.8)
65
- railties (3.0.8)
66
- actionpack (= 3.0.8)
67
- activesupport (= 3.0.8)
66
+ railties (= 3.2.13)
67
+ railties (3.2.13)
68
+ actionpack (= 3.2.13)
69
+ activesupport (= 3.2.13)
70
+ rack-ssl (~> 1.3.2)
68
71
  rake (>= 0.8.7)
69
- thor (~> 0.14.4)
72
+ rdoc (~> 3.4)
73
+ thor (>= 0.14.6, < 2.0)
70
74
  rake (10.0.4)
71
- rdoc (4.0.1)
75
+ rdoc (3.12.2)
72
76
  json (~> 1.4)
77
+ redcarpet (2.2.2)
73
78
  rspec (2.13.0)
74
79
  rspec-core (~> 2.13.0)
75
80
  rspec-expectations (~> 2.13.0)
@@ -78,7 +83,13 @@ GEM
78
83
  rspec-expectations (2.13.0)
79
84
  diff-lcs (>= 1.1.3, < 2.0)
80
85
  rspec-mocks (2.13.1)
81
- thor (0.14.6)
86
+ sprockets (2.2.2)
87
+ hike (~> 1.2)
88
+ multi_json (~> 1.0)
89
+ rack (~> 1.0)
90
+ tilt (~> 1.1, != 1.3.0)
91
+ thor (0.18.1)
92
+ tilt (1.3.7)
82
93
  treetop (1.4.12)
83
94
  polyglot
84
95
  polyglot (>= 0.3.1)
@@ -89,10 +100,10 @@ PLATFORMS
89
100
  ruby
90
101
 
91
102
  DEPENDENCIES
92
- RedCloth
93
103
  activesupport
94
104
  bundler
95
105
  jeweler
96
106
  rails (>= 3.0)
107
+ redcarpet
97
108
  rspec
98
109
  yard
@@ -1,15 +1,18 @@
1
- h1. Configoro -- Environment-specific configuration data for Rails apps
1
+ Configoro
2
+ =========
2
3
 
3
- | *Author* | Tim Morgan |
4
- | *Version* | 1.1 (May 9, 2011) |
5
- | *License* | Released under the MIT license. |
4
+ **Environment-specific configuration data for Rails apps**
6
5
 
7
- h2. About
6
+ | **Author** | Tim Morgan |
7
+ | **License** | Released under the MIT license. |
8
+
9
+ About
10
+ -----
8
11
 
9
12
  Pretty much every Rails app out there needs to store environment-specific
10
13
  configuration data: API URLs, Memcache settings, AWS keys, etc. The "quick fix"
11
- approach is usually to dump this information in, e.g., @development.rb@ as
12
- constants, like @MAILCHIMP_API_URL@. This creates cluttered and unorganized
14
+ approach is usually to dump this information in, e.g., `development.rb` as
15
+ constants, like `MAILCHIMP_API_URL`. This creates cluttered and unorganized
13
16
  environment files.
14
17
 
15
18
  Configoro creates a configuration object that can be accessed as both a hash and
@@ -18,83 +21,100 @@ data.
18
21
 
19
22
  The data is read from YAML files stored alongside the environment files.
20
23
 
21
- h2. Installation
24
+ Installation
25
+ ------------
22
26
 
23
27
  To use this gem, simply add
24
28
 
25
- <pre><code>
29
+ ```` ruby
26
30
  gem 'configoro'
27
- </code></pre>
31
+ ````
28
32
 
29
33
  to your Gemfile, then run
30
34
 
31
- <pre><code>
35
+ ```` ruby
32
36
  rails generate configoro
33
- </code></pre>
37
+ ````
34
38
 
35
39
  to install some default configuration files. Edit these new files with your
36
40
  configuration data.
37
41
 
38
- h2. Usage
42
+ Usage
43
+ -----
39
44
 
40
- Assume your application namespace is @MyApp@ (which is what it
41
- would be if you had created your Rails project using @rails new my_app@). You
42
- can find your namespace in your @config/application.rb@ file.
45
+ Assume your application namespace is `MyApp` (which is what it
46
+ would be if you had created your Rails project using `rails new my_app`). You
47
+ can find your namespace in your `config/application.rb` file.
43
48
 
44
49
  In this case, you would access your configuration using the
45
- @MyApp::Configuration@ object. You can access it as an indifferent hash
50
+ `MyApp::Configuration` object. You can access it as an indifferent hash
46
51
 
47
- <pre><code>
52
+ ```` ruby
48
53
  MyApp::Configuration[:mailchimp_api_url]
49
54
  MyApp::Configuration['mailchimp_api_url']
50
- </code></pre>
55
+ ````
51
56
 
52
57
  or as a struct.
53
58
 
54
- <pre><code>
59
+ ```` ruby
55
60
  MyApp::Configuration.mailchimp_api_url
56
- </code></pre>
61
+ ````
57
62
 
58
63
  If you include any hashes in your configuration YAML files, they will also be
59
64
  accessible as indifferent hashes or structs:
60
65
 
61
- <pre><code>
66
+ ```` ruby
62
67
  MyApp::Configuration.memcache.timeout
63
68
  MyApp::Configuration[:memcache]['timeout']
64
69
  MyApp::Configuration['memcache'].timeout
65
- </code></pre>
70
+ ````
66
71
 
67
- h2. Configuration Files
72
+ Configuration Files
73
+ -------------------
68
74
 
69
- Configuration is stored within the @config/environments@ directory of your Rails
70
- app. Files ending in ".yml" are loaded from the @common/@ subdirectory and a
75
+ Configuration is stored within the `config/environments` directory of your Rails
76
+ app. Files ending in ".yml" are loaded from the `common/` subdirectory and a
71
77
  subdirectory named after the current environment.
72
78
 
73
79
  Configuration files are preprocessed as ERB, in the same way that Rails
74
- preprocesses @config/database.yml@. This allows dynamic configuration,
75
- e.g. @host: <%= ENV["DB_HOST"] || "localhost" %>@.
80
+ preprocesses `config/database.yml`. This allows dynamic configuration,
81
+ e.g. `host: <%= ENV["DB_HOST"] || "localhost" %>`.
76
82
 
77
83
  Each file goes into its own hash in the configuration. For example, if you
78
- placed a file called @memcache.yml@ within @config/environments/development@,
84
+ placed a file called `memcache.yml` within `config/environments/development`,
79
85
  you would be able to access your Memcache timeout using
80
- @MyApp::Configuration.memcache.timeout@.
86
+ `MyApp::Configuration.memcache.timeout`.
81
87
 
82
88
  h3. Custom Configuration Locations
83
89
 
84
90
  If you need to do your own configuration loading, you can do so using the
85
91
  {Configoro::Hash#<<} method. For example, you could place the following in a
86
- Ruby file under @config/initializers@:
92
+ Ruby file under `config/initializers`:
87
93
 
88
- <pre><code>
94
+ ```` ruby
89
95
  MyApp::Configuration << "path/to/additional/yaml_file.yml"
90
96
  MyApp::Configuration << { 'additional' => 'configuration' }
91
97
 
92
98
  MyApp::Configuration.additional #=> 'configuration'
93
- </code></pre>
99
+ ````
94
100
 
95
101
  Note that if you pass a path to a YAML file, a key will be created to store the
96
102
  contents of the file, named after the file name. If the key already exists, the
97
103
  new values will be deep-merged into the existing values.
98
104
 
99
- In the example above, the data in the @yaml_file.yml@ file can be accessed using
100
- @MyApp::Configuration.yaml_file@.
105
+ In the example above, the data in the `yaml_file.yml` file can be accessed using
106
+ `MyApp::Configuration.yaml_file`.
107
+
108
+ Other Notes
109
+ -----------
110
+
111
+ If you want to use Configoro outside of Rails or your gemset, you can require
112
+ the `configoro/simple` file. This file defines a subset of the `Configoro`
113
+ object you can use to access your configuration. You will need to set
114
+ {Configoro.paths} manually, and the `Configoro::Hash` object will have the same
115
+ functionality as a normal Hash, without all the bells and whistles described
116
+ above.
117
+
118
+ If you then "upgrade" your environment to a full-fledged Rails or gem-ified
119
+ environment (perhaps by running your app's `environment.rb` file, be sure to
120
+ run {Configoro.reset_paths} before requiring the `configoro` gem file.
data/Rakefile CHANGED
@@ -19,13 +19,13 @@ require 'rake'
19
19
  require 'jeweler'
20
20
  Jeweler::Tasks.new do |gem|
21
21
  # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
22
- gem.name = "configoro"
23
- gem.homepage = "http://github.com/RISCfuture/configoro"
24
- gem.license = "MIT"
25
- gem.summary = %Q{Configuration object and YAML-based storage for Rails apps}
22
+ gem.name = 'configoro'
23
+ gem.homepage = 'http://github.com/RISCfuture/configoro'
24
+ gem.license = 'MIT'
25
+ gem.summary = %Q{Configuration object and YAML-based storage for Rails apps}
26
26
  gem.description = %Q{Creates a YourApp::Configuration object whose methods are generated from environment-specific YAML files.}
27
- gem.email = "git@timothymorgan.info"
28
- gem.authors = [ "Tim Morgan" ]
27
+ gem.email = 'git@timothymorgan.info'
28
+ gem.authors = ['Tim Morgan']
29
29
  # dependencies defined in Gemfile
30
30
  end
31
31
  Jeweler::RubygemsDotOrgTasks.new
@@ -44,14 +44,15 @@ task :default => :spec
44
44
 
45
45
  require 'yard'
46
46
  YARD::Rake::YardocTask.new do |doc|
47
- doc.options << "-m" << "textile"
48
- doc.options << "--protected"
49
- doc.options << "--no-private"
50
- doc.options << "-r" << "README.textile"
51
- doc.options << "-o" << "doc"
52
- doc.options << "--title" << "Configoro Documentation"
53
-
54
- doc.files = [ 'lib/**/*', 'README.textile' ]
47
+ doc.options << '-m' << 'markdown'
48
+ doc.options << '-M' << 'redcarpet'
49
+ doc.options << '--protected'
50
+ doc.options << '--no-private'
51
+ doc.options << '-r' << 'README.md'
52
+ doc.options << '-o' << 'doc'
53
+ doc.options << '--title' << 'Configoro Documentation'
54
+
55
+ doc.files = %w(lib/**/* README.md)
55
56
  end
56
57
 
57
58
  desc "Generate API documentation"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.2.4
data/configoro.gemspec CHANGED
@@ -5,16 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "configoro"
8
- s.version = "1.2.3"
8
+ s.version = "1.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Morgan"]
12
- s.date = "2013-04-25"
12
+ s.date = "2013-04-26"
13
13
  s.description = "Creates a YourApp::Configuration object whose methods are generated from environment-specific YAML files."
14
14
  s.email = "git@timothymorgan.info"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.textile"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  "Gemfile",
25
25
  "Gemfile.lock",
26
26
  "LICENSE.txt",
27
- "README.textile",
27
+ "README.md",
28
28
  "Rakefile",
29
29
  "VERSION",
30
30
  "configoro.gemspec",
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/configoro/base.rb",
34
34
  "lib/configoro/hash.rb",
35
35
  "lib/configoro/railtie.rb",
36
+ "lib/configoro/simple.rb",
36
37
  "spec/configoro/hash_spec.rb",
37
38
  "spec/configoro_spec.rb",
38
39
  "spec/data/config/environments/common/basic.yml",
@@ -59,7 +60,7 @@ Gem::Specification.new do |s|
59
60
  s.add_development_dependency(%q<rails>, [">= 3.0"])
60
61
  s.add_development_dependency(%q<rspec>, [">= 0"])
61
62
  s.add_development_dependency(%q<yard>, [">= 0"])
62
- s.add_development_dependency(%q<RedCloth>, [">= 0"])
63
+ s.add_development_dependency(%q<redcarpet>, [">= 0"])
63
64
  s.add_development_dependency(%q<bundler>, [">= 0"])
64
65
  s.add_development_dependency(%q<jeweler>, [">= 0"])
65
66
  else
@@ -67,7 +68,7 @@ Gem::Specification.new do |s|
67
68
  s.add_dependency(%q<rails>, [">= 3.0"])
68
69
  s.add_dependency(%q<rspec>, [">= 0"])
69
70
  s.add_dependency(%q<yard>, [">= 0"])
70
- s.add_dependency(%q<RedCloth>, [">= 0"])
71
+ s.add_dependency(%q<redcarpet>, [">= 0"])
71
72
  s.add_dependency(%q<bundler>, [">= 0"])
72
73
  s.add_dependency(%q<jeweler>, [">= 0"])
73
74
  end
@@ -76,7 +77,7 @@ Gem::Specification.new do |s|
76
77
  s.add_dependency(%q<rails>, [">= 3.0"])
77
78
  s.add_dependency(%q<rspec>, [">= 0"])
78
79
  s.add_dependency(%q<yard>, [">= 0"])
79
- s.add_dependency(%q<RedCloth>, [">= 0"])
80
+ s.add_dependency(%q<redcarpet>, [">= 0"])
80
81
  s.add_dependency(%q<bundler>, [">= 0"])
81
82
  s.add_dependency(%q<jeweler>, [">= 0"])
82
83
  end
data/lib/configoro.rb CHANGED
@@ -1,17 +1,29 @@
1
- in_rails = defined?(Rails)
1
+ unless defined?(Rails)
2
+ raise "Configoro must be run in the context of a Rails environment, or require 'configoro/simple' outside of Rails"
3
+ end
2
4
 
3
5
  require 'erb'
4
6
  require 'yaml'
5
7
 
6
- if in_rails
7
- require 'bundler'
8
- Bundler.setup
9
- end
8
+ require 'bundler'
9
+ Bundler.setup
10
+
11
+ require 'active_support/hash_with_indifferent_access'
12
+ require 'active_support/core_ext/hash/deep_merge'
10
13
 
11
- require 'configoro/base'
12
- require 'configoro/hash'
14
+ load 'configoro/base.rb'
13
15
 
14
- if in_rails
15
- require 'configoro/railtie'
16
- require "#{File.dirname __FILE__}/../generators/configoro_generator"
16
+ module Configoro
17
+
18
+ # undo anything done by configoro/simple...
19
+ begin
20
+ remove_const :Hash
21
+ remove_const :HashWithIndifferentAccess
22
+ rescue NameError
23
+ # ignored
24
+ end
17
25
  end
26
+ load 'configoro/hash.rb'
27
+
28
+ load 'configoro/railtie.rb'
29
+ load "#{File.dirname __FILE__}/../generators/configoro_generator.rb"
@@ -3,15 +3,8 @@
3
3
 
4
4
  module Configoro
5
5
 
6
- # @return [Module] The Rails application namespace; e.g., @MyApp@ for a Rails
7
- # app named @MyApp::Application@.
8
-
9
- def self.namespace
10
- Object.const_get Rails.application.class.to_s.split('::').first
11
- end
12
-
13
6
  # Creates the configuration dictionary and stores it under
14
- # @MyApp::Configuration@ (assuming an application named @MyApp@).
7
+ # `MyApp::Configuration` (assuming an application named `MyApp`).
15
8
 
16
9
  def self.initialize
17
10
  namespace.const_set :Configuration, load_environment(Rails.env)
@@ -42,6 +35,12 @@ module Configoro
42
35
  end
43
36
  end
44
37
 
38
+ # Resets any custom configuration paths set using {.paths}.
39
+
40
+ def self.reset_paths
41
+ remove_instance_variable :@paths
42
+ end
43
+
45
44
  # Loads the configuration for an environment and returns it as a {Hash}. Use
46
45
  # this method to access Configoro options outside the context of your Rails
47
46
  # app. You will need to configure paths first (see example).
@@ -54,13 +53,17 @@ module Configoro
54
53
  # Configoro.load_environment(rails_env) #=> { ... }
55
54
 
56
55
  def self.load_environment(env)
57
- config = Hash.new
56
+ config = Configoro::Hash.new
58
57
  load_data config, env
59
58
  config
60
59
  end
61
60
 
62
61
  private
63
62
 
63
+ def self.namespace
64
+ Object.const_get Rails.application.class.to_s.split('::').first
65
+ end
66
+
64
67
  def self.load_data(config, env)
65
68
  paths.each do |path|
66
69
  Dir.glob("#{path}/common/*.yml").sort.each { |file| config << file }
@@ -1,154 +1,152 @@
1
- require 'active_support/hash_with_indifferent_access'
2
- require 'active_support/core_ext/hash/deep_merge'
3
-
4
- class Configoro::Hash < HashWithIndifferentAccess
5
-
6
- # @private
7
- def initialize(hsh={})
8
- if hsh.kind_of?(::Hash) then
9
- super()
10
- update hsh
11
- else
12
- super
1
+ module Configoro
2
+ class Hash < HashWithIndifferentAccess
3
+
4
+ # @private
5
+ def initialize(hsh={})
6
+ if hsh.kind_of?(::Hash) then
7
+ super()
8
+ update hsh
9
+ else
10
+ super
11
+ end
13
12
  end
14
- end
15
13
 
16
- # Deep-merges additional hash entries into this hash.
17
- #
18
- # @return [Configoro::Hash] This object.
19
- # @overload <<(hash)
20
- # Adds the entries from another hash.
21
- # @param [::Hash] hash The additional keys to add.
22
- # @overload <<(path)
23
- # Adds the entries from a YAML file. The entries will be added under a
24
- # sub-hash named after the YAML file's name.
25
- # @param [String] path The path to a YAML file ending in ".yml".
26
- # @raise [ArgumentError] If the filename does not end in ".yml".
27
-
28
- def <<(hsh_or_path)
29
- case hsh_or_path
30
- when String
31
- raise ArgumentError, "Only files ending in .yml can be added" unless File.extname(hsh_or_path) == '.yml'
32
- return self unless File.exist?(hsh_or_path)
33
- data = load_preprocessed_yaml(hsh_or_path)
34
- deep_merge! File.basename(hsh_or_path, ".yml") => data
35
- when ::Hash
36
- deep_merge! hsh_or_path
14
+ # Deep-merges additional hash entries into this hash.
15
+ #
16
+ # @return [Configoro::Hash] This object.
17
+ # @overload <<(hash)
18
+ # Adds the entries from another hash.
19
+ # @param [::Hash] hash The additional keys to add.
20
+ # @overload <<(path)
21
+ # Adds the entries from a YAML file. The entries will be added under a
22
+ # sub-hash named after the YAML file's name.
23
+ # @param [String] path The path to a YAML file ending in ".yml".
24
+ # @raise [ArgumentError] If the filename does not end in ".yml".
25
+
26
+ def <<(hsh_or_path)
27
+ case hsh_or_path
28
+ when String
29
+ raise ArgumentError, "Only files ending in .yml can be added" unless File.extname(hsh_or_path) == '.yml'
30
+ return self unless File.exist?(hsh_or_path)
31
+ data = load_preprocessed_yaml(hsh_or_path)
32
+ deep_merge! File.basename(hsh_or_path, ".yml") => data
33
+ when ::Hash
34
+ deep_merge! hsh_or_path
35
+ end
37
36
  end
38
- end
39
37
 
40
- alias_method :push, :<<
38
+ alias_method :push, :<<
41
39
 
42
- # @private
43
- def dup
44
- Hash.new(self)
45
- end
40
+ # @private
41
+ def dup
42
+ Hash.new(self)
43
+ end
46
44
 
47
- # Recursively merges this hash with another hash. All nested hashes are forced
48
- # to be @Configoro::Hash@ instances.
49
- #
50
- # @param [::Hash] other_hash The hash to merge into this one.
51
- # @return [Configoro::Hash] This object.
52
-
53
- def deep_merge!(other_hash)
54
- other_hash.each_pair do |k, v|
55
- tv = self[k]
56
- self[k] = if v.kind_of?(::Hash) then
57
- if tv.kind_of?(::Hash) then
58
- Configoro::Hash.new(tv).deep_merge!(v)
45
+ # Recursively merges this hash with another hash. All nested hashes are forced
46
+ # to be `Configoro::Hash` instances.
47
+ #
48
+ # @param [::Hash] other_hash The hash to merge into this one.
49
+ # @return [Configoro::Hash] This object.
50
+
51
+ def deep_merge!(other_hash)
52
+ other_hash.each_pair do |k, v|
53
+ tv = self[k]
54
+ self[k] = if v.kind_of?(::Hash) then
55
+ if tv.kind_of?(::Hash) then
56
+ Configoro::Hash.new(tv).deep_merge!(v)
57
+ else
58
+ Configoro::Hash.new(v)
59
+ end
59
60
  else
60
- Configoro::Hash.new(v)
61
+ v
61
62
  end
62
- else
63
- v
64
- end
63
+ end
64
+ self
65
65
  end
66
- self
67
- end
68
66
 
69
- # @private
70
- #
71
- # To optimize access, we create a getter method every time we encounter a
72
- # key that exists in the hash. If the key is later deleted, the method will
73
- # be removed.
67
+ # @private
68
+ #
69
+ # To optimize access, we create a getter method every time we encounter a
70
+ # key that exists in the hash. If the key is later deleted, the method will
71
+ # be removed.
74
72
 
75
- def method_missing(meth, *args)
76
- if include?(meth.to_s) then
77
- if args.empty? then
78
- create_getter meth
79
- else
80
- raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
81
- end
82
- elsif meth.to_s =~ /^(.+)\?$/ and include?(root_meth = $1) then
83
- if args.empty? then
84
- !! create_getter(root_meth) #TODO duplication of logic
73
+ def method_missing(meth, *args)
74
+ if include?(meth.to_s) then
75
+ if args.empty? then
76
+ create_getter meth
77
+ else
78
+ raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
79
+ end
80
+ elsif meth.to_s =~ /^(.+)\?$/ and include?(root_meth = $1) then
81
+ if args.empty? then
82
+ !!create_getter(root_meth) #TODO duplication of logic
83
+ else
84
+ raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
85
+ end
85
86
  else
86
- raise ArgumentError, "wrong number of arguments (#{args.size} for 0)"
87
+ super
87
88
  end
88
- else
89
- super
90
89
  end
91
- end
92
90
 
93
- # @private
94
- def inspect
95
- "#{to_hash.inspect}:#{self.class.to_s}"
96
- end
91
+ # @private
92
+ def inspect
93
+ "#{to_hash.inspect}:#{self.class.to_s}"
94
+ end
97
95
 
98
- protected
96
+ protected
99
97
 
100
- def self.new_from_hash_copying_default(hash)
101
- Configoro::Hash.new(hash).tap do |new_hash|
102
- new_hash.default = hash.default
98
+ def self.new_from_hash_copying_default(hash)
99
+ Configoro::Hash.new(hash).tap do |new_hash|
100
+ new_hash.default = hash.default
101
+ end
103
102
  end
104
- end
105
103
 
106
- def convert_value(value)
107
- if value.is_a?(::Hash)
108
- self.class.new_from_hash_copying_default(value)
109
- elsif value.is_a?(Array)
110
- value.dup.replace(value.map { |e| convert_value(e) })
111
- else
112
- value
104
+ def convert_value(value)
105
+ if value.is_a?(::Hash)
106
+ self.class.new_from_hash_copying_default(value)
107
+ elsif value.is_a?(Array)
108
+ value.dup.replace(value.map { |e| convert_value(e) })
109
+ else
110
+ value
111
+ end
113
112
  end
114
- end
115
113
 
116
- private
114
+ private
117
115
 
118
- def create_getter(meth)
119
- singleton_class.send(:define_method, meth) do
120
- if include?(meth.to_s) then
121
- self[meth.to_s]
122
- else
123
- remove_getter meth
116
+ def create_getter(meth)
117
+ singleton_class.send(:define_method, meth) do
118
+ if include?(meth.to_s) then
119
+ self[meth.to_s]
120
+ else
121
+ remove_getter meth
122
+ end
124
123
  end
125
- end
126
-
127
- singleton_class.send(:define_method, :"#{meth}?") do
128
- if include?(meth.to_s) then
129
- !! self[meth.to_s]
130
- else
131
- remove_getter meth
124
+
125
+ singleton_class.send(:define_method, :"#{meth}?") do
126
+ if include?(meth.to_s) then
127
+ !!self[meth.to_s]
128
+ else
129
+ remove_getter meth
130
+ end
132
131
  end
133
- end
134
-
135
- self[meth.to_s]
136
- end
137
132
 
138
- def remove_getter(meth)
139
- if methods.include?(meth.to_sym) then
140
- instance_eval "undef #{meth.to_sym.inspect}"
141
- end
142
-
143
- if methods.include?(:"#{meth}?") then
144
- instance_eval "undef #{:"#{meth}?".inspect}"
133
+ self[meth.to_s]
145
134
  end
146
135
 
147
- raise NameError, "undefined local variable or method `#{meth}' for #{self.inspect}"
148
- end
136
+ def remove_getter(meth)
137
+ if methods.include?(meth.to_sym) then
138
+ instance_eval "undef #{meth.to_sym.inspect}"
139
+ end
149
140
 
150
- def load_preprocessed_yaml(path)
151
- YAML.load(ERB.new(IO.read(path)).result)
152
- end
141
+ if methods.include?(:"#{meth}?") then
142
+ instance_eval "undef #{:"#{meth}?".inspect}"
143
+ end
153
144
 
145
+ raise NameError, "undefined local variable or method `#{meth}' for #{self.inspect}"
146
+ end
147
+
148
+ def load_preprocessed_yaml(path)
149
+ YAML.load(ERB.new(IO.read(path)).result)
150
+ end
151
+ end
154
152
  end
@@ -1,4 +1,4 @@
1
- # Loads the @Configuration@ object during the Rails initialization process.
1
+ # Loads the `Configuration` object during the Rails initialization process.
2
2
 
3
3
  class Configoro::Railtie < Rails::Railtie
4
4
  initializer "Configoro", before: :load_config_initializers do
@@ -0,0 +1,23 @@
1
+ # A stripped-down version of Configoro that works without any gems.
2
+
3
+ require 'erb'
4
+ require 'yaml'
5
+
6
+ load File.join(File.dirname(__FILE__), 'base.rb')
7
+
8
+ # @private
9
+ class Configoro::HashWithIndifferentAccess < ::Hash
10
+ def deep_merge(other_hash)
11
+ dup.deep_merge!(other_hash)
12
+ end
13
+
14
+ def deep_merge!(other_hash)
15
+ other_hash.each_pair do |k, v|
16
+ tv = self[k]
17
+ self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
18
+ end
19
+ self
20
+ end
21
+ end
22
+
23
+ load File.join(File.dirname(__FILE__), 'hash.rb')
data/spec/spec_helper.rb CHANGED
@@ -7,8 +7,7 @@ Bundler.require :development
7
7
  require 'yaml'
8
8
  Bundler.setup
9
9
 
10
- require 'configoro/base'
11
- require 'configoro/hash'
10
+ require 'configoro'
12
11
 
13
12
  # Requires supporting files with custom matchers and macros, etc,
14
13
  # in ./support/ and its subdirectories.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configoro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -76,7 +76,7 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: RedCloth
79
+ name: redcarpet
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -130,7 +130,7 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files:
132
132
  - LICENSE.txt
133
- - README.textile
133
+ - README.md
134
134
  files:
135
135
  - .document
136
136
  - .rspec
@@ -139,7 +139,7 @@ files:
139
139
  - Gemfile
140
140
  - Gemfile.lock
141
141
  - LICENSE.txt
142
- - README.textile
142
+ - README.md
143
143
  - Rakefile
144
144
  - VERSION
145
145
  - configoro.gemspec
@@ -148,6 +148,7 @@ files:
148
148
  - lib/configoro/base.rb
149
149
  - lib/configoro/hash.rb
150
150
  - lib/configoro/railtie.rb
151
+ - lib/configoro/simple.rb
151
152
  - spec/configoro/hash_spec.rb
152
153
  - spec/configoro_spec.rb
153
154
  - spec/data/config/environments/common/basic.yml
@@ -174,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
175
  version: '0'
175
176
  segments:
176
177
  - 0
177
- hash: -2903058647280752545
178
+ hash: -1144284965917323099
178
179
  required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  none: false
180
181
  requirements: