configster 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +1 -0
- data/configster.gemspec +22 -0
- data/lib/configster.rb +5 -0
- data/lib/configster/configster.rb +52 -0
- data/lib/configster/version.rb +3 -0
- data/spec/configster_spec.rb +12 -0
- data/spec/configurations/test_configuration.yml +8 -0
- data/spec/konfigured_klass_spec.rb +31 -0
- data/spec/spec_helper.rb +37 -0
- metadata +75 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Patrick Tulskie
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Configster
|
2
|
+
|
3
|
+
Configster is a tidy little configuration management utility for your application.
|
4
|
+
|
5
|
+
You probably haven't heard of it.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'configster'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install configster
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
For most applications, you'll want to load Configster before you start loading the rest of your application. For example:
|
24
|
+
|
25
|
+
require 'configster'
|
26
|
+
Configster.load_configster!(File.join('path', 'to', 'my_config.yml'))
|
27
|
+
|
28
|
+
You can also pass a raw hash of stuff into `load_configster!` as long as it's in the format of `"ClassName" => { 'variable' => 'whatever' }`
|
29
|
+
|
30
|
+
Then, just include Configster in any classes you want:
|
31
|
+
|
32
|
+
class KonfiguredKlass
|
33
|
+
include Configster
|
34
|
+
end
|
35
|
+
|
36
|
+
Your class now has access to a `configster` and `raw_configster` function where you can query bits and pieces of your configuration.
|
37
|
+
|
38
|
+
## Example
|
39
|
+
|
40
|
+
Say you're writing a sweet application that uses [HTTParty](https://github.com/jnunemaker/httparty) to fetch data from Twitter. You want to share this application with the world, but you don't want to hard code your credentials. Here's how you might handle that:
|
41
|
+
|
42
|
+
First, make yourself a nice little configuration file and save it to `~/my_sweet_app_credentials.yml`:
|
43
|
+
|
44
|
+
MySweetApp:
|
45
|
+
username: SweetUsername
|
46
|
+
password: SweetPassword123
|
47
|
+
|
48
|
+
Then, you'll write your application like this:
|
49
|
+
|
50
|
+
require 'configster'
|
51
|
+
Configster.load_configster!('~/my_sweet_app_credentials.yml')
|
52
|
+
|
53
|
+
class MySweetApp
|
54
|
+
|
55
|
+
include Configster
|
56
|
+
include HTTParty
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
@auth = {
|
60
|
+
:username => configster.username,
|
61
|
+
:password => configster.password
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def timeline(which = :friends, options = { })
|
66
|
+
options.merge!(:basic_auth => @auth)
|
67
|
+
self.class.get("/statuses/#{which}_timeline.json", options)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
Now you can share your application without hard coding and/or sharing your credentials.
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Write specs for your changes to make sure I don't break your features in the future.
|
79
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/configster.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'configster/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "configster"
|
8
|
+
gem.version = Configster::VERSION
|
9
|
+
gem.authors = ["Patrick Tulskie"]
|
10
|
+
gem.email = ["patricktulskie@gmail.com"]
|
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
|
+
gem.summary = %q{Configster keeps your configuration out of your application.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency('rspec')
|
21
|
+
|
22
|
+
end
|
data/lib/configster.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Configster
|
2
|
+
|
3
|
+
# =========================================
|
4
|
+
# = Class Methods for the Receiving Class =
|
5
|
+
# =========================================
|
6
|
+
module ClassMethods
|
7
|
+
def configster
|
8
|
+
@configster ||= Configster.configuration_for(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def raw_configster
|
12
|
+
Configster.raw_configuration_for(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.extend(ClassMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
# ============================================
|
21
|
+
# = Instance Methods for the Receiving Class =
|
22
|
+
# ============================================
|
23
|
+
def configster
|
24
|
+
self.class.configster
|
25
|
+
end
|
26
|
+
|
27
|
+
def raw_configster
|
28
|
+
self.class.raw_configster
|
29
|
+
end
|
30
|
+
|
31
|
+
# ===========================
|
32
|
+
# = Core Configster Methods =
|
33
|
+
# ===========================
|
34
|
+
def self.load_configster!(configster_config)
|
35
|
+
@configster_config = case configster_config
|
36
|
+
when Hash
|
37
|
+
configster_config
|
38
|
+
when String
|
39
|
+
YAML.load_file(configster_config)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.configuration_for(klass)
|
44
|
+
klass_config = @configster_config[klass.to_s]
|
45
|
+
klass_config ? OpenStruct.new(klass_config).freeze : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.raw_configuration_for(klass)
|
49
|
+
@configster_config[klass.to_s]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Configster do
|
4
|
+
|
5
|
+
subject { Configster }
|
6
|
+
it { should respond_to(:configuration_for) }
|
7
|
+
|
8
|
+
it "should be able to load the configuration for a specific class" do
|
9
|
+
Configster.configuration_for(KonfiguredKlass).should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe KonfiguredKlass do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@test_klass = KonfiguredKlass.new
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { @test_klass }
|
10
|
+
it { should respond_to(:configster) }
|
11
|
+
|
12
|
+
it "should be able to fetch attributes from the configuration" do
|
13
|
+
@test_klass.configster.should respond_to(:user_name)
|
14
|
+
@test_klass.configster.should respond_to(:password)
|
15
|
+
@test_klass.configster.should respond_to(:tag_line)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be frozen" do
|
19
|
+
@test_klass.configster.should be_frozen
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should not pollute other configurations" do
|
23
|
+
another_klass = AnotherKlass.new
|
24
|
+
@test_klass.configster.user_name.should_not == another_klass.configster.user_name
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be able to load a raw configuration" do
|
28
|
+
@test_klass.raw_configster.should be_a(Hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rspec'
|
6
|
+
require 'configster'
|
7
|
+
|
8
|
+
$spec_root = File.dirname(__FILE__)
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
12
|
+
|
13
|
+
def puts(s)
|
14
|
+
file = File.basename(caller.first)
|
15
|
+
super("puts() from #{file}: #{s}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def print(s)
|
19
|
+
file = File.basename(caller.first)
|
20
|
+
super("print() from #{file}: #{s}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def p(s)
|
24
|
+
file = File.basename(caller.first)
|
25
|
+
super("p() from #{file}: #{s}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Configster.load_configster!(File.join($spec_root, 'configurations', 'test_configuration.yml'))
|
30
|
+
|
31
|
+
class KonfiguredKlass
|
32
|
+
include Configster
|
33
|
+
end
|
34
|
+
|
35
|
+
class AnotherKlass
|
36
|
+
include Configster
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Patrick Tulskie
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70264095054640 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70264095054640
|
25
|
+
description: Configster is a tidy little configuration management utility for your
|
26
|
+
application. Store your configuration as YAML outside of your application. You
|
27
|
+
probably haven't heard of it.
|
28
|
+
email:
|
29
|
+
- patricktulskie@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- configster.gemspec
|
40
|
+
- lib/configster.rb
|
41
|
+
- lib/configster/configster.rb
|
42
|
+
- lib/configster/version.rb
|
43
|
+
- spec/configster_spec.rb
|
44
|
+
- spec/configurations/test_configuration.yml
|
45
|
+
- spec/konfigured_klass_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: ''
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.8
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Configster keeps your configuration out of your application.
|
71
|
+
test_files:
|
72
|
+
- spec/configster_spec.rb
|
73
|
+
- spec/configurations/test_configuration.yml
|
74
|
+
- spec/konfigured_klass_spec.rb
|
75
|
+
- spec/spec_helper.rb
|