configster 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +12 -0
- data/README.md +13 -3
- data/configster.gemspec +1 -1
- data/examples/active_record_example.rb +21 -0
- data/examples/httparty_example.rb +22 -0
- data/lib/configster/configster.rb +9 -6
- data/lib/configster/version.rb +1 -1
- data/spec/configster_spec.rb +8 -2
- data/spec/spec_helper.rb +1 -1
- metadata +8 -5
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## 0.0.2 (September 12, 2012)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- Added the ability to load multiple configurations.
|
6
|
+
- Added an examples directory with a basic HTTParty and ActiveRecord example.
|
7
|
+
|
8
|
+
Documentation:
|
9
|
+
|
10
|
+
- Fixed a "bug" in the README.
|
11
|
+
- Added a note about accessing Configster directly.
|
12
|
+
- Added additional notes that reference the examples directory.
|
data/README.md
CHANGED
@@ -23,9 +23,9 @@ Or install it yourself as:
|
|
23
23
|
For most applications, you'll want to load Configster before you start loading the rest of your application. For example:
|
24
24
|
|
25
25
|
require 'configster'
|
26
|
-
Configster.
|
26
|
+
Configster.load!(File.join('path', 'to', 'my_config.yml'))
|
27
27
|
|
28
|
-
You can also pass a raw hash of stuff into `
|
28
|
+
You can also pass a raw hash of stuff into `load!` as long as it's in the format of `"ClassName" => { 'variable' => 'whatever' }`
|
29
29
|
|
30
30
|
Then, just include Configster in any classes you want:
|
31
31
|
|
@@ -48,7 +48,7 @@ First, make yourself a nice little configuration file and save it to `~/my_sweet
|
|
48
48
|
Then, you'll write your application like this:
|
49
49
|
|
50
50
|
require 'configster'
|
51
|
-
Configster.
|
51
|
+
Configster.load!('File.expand_path(~/my_sweet_app_credentials.yml'))
|
52
52
|
|
53
53
|
class MySweetApp
|
54
54
|
|
@@ -69,8 +69,18 @@ Then, you'll write your application like this:
|
|
69
69
|
|
70
70
|
end
|
71
71
|
|
72
|
+
You can also access the configuration more directly without the mixin by doing the following:
|
73
|
+
|
74
|
+
# Return the config as an instance of OpenStruct
|
75
|
+
Configster.config_for('MySweetApp')
|
76
|
+
|
77
|
+
# Return the config as a raw hash
|
78
|
+
Configster.raw_config_for('MySweetApp')
|
79
|
+
|
72
80
|
Now you can share your application without hard coding and/or sharing your credentials.
|
73
81
|
|
82
|
+
For more examples accessing Configster directly or using it without YAML, check the examples directory in the gem.
|
83
|
+
|
74
84
|
## Contributing
|
75
85
|
|
76
86
|
1. Fork it
|
data/configster.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["patricktulskie@gmail.com"]
|
11
11
|
gem.description = %q{Configster is a tidy little configuration management utility for your application. Store your configuration as YAML outside of your application. You probably haven't heard of it.}
|
12
12
|
gem.summary = %q{Configster keeps your configuration out of your application.}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/PatrickTulskie/configster"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'configster'
|
3
|
+
|
4
|
+
Configster.load!(
|
5
|
+
'my_production_database' => {
|
6
|
+
:adapter => 'mysql2',
|
7
|
+
:database => 'configster_production_database',
|
8
|
+
:cast => false
|
9
|
+
:encoding => 'utf8'
|
10
|
+
:username => 'configster',
|
11
|
+
:password => 'configitywiggy',
|
12
|
+
:socket => '/tmp/mysql.sock'
|
13
|
+
}
|
14
|
+
)
|
15
|
+
|
16
|
+
# You don't have to load from the mixin - you can just access Configster directly for free form configurations.
|
17
|
+
my_database_config = Configster.raw_config_for('my_production_database')
|
18
|
+
my_database_config.symbolize_keys!
|
19
|
+
|
20
|
+
# And throw it into ActiveRecord
|
21
|
+
ActiveRecord::Base.establish_connection(my_database_config)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'configster'
|
2
|
+
|
3
|
+
# Do this in an initializer somewhere...
|
4
|
+
Configster.load!(
|
5
|
+
'MySweetApp' => {
|
6
|
+
'username' => 'SweetUsername',
|
7
|
+
'password' => 'SweetPassword123'
|
8
|
+
}
|
9
|
+
)
|
10
|
+
|
11
|
+
class MySweetApp
|
12
|
+
|
13
|
+
include Configster
|
14
|
+
include HTTParty
|
15
|
+
# Configure your class here and then you're all set
|
16
|
+
basic_auth configster.username, configster.password
|
17
|
+
|
18
|
+
def timeline(which = :friends, options = { })
|
19
|
+
self.class.get("/statuses/#{which}_timeline.json", options)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -5,11 +5,11 @@ module Configster
|
|
5
5
|
# =========================================
|
6
6
|
module ClassMethods
|
7
7
|
def configster
|
8
|
-
@configster ||= Configster.
|
8
|
+
@configster ||= Configster.config_for(self)
|
9
9
|
end
|
10
10
|
|
11
11
|
def raw_configster
|
12
|
-
Configster.
|
12
|
+
Configster.raw_config_for(self)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -31,21 +31,24 @@ module Configster
|
|
31
31
|
# ===========================
|
32
32
|
# = Core Configster Methods =
|
33
33
|
# ===========================
|
34
|
-
def self.
|
35
|
-
@configster_config
|
34
|
+
def self.load!(configster_config)
|
35
|
+
@configster_config ||= { }
|
36
|
+
new_config = case configster_config
|
36
37
|
when Hash
|
37
38
|
configster_config
|
38
39
|
when String
|
39
40
|
YAML.load_file(configster_config)
|
40
41
|
end
|
42
|
+
|
43
|
+
@configster_config.merge!(new_config)
|
41
44
|
end
|
42
45
|
|
43
|
-
def self.
|
46
|
+
def self.config_for(klass)
|
44
47
|
klass_config = @configster_config[klass.to_s]
|
45
48
|
klass_config ? OpenStruct.new(klass_config).freeze : nil
|
46
49
|
end
|
47
50
|
|
48
|
-
def self.
|
51
|
+
def self.raw_config_for(klass)
|
49
52
|
@configster_config[klass.to_s]
|
50
53
|
end
|
51
54
|
|
data/lib/configster/version.rb
CHANGED
data/spec/configster_spec.rb
CHANGED
@@ -3,10 +3,16 @@ require "spec_helper"
|
|
3
3
|
describe Configster do
|
4
4
|
|
5
5
|
subject { Configster }
|
6
|
-
it { should respond_to(:
|
6
|
+
it { should respond_to(:config_for) }
|
7
7
|
|
8
8
|
it "should be able to load the configuration for a specific class" do
|
9
|
-
Configster.
|
9
|
+
Configster.config_for(KonfiguredKlass).should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not destroy other configurations when loading additional configs" do
|
13
|
+
Configster.load!('test_thing' => { 'test' => true })
|
14
|
+
Configster.config_for('test_thing').test.should be_true
|
15
|
+
Configster.config_for(KonfiguredKlass).user_name.should == 'configster'
|
10
16
|
end
|
11
17
|
|
12
18
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -26,7 +26,7 @@ RSpec.configure do |config|
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
Configster.
|
29
|
+
Configster.load!(File.join($spec_root, 'configurations', 'test_configuration.yml'))
|
30
30
|
|
31
31
|
class KonfiguredKlass
|
32
32
|
include Configster
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70104961260240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70104961260240
|
25
25
|
description: Configster is a tidy little configuration management utility for your
|
26
26
|
application. Store your configuration as YAML outside of your application. You
|
27
27
|
probably haven't heard of it.
|
@@ -32,11 +32,14 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- .gitignore
|
35
|
+
- CHANGELOG.md
|
35
36
|
- Gemfile
|
36
37
|
- LICENSE.txt
|
37
38
|
- README.md
|
38
39
|
- Rakefile
|
39
40
|
- configster.gemspec
|
41
|
+
- examples/active_record_example.rb
|
42
|
+
- examples/httparty_example.rb
|
40
43
|
- lib/configster.rb
|
41
44
|
- lib/configster/configster.rb
|
42
45
|
- lib/configster/version.rb
|
@@ -44,7 +47,7 @@ files:
|
|
44
47
|
- spec/configurations/test_configuration.yml
|
45
48
|
- spec/konfigured_klass_spec.rb
|
46
49
|
- spec/spec_helper.rb
|
47
|
-
homepage:
|
50
|
+
homepage: https://github.com/PatrickTulskie/configster
|
48
51
|
licenses: []
|
49
52
|
post_install_message:
|
50
53
|
rdoc_options: []
|