mutaconf 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.screenrc +8 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +44 -0
- data/LICENSE.txt +20 -0
- data/README.md +8 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/mutaconf/dsl.rb +63 -0
- data/lib/mutaconf/errors.rb +14 -0
- data/lib/mutaconf/target.rb +32 -0
- data/lib/mutaconf.rb +11 -0
- data/mutaconf.gemspec +82 -0
- data/spec/block_spec.rb +71 -0
- data/spec/fixtures/eval.rb +4 -0
- data/spec/helper.rb +16 -0
- data/spec/source_spec.rb +66 -0
- data/spec/subclass_spec.rb +32 -0
- data/spec/target_spec.rb +74 -0
- data/spec/version_spec.rb +9 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48c32e67a2354968eb59c5e23d98eb148ee4cd40
|
4
|
+
data.tar.gz: fa3d2c5b847a084389bb79ad1d0eeb6532f92d3a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9015197b8f1ceaf5132f76a27f31780cff2ad956f985ba1164d8973bc3971fc7002bceab61cd7e1f9ad2589446d9ffcfd6c77d70a847eab1d3e3f079c071d5ae
|
7
|
+
data.tar.gz: 28008da318804191037ae4c122d75d0662f2f36fb4648182e55ab3b92f3b7a1805281e0c35d336260552dfea5a69ac6839214f14ea8535d54e91fdf9cbfe5b1c
|
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
mutaconf
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/.screenrc
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem 'bundler'
|
10
|
+
gem 'rake'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'jeweler'
|
13
|
+
gem 'gemcutter'
|
14
|
+
gem 'gem-release'
|
15
|
+
gem 'rake-version'
|
16
|
+
gem 'simplecov'
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.3)
|
5
|
+
gem-release (0.5.3)
|
6
|
+
gemcutter (0.7.1)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.8.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.7.7)
|
14
|
+
multi_json (1.7.2)
|
15
|
+
rake (10.0.4)
|
16
|
+
rake-version (0.3.1)
|
17
|
+
rake (~> 10)
|
18
|
+
rdoc (4.0.1)
|
19
|
+
json (~> 1.4)
|
20
|
+
rspec (2.13.0)
|
21
|
+
rspec-core (~> 2.13.0)
|
22
|
+
rspec-expectations (~> 2.13.0)
|
23
|
+
rspec-mocks (~> 2.13.0)
|
24
|
+
rspec-core (2.13.1)
|
25
|
+
rspec-expectations (2.13.0)
|
26
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
27
|
+
rspec-mocks (2.13.1)
|
28
|
+
simplecov (0.7.1)
|
29
|
+
multi_json (~> 1.0)
|
30
|
+
simplecov-html (~> 0.7.1)
|
31
|
+
simplecov-html (0.7.1)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler
|
38
|
+
gem-release
|
39
|
+
gemcutter
|
40
|
+
jeweler
|
41
|
+
rake
|
42
|
+
rake-version
|
43
|
+
rspec
|
44
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Alpha Hydrae
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "mutaconf"
|
18
|
+
gem.homepage = "http://github.com/AlphaHydrae/mutaconf"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Configuration utilities.}
|
21
|
+
gem.description = %Q{Create simple DSLs and read configuration from hashes or objects.}
|
22
|
+
gem.email = "hydrae.alpha@gmail.com"
|
23
|
+
gem.authors = ["AlphaHydrae"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
Rake::TaskManager.class_eval do
|
29
|
+
def remove_task(task_name)
|
30
|
+
@tasks.delete(task_name.to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
[ 'version', 'version:bump:major', 'version:bump:minor', 'version:bump:patch', 'version:write' ].each do |task|
|
35
|
+
Rake.application.remove_task task
|
36
|
+
end
|
37
|
+
|
38
|
+
# version tasks
|
39
|
+
require 'rake-version'
|
40
|
+
RakeVersion::Tasks.new do |v|
|
41
|
+
v.copy 'lib/mutaconf.rb'
|
42
|
+
end
|
43
|
+
|
44
|
+
require 'rspec/core/rake_task'
|
45
|
+
desc "Run specs"
|
46
|
+
RSpec::Core::RakeTask.new do |t|
|
47
|
+
#t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
48
|
+
# Put spec opts in a file named .rspec in root
|
49
|
+
end
|
50
|
+
|
51
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.4
|
data/lib/mutaconf/dsl.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
module Mutaconf
|
3
|
+
|
4
|
+
class DSL
|
5
|
+
attr_accessor :keys, :target, :lenient
|
6
|
+
|
7
|
+
def initialize options = {}
|
8
|
+
@keys ||= options[:keys] || [] # TODO: spec pre-set keys in parent class
|
9
|
+
@target = Target.new options[:target]
|
10
|
+
@lenient = options[:lenient] if options.key?(:lenient)
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure source = nil, options = {}, &block
|
14
|
+
|
15
|
+
if source.kind_of? Hash
|
16
|
+
configure_from_hash source, options
|
17
|
+
elsif source.kind_of? String
|
18
|
+
configure_from_file source, options
|
19
|
+
elsif source
|
20
|
+
configure_from_object source, options
|
21
|
+
end
|
22
|
+
|
23
|
+
instance_exec self, &block if block
|
24
|
+
|
25
|
+
@target.object
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def configure_from_hash h, options = {}
|
31
|
+
h.each_pair do |k,v|
|
32
|
+
raise KeyError, k unless @keys.empty? or @keys.include?(k.to_sym) or @lenient
|
33
|
+
@target.set k, v if @keys.empty? or @keys.include?(k.to_sym)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def configure_from_file f, options = {}
|
38
|
+
args = [ File.open(f, 'r').read, f ]
|
39
|
+
args << options[:lineno] if options[:lineno]
|
40
|
+
instance_eval *args
|
41
|
+
end
|
42
|
+
|
43
|
+
def configure_from_object o, options = {}
|
44
|
+
@keys.each{ |key| @target.set key, o.send(key.to_sym) if o.respond_to? key.to_sym }
|
45
|
+
end
|
46
|
+
|
47
|
+
def method_missing name, *args, &block
|
48
|
+
|
49
|
+
m = name.to_s.match(/\A(\w+)\=?\Z/)
|
50
|
+
|
51
|
+
# TODO: fail if property is not in @keys
|
52
|
+
key = m[1]
|
53
|
+
if key
|
54
|
+
raise KeyError, key unless @target.has?(key) or @lenient
|
55
|
+
return @target.get key if args.empty?
|
56
|
+
raise KeyError, key unless @keys.empty? or @keys.include?(key.to_sym) or @lenient
|
57
|
+
@target.set key, args.first if @keys.empty? or @keys.include?(key.to_sym)
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Mutaconf
|
4
|
+
|
5
|
+
class Target
|
6
|
+
attr_reader :object
|
7
|
+
|
8
|
+
def initialize object
|
9
|
+
@object = object
|
10
|
+
end
|
11
|
+
|
12
|
+
def set key, value
|
13
|
+
if @object.kind_of? Hash
|
14
|
+
@object[key.to_sym] = value
|
15
|
+
else
|
16
|
+
@object.send "#{key}=", value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def get key
|
21
|
+
if @object.kind_of? Hash
|
22
|
+
@object[key.to_sym]
|
23
|
+
else
|
24
|
+
@object.send key.to_sym
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def has? key
|
29
|
+
@object.kind_of?(Hash) or @object.kind_of?(OpenStruct) or @object.respond_to?("#{key}=")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/mutaconf.rb
ADDED
data/mutaconf.gemspec
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "mutaconf"
|
8
|
+
s.version = "0.0.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["AlphaHydrae"]
|
12
|
+
s.date = "2013-04-14"
|
13
|
+
s.description = "Create simple DSLs and read configuration from hashes or objects."
|
14
|
+
s.email = "hydrae.alpha@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rspec",
|
21
|
+
".ruby-gemset",
|
22
|
+
".ruby-version",
|
23
|
+
".screenrc",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/mutaconf.rb",
|
31
|
+
"lib/mutaconf/dsl.rb",
|
32
|
+
"lib/mutaconf/errors.rb",
|
33
|
+
"lib/mutaconf/target.rb",
|
34
|
+
"mutaconf.gemspec",
|
35
|
+
"spec/block_spec.rb",
|
36
|
+
"spec/fixtures/eval.rb",
|
37
|
+
"spec/helper.rb",
|
38
|
+
"spec/source_spec.rb",
|
39
|
+
"spec/subclass_spec.rb",
|
40
|
+
"spec/target_spec.rb",
|
41
|
+
"spec/version_spec.rb"
|
42
|
+
]
|
43
|
+
s.homepage = "http://github.com/AlphaHydrae/mutaconf"
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = "2.0.3"
|
47
|
+
s.summary = "Configuration utilities."
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
s.specification_version = 4
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<gemcutter>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<gem-release>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<rake-version>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<gemcutter>, [">= 0"])
|
67
|
+
s.add_dependency(%q<gem-release>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rake-version>, [">= 0"])
|
69
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
75
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
76
|
+
s.add_dependency(%q<gemcutter>, [">= 0"])
|
77
|
+
s.add_dependency(%q<gem-release>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rake-version>, [">= 0"])
|
79
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
data/spec/block_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Mutaconf::DSL do
|
4
|
+
|
5
|
+
let(:target){ {} }
|
6
|
+
let(:dsl){ Mutaconf::DSL.new options }
|
7
|
+
let(:options){ { target: target } }
|
8
|
+
|
9
|
+
it "should configure properties with instance evaluation" do
|
10
|
+
result = dsl.configure do
|
11
|
+
a 'b'
|
12
|
+
c 'd'
|
13
|
+
end
|
14
|
+
expected = { a: 'b', c: 'd' }
|
15
|
+
result.should be(target)
|
16
|
+
target.should == expected
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should configure properties with a configuration object" do
|
20
|
+
result = dsl.configure do |config|
|
21
|
+
config.e = 'f'
|
22
|
+
config.g = 'h'
|
23
|
+
config.i = 'j'
|
24
|
+
end
|
25
|
+
expected = { e: 'f', g: 'h', i: 'j' }
|
26
|
+
result.should be(target)
|
27
|
+
target.should == expected
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with restricted keys" do
|
31
|
+
|
32
|
+
let(:options){ { target: target, keys: [ :a ] } }
|
33
|
+
|
34
|
+
it "should raise a key error for a unknown key with instance evaluation" do
|
35
|
+
lambda{ dsl.configure{ b 'c' } }.should raise_error(Mutaconf::KeyError, /'b'/)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise a key error for an unknown key with a configuration object" do
|
39
|
+
lambda{ dsl.configure{ |config| config.b = 'c' } }.should raise_error(Mutaconf::KeyError, /'b'/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with restricted keys in lenient mode" do
|
44
|
+
|
45
|
+
let(:options){ { target: target, keys: [ :a, :e ], lenient: true } }
|
46
|
+
|
47
|
+
it "should configure restricted properties with instance evaluation" do
|
48
|
+
result = dsl.configure do
|
49
|
+
a 'b'
|
50
|
+
c 'd'
|
51
|
+
e 'f'
|
52
|
+
g 'h'
|
53
|
+
end
|
54
|
+
expected = { a: 'b', e: 'f' }
|
55
|
+
result.should be(target)
|
56
|
+
target.should == expected
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should configure restricted properties with a configuration object" do
|
60
|
+
result = dsl.configure do |config|
|
61
|
+
config.a = 'b'
|
62
|
+
config.c = 'd'
|
63
|
+
config.e = 'f'
|
64
|
+
config.g = 'h'
|
65
|
+
end
|
66
|
+
expected = { a: 'b', e: 'f' }
|
67
|
+
result.should be(target)
|
68
|
+
target.should == expected
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'simplecov'
|
13
|
+
SimpleCov.start
|
14
|
+
|
15
|
+
require 'rspec'
|
16
|
+
require 'mutaconf'
|
data/spec/source_spec.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe Mutaconf::DSL do
|
5
|
+
|
6
|
+
let(:target){ {} }
|
7
|
+
let(:dsl){ Mutaconf::DSL.new options }
|
8
|
+
let(:options){ { target: target } }
|
9
|
+
|
10
|
+
it "should configure properties from a hash source" do
|
11
|
+
result = dsl.configure a: 'b', c: 'd'
|
12
|
+
expected = { a: 'b', c: 'd' }
|
13
|
+
result.should be(target)
|
14
|
+
target.should == expected
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should configure properties from a file with instance evaluation" do
|
18
|
+
result = dsl.configure fixture(:eval)
|
19
|
+
expected = { a: 'b', c: 'd', e: 'f', g: 'h' }
|
20
|
+
result.should be(target)
|
21
|
+
target.should == expected
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with restricted keys" do
|
25
|
+
|
26
|
+
let(:options){ { target: target, keys: [ :a ] } }
|
27
|
+
|
28
|
+
it "should raise a key error for an unknown key from a hash source" do
|
29
|
+
lambda{ dsl.configure b: 'c' }.should raise_error(Mutaconf::KeyError, /'b'/)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should raise a key error for an unknown key from a file with instance evaluation" do
|
33
|
+
lambda{ dsl.configure fixture(:eval) }.should raise_error(Mutaconf::KeyError, /'c'/)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with restricted keys in lenient mode" do
|
38
|
+
|
39
|
+
let(:options){ { target: target, keys: [ :a, :e ], lenient: true } }
|
40
|
+
|
41
|
+
it "should configure restricted properties from a hash source" do
|
42
|
+
result = dsl.configure a: 'b', c: 'd', e: 'f', g: 'h'
|
43
|
+
expected = { a: 'b', e: 'f' }
|
44
|
+
result.should be(target)
|
45
|
+
target.should == expected
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should configure restricted properties from an object" do
|
49
|
+
result = dsl.configure OpenStruct.new(a: 'b', c: 'd', e: 'f', g: 'h')
|
50
|
+
expected = { a: 'b', e: 'f' }
|
51
|
+
result.should be(target)
|
52
|
+
target.should == expected
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should configure restricted properties from a file with instance evaluation" do
|
56
|
+
result = dsl.configure fixture(:eval)
|
57
|
+
expected = { a: 'b', e: 'f' }
|
58
|
+
result.should be(target)
|
59
|
+
target.should == expected
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def fixture name
|
64
|
+
File.join File.dirname(__FILE__), 'fixtures', "#{name}.rb"
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Mutaconf::DSL do
|
4
|
+
|
5
|
+
class CustomDSL < Mutaconf::DSL
|
6
|
+
attr_reader :value
|
7
|
+
|
8
|
+
def initialize options = {}
|
9
|
+
super options
|
10
|
+
@value = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def increase by
|
14
|
+
@value += by
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:target){ {} }
|
19
|
+
let(:dsl){ CustomDSL.new target: target }
|
20
|
+
|
21
|
+
it "should work when subclassed" do
|
22
|
+
result = dsl.configure do
|
23
|
+
a 'b'
|
24
|
+
c 'd'
|
25
|
+
increase 5
|
26
|
+
end
|
27
|
+
expected = { a: 'b', c: 'd' }
|
28
|
+
result.should be(target)
|
29
|
+
target.should == expected
|
30
|
+
dsl.value.should == 5
|
31
|
+
end
|
32
|
+
end
|
data/spec/target_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Mutaconf::Target do
|
4
|
+
|
5
|
+
subject{ Mutaconf::Target.new target }
|
6
|
+
|
7
|
+
context "with a hash" do
|
8
|
+
|
9
|
+
let(:target){ { a: 'z' } }
|
10
|
+
|
11
|
+
it "should set values" do
|
12
|
+
subject.set :a, 'b'
|
13
|
+
subject.set :c, 'd'
|
14
|
+
target.should == { a: 'b', c: 'd' }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should get values" do
|
18
|
+
subject.get(:a).should == 'z'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have all values" do
|
22
|
+
('a'..'z').each{ |key| subject.has?(key).should be_true }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with an open struct" do
|
27
|
+
|
28
|
+
let(:target){ OpenStruct.new a: 'z' }
|
29
|
+
|
30
|
+
it "should set values" do
|
31
|
+
subject.set :a, 'b'
|
32
|
+
subject.set :c, 'd'
|
33
|
+
target.a.should == 'b'
|
34
|
+
target.c.should == 'd'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get values" do
|
38
|
+
subject.get(:a).should == 'z'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have all values" do
|
42
|
+
('a'..'z').each{ |key| subject.has?(key).should be_true }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with an object" do
|
47
|
+
|
48
|
+
let(:target) do
|
49
|
+
Class.new do
|
50
|
+
attr_accessor :a, :c
|
51
|
+
|
52
|
+
def initialize
|
53
|
+
@a = 'z'
|
54
|
+
end
|
55
|
+
end.new
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set values" do
|
59
|
+
subject.set :a, 'b'
|
60
|
+
subject.set :c, 'd'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should get values" do
|
64
|
+
subject.get(:a).should == 'z'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have values corresponding to its setters" do
|
68
|
+
subject.has?(:a).should be_true
|
69
|
+
subject.has?(:b).should be_false
|
70
|
+
subject.has?(:c).should be_true
|
71
|
+
('d'..'z').each{ |key| subject.has?(key).should be_false }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mutaconf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AlphaHydrae
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: jeweler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: gemcutter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: gem-release
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake-version
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Create simple DSLs and read configuration from hashes or objects.
|
126
|
+
email: hydrae.alpha@gmail.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files:
|
130
|
+
- LICENSE.txt
|
131
|
+
- README.md
|
132
|
+
files:
|
133
|
+
- .rspec
|
134
|
+
- .ruby-gemset
|
135
|
+
- .ruby-version
|
136
|
+
- .screenrc
|
137
|
+
- Gemfile
|
138
|
+
- Gemfile.lock
|
139
|
+
- LICENSE.txt
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- VERSION
|
143
|
+
- lib/mutaconf.rb
|
144
|
+
- lib/mutaconf/dsl.rb
|
145
|
+
- lib/mutaconf/errors.rb
|
146
|
+
- lib/mutaconf/target.rb
|
147
|
+
- mutaconf.gemspec
|
148
|
+
- spec/block_spec.rb
|
149
|
+
- spec/fixtures/eval.rb
|
150
|
+
- spec/helper.rb
|
151
|
+
- spec/source_spec.rb
|
152
|
+
- spec/subclass_spec.rb
|
153
|
+
- spec/target_spec.rb
|
154
|
+
- spec/version_spec.rb
|
155
|
+
homepage: http://github.com/AlphaHydrae/mutaconf
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - '>='
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.0.3
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: Configuration utilities.
|
179
|
+
test_files: []
|