app_config 1.1.1 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +16 -0
- data/Gemfile.lock +3 -5
- data/README.md +25 -49
- data/app_config.gemspec +2 -2
- data/lib/app_config/error.rb +1 -1
- data/lib/app_config/storage/base.rb +13 -3
- data/lib/app_config/storage/mongo.rb +9 -21
- data/lib/app_config/storage/yaml.rb +2 -14
- data/lib/app_config/version.rb +3 -0
- data/lib/app_config.rb +13 -48
- data/spec/app_config/storage/mongo_spec.rb +5 -7
- data/spec/app_config/storage/yaml_spec.rb +3 -3
- data/spec/app_config_spec.rb +10 -23
- data/spec/spec_helper.rb +2 -2
- metadata +34 -42
- data/lib/core_ext/hashish.rb +0 -140
- data/spec/core_ext/hashish_spec.rb +0 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 57a758d17f3cf8b5932064d8daaba948f2b0e51a
|
4
|
+
data.tar.gz: a9851dc01c313b651654a52a1b8ad8e397f82380
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7e65918fd775a55c5611d24084fe36ccc212b609fe4a864379e357b4a2f5ead09061a6c992ea40d1f80ea240e5ba75fd7a65de915665215f6009dcb2265d4b8
|
7
|
+
data.tar.gz: 1f7d96ba6828400f2784cbc523b4078697d8cce396b2bd8abe221f130070d69f9a5ccad961402500aa2b6012337f3be4bfe9338323dd5e00f63c1708aace227f
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
app_config (
|
4
|
+
app_config (2.0.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -9,12 +9,11 @@ GEM
|
|
9
9
|
bson (1.3.1)
|
10
10
|
bson_ext (1.3.1)
|
11
11
|
diff-lcs (1.1.3)
|
12
|
-
maruku (0.6.0)
|
13
|
-
syntax (>= 1.0.0)
|
14
12
|
mongo (1.3.1)
|
15
13
|
bson (>= 1.3.1)
|
16
14
|
multi_json (1.3.6)
|
17
15
|
rake (0.9.2.2)
|
16
|
+
redcarpet (2.3.0)
|
18
17
|
rspec (2.10.0)
|
19
18
|
rspec-core (~> 2.10.0)
|
20
19
|
rspec-expectations (~> 2.10.0)
|
@@ -27,7 +26,6 @@ GEM
|
|
27
26
|
multi_json (~> 1.0)
|
28
27
|
simplecov-html (~> 0.5.3)
|
29
28
|
simplecov-html (0.5.3)
|
30
|
-
syntax (1.0.0)
|
31
29
|
yard (0.8.2)
|
32
30
|
|
33
31
|
PLATFORMS
|
@@ -36,9 +34,9 @@ PLATFORMS
|
|
36
34
|
DEPENDENCIES
|
37
35
|
app_config!
|
38
36
|
bson_ext
|
39
|
-
maruku
|
40
37
|
mongo
|
41
38
|
rake
|
39
|
+
redcarpet
|
42
40
|
rspec (~> 2.10.0)
|
43
41
|
simplecov
|
44
42
|
yard
|
data/README.md
CHANGED
@@ -1,33 +1,35 @@
|
|
1
|
-
# AppConfig
|
1
|
+
# AppConfig [![Build Status](https://travis-ci.org/Oshuma/app_config.png?branch=master)](https://travis-ci.org/Oshuma/app_config) [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=3N885MZB7QCY6&lc=US&item_name=Dale%20Campbell&item_number=app_config¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted)
|
2
2
|
|
3
3
|
An easy to use, customizable library to easily store and retrieve application
|
4
4
|
(or library) configuration, API keys or basically anything in 'key/value' pairs.
|
5
5
|
|
6
6
|
AppConfig requires at least Ruby 1.9.
|
7
7
|
|
8
|
+
|
9
|
+
## Deprecation Note
|
10
|
+
|
11
|
+
Version `2.0` is **not** backwards compatible with the `1.x` branch.
|
12
|
+
|
13
|
+
See the [wiki](https://github.com/Oshuma/app_config/wiki) for upgrade instructions.
|
14
|
+
|
15
|
+
|
8
16
|
## Usage
|
9
17
|
|
10
|
-
Usage is simple. Just pass either a hash of options, or a block, to {AppConfig.setup}.
|
18
|
+
Usage is simple. Just pass either a hash of options, or a block, to {AppConfig.setup!}.
|
11
19
|
|
12
20
|
In it's simplest form, you can use it like so:
|
13
21
|
|
14
|
-
AppConfig.setup(:admin_email => 'admin@example.com')
|
22
|
+
AppConfig.setup!(:admin_email => 'admin@example.com')
|
15
23
|
# ..or..
|
16
|
-
AppConfig.setup do |config|
|
17
|
-
config
|
24
|
+
AppConfig.setup! do |config|
|
25
|
+
config.admin_email = 'admin@example.com'
|
18
26
|
end
|
19
27
|
|
20
|
-
#
|
21
|
-
AppConfig[:admin_email] # => 'admin@example.com'
|
28
|
+
AppConfig.admin_email # => 'admin@example.com'
|
22
29
|
|
23
30
|
You may also specify the storage method along with options specific to that storage method.
|
24
31
|
Check the [wiki](https://github.com/Oshuma/app_config/wiki) for more usage examples.
|
25
32
|
|
26
|
-
## Deprecation Note
|
27
|
-
|
28
|
-
Version `1.0` is \***not**\* backwards compatible with `0.7.1`! See the [wiki](https://github.com/Oshuma/app_config/wiki)
|
29
|
-
for upgrade instructions.
|
30
|
-
|
31
33
|
|
32
34
|
## AppConfig::Storage::YAML
|
33
35
|
|
@@ -40,18 +42,17 @@ Given this YAML file:
|
|
40
42
|
|
41
43
|
Use it like so:
|
42
44
|
|
43
|
-
AppConfig.setup(:yaml => '/path/to/app_config.yml')
|
45
|
+
AppConfig.setup!(:yaml => '/path/to/app_config.yml')
|
44
46
|
|
45
47
|
# Later on...
|
46
|
-
#
|
47
|
-
AppConfig
|
48
|
-
AppConfig
|
49
|
-
AppConfig[:api_key] # => 'SUPERAWESOMESERVICE'
|
48
|
+
AppConfig.admin_email # => 'admin@example.com'
|
49
|
+
AppConfig.api_name # => 'Supr Webz 2.0'
|
50
|
+
AppConfig.api_key # => 'SUPERAWESOMESERVICE'
|
50
51
|
|
51
52
|
|
52
53
|
## AppConfig::Storage::Mongo
|
53
54
|
|
54
|
-
You can pass a `:mongo` options hash to {AppConfig.setup} which should contain
|
55
|
+
You can pass a `:mongo` options hash to {AppConfig.setup!} which should contain
|
55
56
|
configuration values for a Mongo database. Check the {AppConfig::Storage::Mongo::DEFAULTS}
|
56
57
|
constant for the default Mongo connection options.
|
57
58
|
|
@@ -61,43 +62,18 @@ constant for the default Mongo connection options.
|
|
61
62
|
:collection => 'app_config' # default
|
62
63
|
}
|
63
64
|
|
64
|
-
AppConfig.setup(:mongo => mongo_opts)
|
65
|
+
AppConfig.setup!(:mongo => mongo_opts)
|
65
66
|
|
66
|
-
AppConfig
|
67
|
-
# => 'admin@example.com'
|
67
|
+
AppConfig.admin_email # => 'admin@example.com'
|
68
68
|
|
69
|
-
# Override an existing value
|
70
|
-
AppConfig
|
69
|
+
# Override an existing value and save to the database:
|
70
|
+
AppConfig.admin_email = 'other_admin@example.com'
|
71
|
+
AppConfig.save!
|
71
72
|
|
72
73
|
The values are read/saved (by default) to the `app_config` database and
|
73
74
|
`app_config` collection. These defaults can be overridden, however, which
|
74
75
|
might lend well to versioned configurations; collection names such as
|
75
76
|
`app_config_v1`, `app_config_v2`, etc.
|
76
77
|
|
77
|
-
AppConfig.setup(:mongo => { :collection => 'app_config_v2' })
|
78
|
-
|
79
|
-
|
80
|
-
## Environment Mode
|
81
|
-
|
82
|
-
There's also an 'environment mode' where you can organize the config
|
83
|
-
sort of like the Rails database config. Given this YAML file:
|
84
|
-
|
85
|
-
# Rails.root/config/app_config.yml
|
86
|
-
development:
|
87
|
-
title: 'Development Mode'
|
88
|
-
|
89
|
-
production:
|
90
|
-
title: 'Production Mode'
|
91
|
-
|
92
|
-
Set the `:env` option to your desired environment.
|
93
|
-
|
94
|
-
# Rails.root/config/initializers/app_config.rb
|
95
|
-
AppConfig.setup({
|
96
|
-
:yaml => "#{Rails.root}/config/app_config.yml",
|
97
|
-
:env => Rails.env # or any string
|
98
|
-
})
|
99
|
-
|
100
|
-
# Uses the given environment section of the config.
|
101
|
-
AppConfig[:title]
|
102
|
-
# => 'Production Mode'
|
78
|
+
AppConfig.setup!(:mongo => { :collection => 'app_config_v2' })
|
103
79
|
|
data/app_config.gemspec
CHANGED
@@ -7,15 +7,15 @@ Gem::Specification.new do |s|
|
|
7
7
|
|
8
8
|
s.authors = ['Dale Campbell']
|
9
9
|
s.email = ['oshuma@gmail.com']
|
10
|
-
s.homepage = 'http://oshuma.github.
|
10
|
+
s.homepage = 'http://oshuma.github.io/app_config'
|
11
11
|
|
12
12
|
s.summary = %q{Quick and easy application configuration.}
|
13
13
|
s.description = %q{An easy to use, customizable library to easily store and retrieve application configuration.}
|
14
14
|
|
15
15
|
s.add_development_dependency 'bson_ext'
|
16
|
-
s.add_development_dependency 'maruku'
|
17
16
|
s.add_development_dependency 'mongo'
|
18
17
|
s.add_development_dependency 'rake'
|
18
|
+
s.add_development_dependency 'redcarpet'
|
19
19
|
s.add_development_dependency 'rspec', '~> 2.10.0'
|
20
20
|
s.add_development_dependency 'simplecov'
|
21
21
|
s.add_development_dependency 'yard'
|
data/lib/app_config/error.rb
CHANGED
@@ -2,12 +2,22 @@ module AppConfig
|
|
2
2
|
module Storage
|
3
3
|
class Base
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
@options = options
|
5
|
+
def initialize
|
7
6
|
end
|
8
7
|
|
9
8
|
def to_hash
|
10
|
-
defined?(@data) ? @data.
|
9
|
+
defined?(@data) ? @data.marshal_dump : Hash.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# Wrap `method_missing` to proxy to `@data`.
|
13
|
+
def method_missing(name, *args)
|
14
|
+
unless @data.nil?
|
15
|
+
if name =~ /.+=$/ # Caller is a setter.
|
16
|
+
@data.send(name.to_sym, *args[0])
|
17
|
+
else
|
18
|
+
@data.send(name.to_sym)
|
19
|
+
end
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
end # Base
|
@@ -22,29 +22,19 @@ module AppConfig
|
|
22
22
|
fetch_data!
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
@data[key]
|
27
|
-
end
|
28
|
-
|
29
|
-
def []=(key, value)
|
30
|
-
@data[key] = value
|
31
|
-
save!
|
32
|
-
end
|
33
|
-
|
34
|
-
def empty?
|
35
|
-
@data.empty?
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
25
|
+
# Saves the data back to Mongo. Returns `true`/`false`.
|
40
26
|
def save!
|
41
27
|
if @_id
|
42
|
-
collection.update({ '_id' => @_id}, @data)
|
28
|
+
retval = collection.update({ '_id' => @_id}, @data.to_h)
|
43
29
|
else
|
44
|
-
collection.save(@data)
|
30
|
+
retval = collection.save(@data.to_h)
|
45
31
|
end
|
32
|
+
|
33
|
+
!!retval
|
46
34
|
end
|
47
35
|
|
36
|
+
private
|
37
|
+
|
48
38
|
def setup_connection
|
49
39
|
@connection = ::Mongo::Connection.new(@options[:host], @options[:port].to_i)
|
50
40
|
authenticate_connection if @options[:user] && @options[:password]
|
@@ -61,10 +51,8 @@ module AppConfig
|
|
61
51
|
def fetch_data!
|
62
52
|
raise 'Not connected to MongoDB' unless connected?
|
63
53
|
|
64
|
-
@data =
|
65
|
-
@
|
66
|
-
|
67
|
-
@_id = @data.delete('_id')
|
54
|
+
@data = OpenStruct.new(collection.find_one)
|
55
|
+
@_id = @data._id
|
68
56
|
end
|
69
57
|
|
70
58
|
def database
|
@@ -9,24 +9,12 @@ module AppConfig
|
|
9
9
|
DEFAULT_PATH = File.join(Dir.home, '.app_config.yml')
|
10
10
|
|
11
11
|
# Loads `@data` with the YAML file located at `path`.
|
12
|
-
# `@data` will be the
|
12
|
+
# `@data` will be the OpenStruct that is accessed with `AppConfig.some_var`.
|
13
13
|
#
|
14
14
|
# Defaults to `Dir.home/.app_config.yml`
|
15
15
|
def initialize(path = DEFAULT_PATH)
|
16
16
|
# Make sure to use the top-level YAML module here.
|
17
|
-
@data =
|
18
|
-
end
|
19
|
-
|
20
|
-
def [](key)
|
21
|
-
@data[key]
|
22
|
-
end
|
23
|
-
|
24
|
-
def []=(key, value)
|
25
|
-
@data[key] = value
|
26
|
-
end
|
27
|
-
|
28
|
-
def empty?
|
29
|
-
@data.empty?
|
17
|
+
@data = OpenStruct.new(::YAML.load_file(path))
|
30
18
|
end
|
31
19
|
|
32
20
|
end # YAML
|
data/lib/app_config.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'ostruct'
|
2
2
|
|
3
3
|
module AppConfig
|
4
|
-
VERSION
|
4
|
+
autoload :VERSION, 'app_config/version'
|
5
5
|
|
6
6
|
autoload :Error, 'app_config/error'
|
7
7
|
autoload :Storage, 'app_config/storage'
|
@@ -14,8 +14,7 @@ module AppConfig
|
|
14
14
|
# Valid storage methods:
|
15
15
|
# * `:mongo` - {AppConfig::Storage::Mongo AppConfig::Storage::Mongo}
|
16
16
|
# * `:yaml` - {AppConfig::Storage::YAML AppConfig::Storage::YAML}
|
17
|
-
def setup(options = {}, &block)
|
18
|
-
warn "DEPRECATED: AppConfig.setup will be renamed to AppConfig.setup! in 2.0."
|
17
|
+
def setup!(options = {}, &block)
|
19
18
|
@@options = options
|
20
19
|
|
21
20
|
if @@options[:yaml]
|
@@ -23,7 +22,7 @@ module AppConfig
|
|
23
22
|
elsif @@options[:mongo]
|
24
23
|
@@storage = AppConfig::Storage::Mongo.new(@@options.delete(:mongo))
|
25
24
|
else
|
26
|
-
@@storage =
|
25
|
+
@@storage = AppConfig::Storage::Base.new
|
27
26
|
end
|
28
27
|
|
29
28
|
yield @@storage if block_given?
|
@@ -31,64 +30,30 @@ module AppConfig
|
|
31
30
|
to_hash
|
32
31
|
end
|
33
32
|
|
34
|
-
# Returns `true` if {AppConfig.setup AppConfig.setup} has been called.
|
33
|
+
# Returns `true` if {AppConfig.setup! AppConfig.setup!} has been called.
|
35
34
|
def setup?
|
36
|
-
|
35
|
+
defined?(@@storage) && !@@storage.nil?
|
37
36
|
end
|
38
37
|
|
39
38
|
# Clears the `@@storage`.
|
40
39
|
def reset!
|
41
|
-
|
42
|
-
remove_class_variable(:@@storage)
|
43
|
-
true
|
44
|
-
else
|
45
|
-
false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Access the configured `key`'s value.
|
50
|
-
def [](key)
|
51
|
-
warn "DEPRECATED: AppConfig.[] is deprecated and will be removed in 2.0."
|
52
|
-
setup unless setup?
|
53
|
-
storage[key]
|
54
|
-
end
|
55
|
-
|
56
|
-
# Set a new `value` for `key` (persistence depends on the type of Storage).
|
57
|
-
def []=(key, value)
|
58
|
-
warn "DEPRECATED: AppConfig.[]= is deprecated and will be removed in 2.0."
|
59
|
-
setup unless setup?
|
60
|
-
storage[key] = value
|
61
|
-
end
|
62
|
-
|
63
|
-
def empty?
|
64
|
-
warn "DEPRECATED: AppConfig.empty? is deprecated and will be removed in 2.0."
|
65
|
-
storage.empty?
|
40
|
+
@@storage = nil
|
66
41
|
end
|
67
42
|
|
68
43
|
def to_hash
|
69
|
-
|
70
|
-
@@storage = default_storage
|
71
|
-
end
|
72
|
-
|
73
|
-
storage.to_hash
|
44
|
+
storage ? storage.to_hash : {}
|
74
45
|
end
|
75
46
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def default_storage
|
80
|
-
Hash.new(&Storage::DEEP_HASH)
|
47
|
+
# Wrap `method_missing` to proxy to `storage`.
|
48
|
+
def method_missing(name, *args)
|
49
|
+
storage.send(name.to_sym, *args)
|
81
50
|
end
|
82
51
|
|
83
|
-
|
84
|
-
warn "DEPRECATED: Environment mode will be removed in 2.0."
|
85
|
-
(@@options[:environment] || @@options[:env]) || nil
|
86
|
-
end
|
87
|
-
alias_method :env, :environment
|
52
|
+
private
|
88
53
|
|
89
54
|
# Returns the `@@storage` contents, which is what is exposed as the configuration.
|
90
55
|
def storage
|
91
|
-
|
56
|
+
@@storage
|
92
57
|
end
|
93
58
|
|
94
59
|
end # self
|
@@ -9,17 +9,15 @@ describe AppConfig::Storage::Mongo do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should have some values' do
|
12
|
-
AppConfig
|
12
|
+
AppConfig.api_key.should_not be_nil
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should update the values' do
|
16
|
-
AppConfig.
|
17
|
-
AppConfig
|
18
|
-
AppConfig[:api_key].should == 'SOME_NEW_API_KEY'
|
19
|
-
end
|
16
|
+
AppConfig.api_key = 'SOME_NEW_API_KEY'
|
17
|
+
AppConfig.api_key.should == 'SOME_NEW_API_KEY'
|
20
18
|
|
21
|
-
|
22
|
-
AppConfig
|
19
|
+
AppConfig.class_variable_get(:@@storage).should_receive(:save!)
|
20
|
+
AppConfig.save!
|
23
21
|
end
|
24
22
|
|
25
23
|
it 'should have a @_id variable for the Mongo ID' do
|
@@ -4,7 +4,7 @@ describe AppConfig::Storage::YAML do
|
|
4
4
|
|
5
5
|
it 'should have some values' do
|
6
6
|
config_for_yaml
|
7
|
-
AppConfig
|
7
|
+
AppConfig.api_key.should_not be_nil
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should raise file not found' do
|
@@ -15,8 +15,8 @@ describe AppConfig::Storage::YAML do
|
|
15
15
|
|
16
16
|
it 'saves the new value in memory' do
|
17
17
|
config_for_yaml
|
18
|
-
AppConfig
|
19
|
-
AppConfig
|
18
|
+
AppConfig.new_key = 'new value'
|
19
|
+
AppConfig.new_key.should == 'new value'
|
20
20
|
end
|
21
21
|
|
22
22
|
it "requires the use of 'Dir.home'" do
|
data/spec/app_config_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe AppConfig do
|
|
6
6
|
AppConfig::VERSION.should_not be_nil
|
7
7
|
end
|
8
8
|
|
9
|
-
it 'responds to .setup()' do
|
10
|
-
AppConfig.should respond_to(:setup)
|
9
|
+
it 'responds to .setup!()' do
|
10
|
+
AppConfig.should respond_to(:setup!)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'responds to .setup?()' do
|
@@ -28,7 +28,7 @@ describe AppConfig do
|
|
28
28
|
config_for_yaml(:api_key => 'API_KEY')
|
29
29
|
# then reset
|
30
30
|
AppConfig.reset!
|
31
|
-
AppConfig
|
31
|
+
AppConfig.send(:storage).should be_nil
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'to_hash() returns an empty hash if storage not set' do
|
@@ -36,14 +36,6 @@ describe AppConfig do
|
|
36
36
|
AppConfig.to_hash.should == {}
|
37
37
|
end
|
38
38
|
|
39
|
-
describe 'environment mode' do
|
40
|
-
it 'should load the proper environment' do
|
41
|
-
config_for_yaml(:yaml => fixture('env_app_config.yml'),
|
42
|
-
:env => 'development')
|
43
|
-
AppConfig[:api_key].should_not be_nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
39
|
it 'should not be setup' do
|
48
40
|
AppConfig.reset!
|
49
41
|
AppConfig.should_not be_setup
|
@@ -55,26 +47,21 @@ describe AppConfig do
|
|
55
47
|
end
|
56
48
|
|
57
49
|
it 'should create nested keys' do
|
50
|
+
pending 'Re-implement this later.'
|
58
51
|
AppConfig.reset!
|
59
|
-
AppConfig.setup
|
52
|
+
AppConfig.setup!
|
60
53
|
|
61
|
-
AppConfig
|
62
|
-
AppConfig
|
54
|
+
AppConfig.person.name.first = 'Dale'
|
55
|
+
AppConfig.person.name.first.should == 'Dale'
|
63
56
|
end
|
64
57
|
|
65
58
|
it 'returns a Hash on setup' do
|
66
59
|
AppConfig.reset!
|
67
|
-
config = AppConfig.setup do |c|
|
68
|
-
c
|
69
|
-
c
|
60
|
+
config = AppConfig.setup! do |c|
|
61
|
+
c.name = 'Dale'
|
62
|
+
c.nick = 'Oshuma'
|
70
63
|
end
|
71
64
|
config.should be_instance_of(Hash)
|
72
65
|
end
|
73
66
|
|
74
|
-
it '.default_storage() returns a nested Hash' do
|
75
|
-
hash = AppConfig.send(:default_storage)
|
76
|
-
hash[:name][:first] = 'Dale'
|
77
|
-
hash[:name][:first].should == 'Dale'
|
78
|
-
end
|
79
|
-
|
80
67
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,10 +14,10 @@ RSpec.configure do |config|
|
|
14
14
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', name))
|
15
15
|
end
|
16
16
|
|
17
|
-
# AppConfig.setup wrapper. Accepts a hash of +options+.
|
17
|
+
# AppConfig.setup! wrapper. Accepts a hash of +options+.
|
18
18
|
def config_for(options)
|
19
19
|
AppConfig.reset!
|
20
|
-
AppConfig.setup(options)
|
20
|
+
AppConfig.setup!(options)
|
21
21
|
end
|
22
22
|
|
23
23
|
# Setup YAML options and pass to config_for().
|
metadata
CHANGED
@@ -1,84 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dale Campbell
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bson_ext
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
28
|
+
name: mongo
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
42
|
+
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
56
|
+
name: redcarpet
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ~>
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,7 +76,6 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ~>
|
92
81
|
- !ruby/object:Gem::Version
|
@@ -94,33 +83,29 @@ dependencies:
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: simplecov
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: yard
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- -
|
108
|
+
- - '>='
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: '0'
|
126
111
|
description: An easy to use, customizable library to easily store and retrieve application
|
@@ -133,6 +118,7 @@ extra_rdoc_files: []
|
|
133
118
|
files:
|
134
119
|
- .gitignore
|
135
120
|
- .rspec
|
121
|
+
- .travis.yml
|
136
122
|
- Gemfile
|
137
123
|
- Gemfile.lock
|
138
124
|
- README.md
|
@@ -145,18 +131,18 @@ files:
|
|
145
131
|
- lib/app_config/storage/base.rb
|
146
132
|
- lib/app_config/storage/mongo.rb
|
147
133
|
- lib/app_config/storage/yaml.rb
|
148
|
-
- lib/
|
134
|
+
- lib/app_config/version.rb
|
149
135
|
- spec/app_config/storage/mongo_spec.rb
|
150
136
|
- spec/app_config/storage/yaml_spec.rb
|
151
137
|
- spec/app_config/storage_spec.rb
|
152
138
|
- spec/app_config_spec.rb
|
153
|
-
- spec/core_ext/hashish_spec.rb
|
154
139
|
- spec/fixtures/app_config.yml
|
155
140
|
- spec/fixtures/app_config_mongo.yml
|
156
141
|
- spec/fixtures/env_app_config.yml
|
157
142
|
- spec/spec_helper.rb
|
158
|
-
homepage: http://oshuma.github.
|
143
|
+
homepage: http://oshuma.github.io/app_config
|
159
144
|
licenses: []
|
145
|
+
metadata: {}
|
160
146
|
post_install_message:
|
161
147
|
rdoc_options:
|
162
148
|
- --inline-source
|
@@ -164,22 +150,28 @@ rdoc_options:
|
|
164
150
|
require_paths:
|
165
151
|
- lib
|
166
152
|
required_ruby_version: !ruby/object:Gem::Requirement
|
167
|
-
none: false
|
168
153
|
requirements:
|
169
|
-
- -
|
154
|
+
- - '>='
|
170
155
|
- !ruby/object:Gem::Version
|
171
156
|
version: '0'
|
172
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
-
none: false
|
174
158
|
requirements:
|
175
|
-
- -
|
159
|
+
- - '>='
|
176
160
|
- !ruby/object:Gem::Version
|
177
161
|
version: '0'
|
178
162
|
requirements: []
|
179
163
|
rubyforge_project:
|
180
|
-
rubygems_version:
|
164
|
+
rubygems_version: 2.0.2
|
181
165
|
signing_key:
|
182
|
-
specification_version:
|
166
|
+
specification_version: 4
|
183
167
|
summary: Quick and easy application configuration.
|
184
|
-
test_files:
|
168
|
+
test_files:
|
169
|
+
- spec/app_config/storage/mongo_spec.rb
|
170
|
+
- spec/app_config/storage/yaml_spec.rb
|
171
|
+
- spec/app_config/storage_spec.rb
|
172
|
+
- spec/app_config_spec.rb
|
173
|
+
- spec/fixtures/app_config.yml
|
174
|
+
- spec/fixtures/app_config_mongo.yml
|
175
|
+
- spec/fixtures/env_app_config.yml
|
176
|
+
- spec/spec_helper.rb
|
185
177
|
has_rdoc: true
|
data/lib/core_ext/hashish.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
# Stolen from Rails `ActiveSupport::HashWithIndifferentAccess` and renamed to Hashish.
|
2
|
-
#
|
3
|
-
# This class has dubious semantics and we only have it so that
|
4
|
-
# people can write `params[:key]` instead of `params['key']`
|
5
|
-
# and they get the same value for both keys.
|
6
|
-
class Hashish < Hash
|
7
|
-
def initialize(constructor = {})
|
8
|
-
if constructor.is_a?(Hash)
|
9
|
-
super()
|
10
|
-
update(constructor)
|
11
|
-
else
|
12
|
-
super(constructor)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def default(key = nil)
|
17
|
-
if key.is_a?(Symbol) && include?(key = key.to_s)
|
18
|
-
self[key]
|
19
|
-
else
|
20
|
-
super
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
25
|
-
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
26
|
-
|
27
|
-
# Assigns a new value to the hash:
|
28
|
-
#
|
29
|
-
# hash = HashWithIndifferentAccess.new
|
30
|
-
# hash[:key] = "value"
|
31
|
-
def []=(key, value)
|
32
|
-
regular_writer(convert_key(key), convert_value(value))
|
33
|
-
end
|
34
|
-
|
35
|
-
# Updates the instantized hash with values from the second:
|
36
|
-
#
|
37
|
-
# hash_1 = HashWithIndifferentAccess.new
|
38
|
-
# hash_1[:key] = "value"
|
39
|
-
#
|
40
|
-
# hash_2 = HashWithIndifferentAccess.new
|
41
|
-
# hash_2[:key] = "New Value!"
|
42
|
-
#
|
43
|
-
# hash_1.update(hash_2) # => {"key"=>"New Value!"}
|
44
|
-
def update(other_hash)
|
45
|
-
other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
alias_method :merge!, :update
|
50
|
-
|
51
|
-
# Checks the hash for a key matching the argument passed in:
|
52
|
-
#
|
53
|
-
# hash = HashWithIndifferentAccess.new
|
54
|
-
# hash["key"] = "value"
|
55
|
-
# hash.key? :key # => true
|
56
|
-
# hash.key? "key" # => true
|
57
|
-
def key?(key)
|
58
|
-
super(convert_key(key))
|
59
|
-
end
|
60
|
-
|
61
|
-
alias_method :include?, :key?
|
62
|
-
alias_method :has_key?, :key?
|
63
|
-
alias_method :member?, :key?
|
64
|
-
|
65
|
-
# Fetches the value for the specified key, same as doing `hash[key]`.
|
66
|
-
def fetch(key, *extras)
|
67
|
-
super(convert_key(key), *extras)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Returns an array of the values at the specified indices:
|
71
|
-
#
|
72
|
-
# hash = HashWithIndifferentAccess.new
|
73
|
-
# hash[:a] = "x"
|
74
|
-
# hash[:b] = "y"
|
75
|
-
# hash.values_at("a", "b") # => ["x", "y"]
|
76
|
-
def values_at(*indices)
|
77
|
-
indices.collect {|key| self[convert_key(key)]}
|
78
|
-
end
|
79
|
-
|
80
|
-
# Returns an exact copy of the hash.
|
81
|
-
def dup
|
82
|
-
HashWithIndifferentAccess.new(self)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Merges the instantized and the specified hashes together, giving precedence to the values from the second hash
|
86
|
-
# Does not overwrite the existing hash.
|
87
|
-
def merge(hash)
|
88
|
-
self.dup.update(hash)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
|
92
|
-
# This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess.
|
93
|
-
def reverse_merge(other_hash)
|
94
|
-
super other_hash.with_indifferent_access
|
95
|
-
end
|
96
|
-
|
97
|
-
def reverse_merge!(other_hash)
|
98
|
-
replace(reverse_merge( other_hash ))
|
99
|
-
end
|
100
|
-
|
101
|
-
# Removes a specified key from the hash.
|
102
|
-
def delete(key)
|
103
|
-
super(convert_key(key))
|
104
|
-
end
|
105
|
-
|
106
|
-
def stringify_keys!; self end
|
107
|
-
def symbolize_keys!; self end
|
108
|
-
def to_options!; self end
|
109
|
-
|
110
|
-
# Convert to a Hash with String keys.
|
111
|
-
def to_hash
|
112
|
-
Hash.new(default).merge!(self)
|
113
|
-
end
|
114
|
-
|
115
|
-
protected
|
116
|
-
|
117
|
-
def convert_key(key)
|
118
|
-
key.kind_of?(Symbol) ? key.to_s : key
|
119
|
-
end
|
120
|
-
|
121
|
-
def convert_value(value)
|
122
|
-
case value
|
123
|
-
when Hash
|
124
|
-
value.with_indifferent_access
|
125
|
-
when Array
|
126
|
-
value.collect { |e| e.is_a?(Hash) ? e.with_indifferent_access : e }
|
127
|
-
else
|
128
|
-
value
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end # Hashish
|
133
|
-
|
134
|
-
class Hash
|
135
|
-
def with_indifferent_access
|
136
|
-
hash = Hashish.new(self)
|
137
|
-
hash.default = self.default
|
138
|
-
hash
|
139
|
-
end
|
140
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hashish do
|
4
|
-
before(:each) do
|
5
|
-
@strings = { 'key' => 'value', 'four' => 20 }
|
6
|
-
@symbols = { :key => 'value', :four => 20 }
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should not give a fuck about symbols' do
|
10
|
-
hashish = Hashish.new(@strings)
|
11
|
-
hashish[:key].should == 'value'
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should not give a fuck about strings' do
|
15
|
-
hashish = Hashish.new(@symbols)
|
16
|
-
hashish['key'].should == 'value'
|
17
|
-
end
|
18
|
-
end
|