TwP-loquacious 1.0.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/History.txt +4 -0
- data/README.rdoc +234 -0
- data/Rakefile +43 -0
- data/examples/gutters.rb +30 -0
- data/examples/nested.rb +47 -0
- data/examples/simple.rb +20 -0
- data/lib/loquacious.rb +75 -0
- data/lib/loquacious/configuration.rb +197 -0
- data/lib/loquacious/configuration/help.rb +151 -0
- data/lib/loquacious/configuration/iterator.rb +152 -0
- data/lib/loquacious/core_ext/string.rb +75 -0
- data/loquacious.gemspec +37 -0
- data/spec/configuration_spec.rb +152 -0
- data/spec/help_spec.rb +323 -0
- data/spec/iterator_spec.rb +62 -0
- data/spec/loquacious_spec.rb +22 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/string_spec.rb +53 -0
- metadata +92 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
describe Loquacious::Configuration::Iterator do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@config = Loquacious.configuration_for 'specs'
|
8
|
+
@iterator = Loquacious::Configuration::Iterator.new(@config)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should find a particular attribute' do
|
12
|
+
node = @iterator.find 'first'
|
13
|
+
node.name.should == 'first'
|
14
|
+
node.key.should == :first
|
15
|
+
node.desc.should == 'foo method'
|
16
|
+
node.obj.should == 'foo'
|
17
|
+
node.config?.should == false
|
18
|
+
|
19
|
+
node = @iterator.find :third
|
20
|
+
node.name.should == 'third'
|
21
|
+
node.key.should == :third
|
22
|
+
node.desc.should == 'the third group'
|
23
|
+
node.config?.should == true
|
24
|
+
|
25
|
+
node = @iterator.find('third.answer')
|
26
|
+
node.name.should == 'third.answer'
|
27
|
+
node.key.should == :answer
|
28
|
+
node.desc.should == 'life the universe and everything'
|
29
|
+
node.obj.should == 42
|
30
|
+
node.config?.should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return nil for unknown attributes' do
|
34
|
+
@iterator.find('last').should be_nil
|
35
|
+
@iterator.find('last.first.none').should be_nil
|
36
|
+
@iterator.find('third.none').should be_nil
|
37
|
+
@iterator.find(:foo).should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should iterate over all attributes' do
|
41
|
+
ary = Array.new
|
42
|
+
@iterator.each {|n| ary << n.name}
|
43
|
+
|
44
|
+
ary.should == %w{first second third third.answer third.question}
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should iterate over nested attributes if given' do
|
48
|
+
ary = Array.new
|
49
|
+
@iterator.each('third') {|n| ary << n.name}
|
50
|
+
ary.should == %w{third third.answer third.question}
|
51
|
+
|
52
|
+
ary.clear
|
53
|
+
@iterator.each('first') {|n| ary << n.name}
|
54
|
+
ary.should == %w{first}
|
55
|
+
|
56
|
+
ary.clear
|
57
|
+
@iterator.each('not_here') {|n| ary << n.name}
|
58
|
+
ary.should be_empty
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# EOF
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
describe Loquacious do
|
5
|
+
before(:all) do
|
6
|
+
@root_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should report a version number" do
|
10
|
+
Loquacious.version.should match(%r/\d+\.\d+\.\d+/)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "finds things releative to 'lib'" do
|
14
|
+
Loquacious.libpath(%w[loquacious config.rb]).should == File.join(@root_dir, %w[lib loquacious config.rb])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "finds things releative to 'root'" do
|
18
|
+
Loquacious.path('Rakefile').should == File.join(@root_dir, 'Rakefile')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# EOF
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format specdoc
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(
|
3
|
+
File.join(File.dirname(__FILE__), %w[.. lib loquacious]))
|
4
|
+
|
5
|
+
Spec::Runner.configure do |config|
|
6
|
+
# == Mock Framework
|
7
|
+
#
|
8
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
9
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
10
|
+
#
|
11
|
+
# config.mock_with :mocha
|
12
|
+
# config.mock_with :flexmock
|
13
|
+
# config.mock_with :rr
|
14
|
+
|
15
|
+
config.before :each do
|
16
|
+
table = Loquacious::Configuration.instance_variable_get(:@table)
|
17
|
+
table.clear
|
18
|
+
|
19
|
+
Loquacious.configuration_for('specs') do
|
20
|
+
first 'foo', :desc => 'foo method'
|
21
|
+
second 'bar', :desc => 'bar method'
|
22
|
+
|
23
|
+
desc 'the third group'
|
24
|
+
third {
|
25
|
+
answer 42, :desc => 'life the universe and everything'
|
26
|
+
question :symbol, :desc => 'perhaps you do not understand'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class StringIO
|
33
|
+
alias :_readline :readline
|
34
|
+
def readline
|
35
|
+
@pos ||= 0
|
36
|
+
seek @pos
|
37
|
+
line = _readline
|
38
|
+
@pos = tell
|
39
|
+
return line
|
40
|
+
rescue EOFError
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def clear
|
45
|
+
@pos = 0
|
46
|
+
seek 0
|
47
|
+
truncate 0
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
@pos = tell
|
52
|
+
seek 0
|
53
|
+
str = read
|
54
|
+
seek @pos
|
55
|
+
return str
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# EOF
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
3
|
+
|
4
|
+
describe String do
|
5
|
+
|
6
|
+
it "reduces to a size by replacing characters from the middle" do
|
7
|
+
"this is a longish string".reduce(10).should == "this...ing"
|
8
|
+
"this is a longish string".reduce(15).should == "this i...string"
|
9
|
+
"this is a longish string".reduce(24).should == "this is a longish string"
|
10
|
+
|
11
|
+
"this is a longish string".reduce(10, '--').should == "this--ring"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "indents by a given number of spaces" do
|
15
|
+
"hello".indent(2).should == " hello"
|
16
|
+
"hello\nworld".indent(4).should == " hello\n world"
|
17
|
+
" a\nslightly\n longer\n string\n".indent(2).should == " a\n slightly\n longer\n string\n "
|
18
|
+
end
|
19
|
+
|
20
|
+
it "indents using a leader string" do
|
21
|
+
"hello".indent("foo ").should == "foo hello"
|
22
|
+
"hello\nworld".indent("...").should == "...hello\n...world"
|
23
|
+
" a\nslightly\n longer\n string\n".indent("#").should == "# a\n#slightly\n# longer\n# string\n#"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "removes a leading gutter from all lines" do
|
27
|
+
str = " | foo"
|
28
|
+
result = str.gutter!
|
29
|
+
result.should == " foo"
|
30
|
+
result.should equal(str)
|
31
|
+
|
32
|
+
str = <<-STRING
|
33
|
+
| And this is where gutters really shine!
|
34
|
+
| HERE DOCS!!
|
35
|
+
||they are the best
|
36
|
+
|
|
37
|
+
| You can indent stuff nicely and all that
|
38
|
+
|all done now
|
39
|
+
STRING
|
40
|
+
|
41
|
+
str.gutter!
|
42
|
+
str.should == " And this is where gutters really shine!\n HERE DOCS!!\n|they are the best\n\n You can indent stuff nicely and all that\nall done now\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "creates a copy when removing a leading gutter" do
|
46
|
+
str = " | foo"
|
47
|
+
result = str.gutter
|
48
|
+
result.should == " foo"
|
49
|
+
result.should_not equal(str)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# EOF
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: TwP-loquacious
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tim Pease
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-04 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.1.12
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bones
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.4.2
|
34
|
+
version:
|
35
|
+
description: "Descriptive configuration files for Ruby written in Ruby. Loquacious provides a very open configuration system written in ruby and descriptions for each configuration attribute. The attributes and descriptions can be iterated over allowing for helpful information about those attributes to be displayed to the user. In the simple case we have a file something like Loquacious.configuration_for('app') { name 'value', :desc => \"Defines the name\" foo 'bar', :desc => \"FooBar\" id 42, :desc => \"Ara T. Howard\" } Which can be loaded via the standard Ruby loading mechanisms Kernel.load 'config/app.rb' The attributes and their descriptions can be printed by using a Help object help = Loquacious.help_for('app') help.show :values => true # show the values for the attributes, too Descriptions are optional, and configurations can be nested arbitrarily deep. Loquacious.configuration_for('nested') { desc \"The outermost level\" a { desc \"One more level in\" b { desc \"Finally, a real value\" c 'value' } } } config = Loquacious.configuration_for('nested') p config.a.b.c #=> \"value\" And as you can see, descriptions can either be given inline after the value or they can appear above the attribute and value on their own line."
|
36
|
+
email: tim.pease@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- History.txt
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- History.txt
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- examples/gutters.rb
|
49
|
+
- examples/nested.rb
|
50
|
+
- examples/simple.rb
|
51
|
+
- lib/loquacious.rb
|
52
|
+
- lib/loquacious/configuration.rb
|
53
|
+
- lib/loquacious/configuration/help.rb
|
54
|
+
- lib/loquacious/configuration/iterator.rb
|
55
|
+
- lib/loquacious/core_ext/string.rb
|
56
|
+
- loquacious.gemspec
|
57
|
+
- spec/configuration_spec.rb
|
58
|
+
- spec/help_spec.rb
|
59
|
+
- spec/iterator_spec.rb
|
60
|
+
- spec/loquacious_spec.rb
|
61
|
+
- spec/spec.opts
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- spec/string_spec.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://codeforpeople.rubyforge.org/loquacious
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.rdoc
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: codeforpeople
|
87
|
+
rubygems_version: 1.2.0
|
88
|
+
signing_key:
|
89
|
+
specification_version: 2
|
90
|
+
summary: Descriptive configuration files for Ruby written in Ruby
|
91
|
+
test_files: []
|
92
|
+
|