simple-conf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +16 -0
- data/Guardfile +7 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/config/configuration.yml +9 -0
- data/config/options.yml +2 -0
- data/lib/simple-conf/loader.rb +49 -0
- data/lib/simple-conf/version.rb +3 -0
- data/lib/simple-conf.rb +6 -0
- data/simple-conf.gemspec +17 -0
- data/spec/simple_conf_spec.rb +31 -0
- data/spec/spec_helper.rb +6 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@simple-conf
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in simple-conf.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'debugger'
|
8
|
+
gem 'ruby_gntp'
|
9
|
+
gem 'guard'
|
10
|
+
gem 'guard-rspec'
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'rspec'
|
15
|
+
end
|
16
|
+
|
data/Guardfile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
guard 'rspec', :cli => '--format documentation', :version => 2, :all_after_pass => false, :all_on_start => false, :keep_failed => false do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^spec/.+\.rb$})
|
4
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
5
|
+
watch(%r{^lib/messaging_app/(.+)\.rb$}) { "spec" }
|
6
|
+
watch('spec/spec_helper.rb') { "spec" }
|
7
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alexander Korsak
|
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,29 @@
|
|
1
|
+
# SimpleConf
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'simple-conf'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install simple-conf
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/config/options.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module SimpleConf
|
4
|
+
class Loader
|
5
|
+
attr_reader :klass
|
6
|
+
|
7
|
+
def initialize(klass)
|
8
|
+
@klass = klass
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
yaml_file.each_pair do |key, value|
|
13
|
+
set(key, value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def path
|
18
|
+
"./config/#{klass.name.downcase}.yml"
|
19
|
+
end
|
20
|
+
|
21
|
+
def yaml_file
|
22
|
+
content = File.open(path).read
|
23
|
+
YAML.load(content)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def define(key)
|
29
|
+
klass.class_eval %Q{
|
30
|
+
class << self
|
31
|
+
attr_reader :#{key}
|
32
|
+
end
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def set(key, value)
|
37
|
+
define(key)
|
38
|
+
|
39
|
+
struct = OpenStruct.new(value) rescue value
|
40
|
+
klass.instance_variable_set(:"@#{key}", struct)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.included(base)
|
45
|
+
loader = Loader.new(base)
|
46
|
+
loader.run
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
data/lib/simple-conf.rb
ADDED
data/simple-conf.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/simple-conf/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alexander Korsak"]
|
6
|
+
gem.email = ["alex.korsak@gmail.com"]
|
7
|
+
gem.description = "Simple configuration library for yml files for loading from the config folder"
|
8
|
+
gem.summary = "Simple configuration library for yml files for loading from the config folder"
|
9
|
+
gem.homepage = "http://github.com/oivoodoo/simple-conf/"
|
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 = "simple-conf"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = SimpleConf::VERSION
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Configuration
|
4
|
+
include SimpleConf
|
5
|
+
end
|
6
|
+
|
7
|
+
class Options
|
8
|
+
include SimpleConf
|
9
|
+
end
|
10
|
+
|
11
|
+
describe SimpleConf do
|
12
|
+
context "on include to config class generate properties" do
|
13
|
+
it { Configuration.staging.domain.should == "staging.example.com" }
|
14
|
+
|
15
|
+
it "should work properly with collections" do
|
16
|
+
Configuration.staging.links.should == [
|
17
|
+
"test1.example.com",
|
18
|
+
"test2.example.com"
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
it { Configuration.production.domain.should == "production.example.com" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe SimpleConf do
|
27
|
+
context "on include to options class generate properties with only one key and value" do
|
28
|
+
it { Options.domain.should == "example.com" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-conf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Korsak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple configuration library for yml files for loading from the config
|
15
|
+
folder
|
16
|
+
email:
|
17
|
+
- alex.korsak@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- .rspec
|
24
|
+
- .rvmrc
|
25
|
+
- Gemfile
|
26
|
+
- Guardfile
|
27
|
+
- LICENSE
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- config/configuration.yml
|
31
|
+
- config/options.yml
|
32
|
+
- lib/simple-conf.rb
|
33
|
+
- lib/simple-conf/loader.rb
|
34
|
+
- lib/simple-conf/version.rb
|
35
|
+
- simple-conf.gemspec
|
36
|
+
- spec/simple_conf_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
homepage: http://github.com/oivoodoo/simple-conf/
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.8.23
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Simple configuration library for yml files for loading from the config folder
|
62
|
+
test_files:
|
63
|
+
- spec/simple_conf_spec.rb
|
64
|
+
- spec/spec_helper.rb
|