korben 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/.rvmrc +1 -0
- data/COMMANDS +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +7 -0
- data/init.rb +1 -0
- data/korben.gemspec +22 -0
- data/lib/korben/kc_config.rb +63 -0
- data/lib/korben/version.rb +3 -0
- data/lib/korben.rb +2 -0
- data/spec/korben/kc_config_spec.rb +38 -0
- data/spec/spec_helper.rb +5 -0
- metadata +125 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p194@korben --create
|
data/COMMANDS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bundle && bundle exec rake spec
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Joel AZEMAR
|
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,38 @@
|
|
1
|
+
# Korben
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'korben'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install korben
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add configuration to initializers files kc_config.rb
|
22
|
+
|
23
|
+
KcConfig.setup do |config|
|
24
|
+
config.const_name = "MyConf"
|
25
|
+
end
|
26
|
+
MyConf.load!( { foo: 'bar' } )
|
27
|
+
|
28
|
+
Anywhere in your code have access to
|
29
|
+
|
30
|
+
MyConf.foo => 'bar'
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/korben'
|
data/korben.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/korben/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Joel AZEMAR']
|
6
|
+
gem.email = ['joel.azemar@gmail.com']
|
7
|
+
gem.description = %q{Simple helper for configuration}
|
8
|
+
gem.summary = %q{Simple helper for Rails App configuration}
|
9
|
+
gem.homepage = 'https://github.com/joel/korben'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'korben'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Korben::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_runtime_dependency 'activesupport'
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
|
3
|
+
module KcConfig
|
4
|
+
# ensures the setup only gets run once
|
5
|
+
@@_ran_once = false
|
6
|
+
|
7
|
+
mattr_accessor :const_name
|
8
|
+
@@const_name = "KcSettings"
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def setup
|
13
|
+
yield self if @@_ran_once == false
|
14
|
+
@@_ran_once = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def load!(settings = {})
|
18
|
+
Kernel.send(:remove_const, KcConfig.const_name) if Kernel.const_defined?(KcConfig.const_name)
|
19
|
+
kc_wrapper = KcWrapper.new
|
20
|
+
kc_wrapper.load!(settings)
|
21
|
+
Kernel.const_set(KcConfig.const_name, kc_wrapper)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class KcWrapper
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@settings = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def load!(settings = {})
|
33
|
+
settings.each do |key, value|
|
34
|
+
set(key, value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def set(key, value)
|
39
|
+
unset(key) if set?(key)
|
40
|
+
define_accessor(key) { value }
|
41
|
+
@settings[key] = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def set?(key)
|
45
|
+
@settings.key?(key)
|
46
|
+
end
|
47
|
+
|
48
|
+
def get(key)
|
49
|
+
@settings[key]
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def define_accessor(name, &block)
|
55
|
+
singleton_class.class_eval { define_method(name, &block) } if !respond_to?(name) || exists?(name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def singleton_class
|
59
|
+
class << self
|
60
|
+
self
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/korben.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KcConfig do
|
4
|
+
|
5
|
+
context "Simple Configuration" do
|
6
|
+
before { KcConfig.load!( { foo: 'bar' } ) }
|
7
|
+
it { KcSettings.get(:foo).should eql 'bar' }
|
8
|
+
it { KcSettings.foo.should eql 'bar' }
|
9
|
+
end
|
10
|
+
|
11
|
+
context "Custom Configuration" do
|
12
|
+
it "should have the default settings constant as 'KcSettings'" do
|
13
|
+
KcConfig.const_name.should eql "KcSettings"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to assign a different settings constant" do
|
17
|
+
KcConfig.setup { |config| config.const_name = "AnotherSettingConstantName" }
|
18
|
+
KcConfig.const_name.should == "AnotherSettingConstantName"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "KcWrapper" do
|
23
|
+
let(:wrapper) { KcWrapper.new }
|
24
|
+
before { wrapper.set(:key, 'value') }
|
25
|
+
subject { wrapper.get(:key) }
|
26
|
+
|
27
|
+
it "should have the value" do
|
28
|
+
should eql 'value'
|
29
|
+
end
|
30
|
+
|
31
|
+
context "have method" do
|
32
|
+
subject { wrapper }
|
33
|
+
its(:key) { should eql 'value' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: korben
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joel AZEMAR
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Simple helper for configuration
|
79
|
+
email:
|
80
|
+
- joel.azemar@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rvmrc
|
87
|
+
- COMMANDS
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- init.rb
|
93
|
+
- korben.gemspec
|
94
|
+
- lib/korben.rb
|
95
|
+
- lib/korben/kc_config.rb
|
96
|
+
- lib/korben/version.rb
|
97
|
+
- spec/korben/kc_config_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: https://github.com/joel/korben
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.24
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Simple helper for Rails App configuration
|
123
|
+
test_files:
|
124
|
+
- spec/korben/kc_config_spec.rb
|
125
|
+
- spec/spec_helper.rb
|