config_fun 0.4.0
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/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +20 -0
- data/README.md +121 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/config_fun.gemspec +65 -0
- data/lib/config_fun.rb +75 -0
- data/spec/config_fun_spec.rb +149 -0
- data/spec/examples/config.rb +9 -0
- data/spec/examples/test.rb +9 -0
- data/spec/spec_helper.rb +3 -0
- metadata +156 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
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 "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.0"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem 'ruby-debug'
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
columnize (0.3.2)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.6.0)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
linecache (0.43)
|
12
|
+
rake (0.9.2)
|
13
|
+
rcov (0.9.9)
|
14
|
+
rspec (2.3.0)
|
15
|
+
rspec-core (~> 2.3.0)
|
16
|
+
rspec-expectations (~> 2.3.0)
|
17
|
+
rspec-mocks (~> 2.3.0)
|
18
|
+
rspec-core (2.3.1)
|
19
|
+
rspec-expectations (2.3.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.3.0)
|
22
|
+
ruby-debug (0.10.4)
|
23
|
+
columnize (>= 0.1)
|
24
|
+
ruby-debug-base (~> 0.10.4.0)
|
25
|
+
ruby-debug-base (0.10.4)
|
26
|
+
linecache (>= 0.3)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 1.0.0)
|
33
|
+
jeweler (~> 1.6.0)
|
34
|
+
rcov
|
35
|
+
rspec (~> 2.3.0)
|
36
|
+
ruby-debug
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Grant Ammons
|
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
@@ -0,0 +1,121 @@
|
|
1
|
+
## ConfigFun: Beautiful configurations for your projects and gems
|
2
|
+
|
3
|
+
http://github.com/gammons/config_fun
|
4
|
+
|
5
|
+
## DESCRIPTION:
|
6
|
+
|
7
|
+
Does your gem or project need the user to create or add configuration to it? Use ConfigFun to allow them to easily configure your gem, in a quick, terse and painless way!
|
8
|
+
|
9
|
+
## SYNOPSIS:
|
10
|
+
|
11
|
+
Adding ConfigFun to your project is super easy. Include the config_fun gem as part of your gem's dependencies.
|
12
|
+
|
13
|
+
Say you need to write a configuration that allows the user to add their account information, name, password, and some IMAP information.
|
14
|
+
With ConfigFun, the configuration could look like this:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
account "personal" do
|
18
|
+
name "grant"
|
19
|
+
password "bungalow"
|
20
|
+
|
21
|
+
imap do
|
22
|
+
server "imap.gmail.com"
|
23
|
+
ssl true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
To parse this configuration, you'd simply Say the following:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
config = ConfigFun.parse!(File.read(account_information_file))
|
32
|
+
```
|
33
|
+
|
34
|
+
..and the config variable would include a sweet hash of all the info the user provided!
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
config == {:account=> {:password => "bungalow", :imap => {:ssl => true, :server => "imap.gmail.com"}, :name => "grant"}}
|
38
|
+
```
|
39
|
+
|
40
|
+
## DETAILS:
|
41
|
+
|
42
|
+
|
43
|
+
### Arrays
|
44
|
+
|
45
|
+
if ConfigFun encounters a block twice within the same context, it will create an array.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
user do
|
49
|
+
room "123"
|
50
|
+
end
|
51
|
+
|
52
|
+
user do
|
53
|
+
room "456"
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
The resulting hash will have a `:user` key with an array of `:room`s as the value.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
{:user=>[{:room=>"123"}, {:room=>"456"}]}
|
61
|
+
```
|
62
|
+
|
63
|
+
### An important caveat
|
64
|
+
|
65
|
+
Blocks do not take any paramters. You may be tempted to do something like the following:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
user "Bob" do
|
69
|
+
room "123"
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
ConfigFun <strong>will not</strong> be able to parse this, because there is no equivalent hash it can boil down to.
|
74
|
+
|
75
|
+
The correct way to write the above code for ConfigFun is as follows:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
user do
|
79
|
+
name "bob"
|
80
|
+
room "123"
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
## REQUIREMENTS:
|
85
|
+
|
86
|
+
* None!
|
87
|
+
* Tested against ruby 1.8.7 and 1.9.2.
|
88
|
+
|
89
|
+
## INSTALL:
|
90
|
+
|
91
|
+
`gem install config_fun`
|
92
|
+
|
93
|
+
## AUTHORS:
|
94
|
+
|
95
|
+
* Grant Ammons
|
96
|
+
|
97
|
+
## LICENSE:
|
98
|
+
|
99
|
+
(The MIT License)
|
100
|
+
|
101
|
+
Copyright (c) 2010 Grant Ammons (grant@pipelinedealsco.com)
|
102
|
+
|
103
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
104
|
+
a copy of this software and associated documentation files (the
|
105
|
+
'Software'), to deal in the Software without restriction, including
|
106
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
107
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
108
|
+
permit persons to whom the Software is furnished to do so, subject to
|
109
|
+
the following conditions:
|
110
|
+
|
111
|
+
The above copyright notice and this permission notice shall be
|
112
|
+
included in all copies or substantial portions of the Software.
|
113
|
+
|
114
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
115
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
116
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
117
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
118
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
119
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
120
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
121
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
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 = "config_fun"
|
18
|
+
gem.homepage = "http://github.com/gammons/config_fun"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{A beautiful configuration maker for your gem or project}
|
21
|
+
gem.description = %Q{does your gem or project require configuration? This will make creating and parsing configuration a snap!}
|
22
|
+
gem.email = "grant@pipelinedealsco.com"
|
23
|
+
gem.authors = ["Grant Ammons"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "config_fun #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
data/config_fun.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
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 = %q{config_fun}
|
8
|
+
s.version = "0.4.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Grant Ammons"]
|
12
|
+
s.date = %q{2011-10-30}
|
13
|
+
s.description = %q{does your gem or project require configuration? This will make creating and parsing configuration a snap!}
|
14
|
+
s.email = %q{grant@pipelinedealsco.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"config_fun.gemspec",
|
29
|
+
"lib/config_fun.rb",
|
30
|
+
"spec/config_fun_spec.rb",
|
31
|
+
"spec/examples/config.rb",
|
32
|
+
"spec/examples/test.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/gammons/config_fun}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.4.2}
|
39
|
+
s.summary = %q{A beautiful configuration maker for your gem or project}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
48
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
52
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
54
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
56
|
+
end
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
61
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/config_fun.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
class ConfigFun
|
2
|
+
def self.parse!(str = nil, &block)
|
3
|
+
self.new(str, &block).__config
|
4
|
+
end
|
5
|
+
|
6
|
+
def initialize(str = nil, &block)
|
7
|
+
@__config = {}
|
8
|
+
@__cur = @__config
|
9
|
+
@__parents = []
|
10
|
+
instance_eval(&block) if block_given?
|
11
|
+
instance_eval(str) if str
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(m, *args, &block)
|
15
|
+
m = (m.to_s[1..(m.to_s.size - 1)]).to_sym if m.to_s.index("_") == 0
|
16
|
+
@__cur = @__parents.reduce(@__config) do |hash, cur|
|
17
|
+
hash[cur].class == Array ? hash[cur].last : hash[cur]
|
18
|
+
end
|
19
|
+
|
20
|
+
if m == :partial
|
21
|
+
read_partial(args)
|
22
|
+
elsif block_given?
|
23
|
+
$stderr << "Warning, ignoring args passed to a block. args = '#{args}'\n" if args.count >= 1
|
24
|
+
if (@__cur[m].nil? or @__cur[m].class == Hash) and (@__cur[m] == {} or not @__cur.keys.include?(m))
|
25
|
+
@__parents << m
|
26
|
+
@__cur[m] = {}
|
27
|
+
@__cur = @__cur[m]
|
28
|
+
instance_eval(&block)
|
29
|
+
@__parents.pop
|
30
|
+
elsif @__cur[m].class == Hash # we've seen this element before, so convert to array.
|
31
|
+
@__parents << m
|
32
|
+
if @__parents.count > 1
|
33
|
+
grandparent = @__parents[0..(@__parents.count - 2)]
|
34
|
+
parent = @__parents[@__parents.count - 1]
|
35
|
+
|
36
|
+
val = @__parents[0..(@__parents.count - 2)].reduce(@__config) do |hash, cur|
|
37
|
+
hash[cur].class == Array ? hash[cur].last : hash[cur]
|
38
|
+
end[parent]
|
39
|
+
|
40
|
+
@__parents[0..(@__parents.count - 2)].reduce(@__config) do |hash, cur|
|
41
|
+
hash[cur].class == Array ? hash[cur].last : hash[cur]
|
42
|
+
end[parent] = [val]
|
43
|
+
|
44
|
+
@__cur = @__parents[0..(@__parents.count - 2)].reduce(@__config) do |hash, cur|
|
45
|
+
hash[cur].class == Array ? hash[cur].last : hash[cur]
|
46
|
+
end[parent]
|
47
|
+
else
|
48
|
+
# case where we are the first item
|
49
|
+
@__config[m] = [@__config[m]]
|
50
|
+
@__cur = @__config[m]
|
51
|
+
end
|
52
|
+
|
53
|
+
@__cur << {}
|
54
|
+
instance_eval(&block)
|
55
|
+
@__parents.pop
|
56
|
+
elsif @__cur[m].class == Array # already an array so just append our new element
|
57
|
+
@__parents << m
|
58
|
+
@__cur[m] << {}
|
59
|
+
@__cur = @__cur[m].last
|
60
|
+
instance_eval(&block)
|
61
|
+
@__parents.pop
|
62
|
+
end
|
63
|
+
else
|
64
|
+
if @__cur.class == Array
|
65
|
+
@__cur.last[m] = args.first
|
66
|
+
else
|
67
|
+
@__cur[m] = args.first
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def __config
|
73
|
+
@__config
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'config_fun'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "config_fun" do
|
5
|
+
context "dsl" do
|
6
|
+
it "should be able to use reserved words with an underscore" do
|
7
|
+
struct = ConfigFun.parse! do
|
8
|
+
_id 1
|
9
|
+
_def 'dingle'
|
10
|
+
_class 'bargle'
|
11
|
+
end
|
12
|
+
struct.should == {:class=>"bargle", :def=>"dingle", :id=>1}
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to nest hashes within hashes" do
|
16
|
+
struct = ConfigFun.parse! do
|
17
|
+
@person = "bob"
|
18
|
+
entries do
|
19
|
+
person do
|
20
|
+
name @person
|
21
|
+
height "5 feet"
|
22
|
+
end
|
23
|
+
shirt "green"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
struct.should == {:entries=>{:person=>{:height=>"5 feet", :name=>"bob"}, :shirt=>"green"}}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should convert multiple entries of the same hash key to an array" do
|
30
|
+
struct = ConfigFun.parse! do
|
31
|
+
entries do
|
32
|
+
dingle do
|
33
|
+
harble "barble"
|
34
|
+
end
|
35
|
+
people do
|
36
|
+
person do
|
37
|
+
name "john"
|
38
|
+
height "5 feet"
|
39
|
+
end
|
40
|
+
person do
|
41
|
+
name "bob"
|
42
|
+
height "6 feet"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
shirt "green"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
struct.should == {:entries => {:dingle => {:harble => "barble"}, :people => {:person => [{:height=>"5 feet", :name=>"john" },{:height=>"6 feet", :name=>"bob"}]}, :shirt => 'green'}}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be able to handle 3 or more array entries" do
|
52
|
+
struct = ConfigFun.parse! do
|
53
|
+
@people = ["sue","bob","sally","jim"]
|
54
|
+
@people.each do |name|
|
55
|
+
person do
|
56
|
+
name name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
struct.should == {:person => [{:name => "sue"}, {:name=>"bob"}, {:name=>"sally"}, {:name=>"jim"}]}
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should see variables defined within its scope inside blocks" do
|
64
|
+
struct = ConfigFun.parse! do
|
65
|
+
@person = "bob"
|
66
|
+
entries do
|
67
|
+
person do
|
68
|
+
brain do
|
69
|
+
iq 100
|
70
|
+
end
|
71
|
+
name @person
|
72
|
+
height "5 feet"
|
73
|
+
end
|
74
|
+
shirt "green"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
struct.should == {:entries=>{:person=>{:height=>"5 feet", :name=>"bob", :brain=>{:iq=>100}}, :shirt=>"green"}}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should be able to handle arrays both outer and inner" do
|
81
|
+
struct = ConfigFun.parse! do
|
82
|
+
entries do
|
83
|
+
person do
|
84
|
+
name "bob"
|
85
|
+
colors do
|
86
|
+
red "red"
|
87
|
+
green "green"
|
88
|
+
end
|
89
|
+
colors do
|
90
|
+
brown "brown"
|
91
|
+
orange "orange"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
person do
|
96
|
+
name "jim"
|
97
|
+
colors do
|
98
|
+
blue "blue"
|
99
|
+
pink "pink"
|
100
|
+
end
|
101
|
+
colors do
|
102
|
+
purple "purple"
|
103
|
+
dark_brown "dark brown"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
struct.should == {:entries=>{:person=>[{:colors=>[{:red=>"red", :green=>"green"}, {:orange=>"orange", :brown=>"brown"}], :name=>"bob"}, {:colors=>[{:blue=>"blue", :pink=>"pink"}, {:purple=>"purple", :dark_brown=>"dark brown"}], :name=>"jim"}]}}
|
109
|
+
end
|
110
|
+
|
111
|
+
it "the base entry should be able to carry an array" do
|
112
|
+
struct = ConfigFun.parse! do
|
113
|
+
entry do
|
114
|
+
item "item1"
|
115
|
+
end
|
116
|
+
|
117
|
+
entry do
|
118
|
+
item "item2"
|
119
|
+
end
|
120
|
+
|
121
|
+
entry do
|
122
|
+
item "item3"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
struct.should == {:entry=>[{:item=>"item1"}, {:item=>"item2"}, {:item=>"item3"}]}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "real-world example use" do
|
130
|
+
let(:config) do
|
131
|
+
config = ConfigFun.parse!(File.read(File.expand_path(File.dirname(__FILE__) + '/examples/test.rb')))
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should parse a config correctly" do
|
135
|
+
expected = {:config=>{:user=>[{:name=>"bob"}, {:name=>"jim"}]}}
|
136
|
+
config.should == expected
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should warn the user if they pass arguments to a block" do
|
141
|
+
$stderr.should_receive("<<").with(/Warning, ignoring args passed to a block/)
|
142
|
+
struct = ConfigFun.parse! do
|
143
|
+
user "bob" do
|
144
|
+
room '123'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: config_fun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Grant Ammons
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-30 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
name: rspec
|
24
|
+
type: :development
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 0
|
35
|
+
version: 2.3.0
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
prerelease: false
|
39
|
+
name: bundler
|
40
|
+
type: :development
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 23
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
prerelease: false
|
55
|
+
name: jeweler
|
56
|
+
type: :development
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 15
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 6
|
66
|
+
- 0
|
67
|
+
version: 1.6.0
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
prerelease: false
|
71
|
+
name: rcov
|
72
|
+
type: :development
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirement: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
85
|
+
name: ruby-debug
|
86
|
+
type: :development
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirement: *id005
|
97
|
+
description: does your gem or project require configuration? This will make creating and parsing configuration a snap!
|
98
|
+
email: grant@pipelinedealsco.com
|
99
|
+
executables: []
|
100
|
+
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
files:
|
107
|
+
- .document
|
108
|
+
- .rspec
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- VERSION
|
115
|
+
- config_fun.gemspec
|
116
|
+
- lib/config_fun.rb
|
117
|
+
- spec/config_fun_spec.rb
|
118
|
+
- spec/examples/config.rb
|
119
|
+
- spec/examples/test.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
has_rdoc: true
|
122
|
+
homepage: http://github.com/gammons/config_fun
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.4.2
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: A beautiful configuration maker for your gem or project
|
155
|
+
test_files: []
|
156
|
+
|