loquacious 1.6.4 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/lib/loquacious/configuration.rb +7 -6
- data/lib/loquacious/undefined.rb +5 -5
- data/lib/loquacious.rb +39 -1
- data/spec/loquacious_spec.rb +55 -1
- data/version.txt +1 -1
- metadata +12 -5
data/History.txt
CHANGED
@@ -47,19 +47,19 @@ module Loquacious
|
|
47
47
|
alias :help :help_for
|
48
48
|
end
|
49
49
|
|
50
|
-
Keepers = %r/^__|^object_id$|^initialize$|^\w+\?$/
|
51
50
|
instance_methods(true).each do |m|
|
52
|
-
next if m[
|
51
|
+
next if m[::Loquacious::KEEPERS]
|
53
52
|
undef_method m
|
54
53
|
end
|
55
54
|
Kernel.methods.each do |m|
|
56
|
-
next if m[
|
55
|
+
next if m[::Loquacious::KEEPERS]
|
57
56
|
module_eval <<-CODE
|
58
57
|
def #{m}( *args, &block )
|
59
58
|
self.method_missing('#{m}', *args, &block)
|
60
59
|
end
|
61
60
|
CODE
|
62
61
|
end
|
62
|
+
undef_method :method_missing rescue nil
|
63
63
|
|
64
64
|
# Accessor for the description hash.
|
65
65
|
attr_reader :__desc
|
@@ -185,21 +185,22 @@ module Loquacious
|
|
185
185
|
alias :__instance_eval :instance_eval
|
186
186
|
|
187
187
|
instance_methods(true).each do |m|
|
188
|
-
next if m[
|
188
|
+
next if m[::Loquacious::KEEPERS]
|
189
189
|
undef_method m
|
190
190
|
end
|
191
191
|
private_instance_methods(true).each do |m|
|
192
|
-
next if m[
|
192
|
+
next if m[::Loquacious::KEEPERS]
|
193
193
|
undef_method m
|
194
194
|
end
|
195
195
|
Kernel.methods.each do |m|
|
196
|
-
next if m[
|
196
|
+
next if m[::Loquacious::KEEPERS]
|
197
197
|
module_eval <<-CODE
|
198
198
|
def #{m}( *args, &block )
|
199
199
|
self.method_missing('#{m}', *args, &block)
|
200
200
|
end
|
201
201
|
CODE
|
202
202
|
end
|
203
|
+
undef_method :method_missing rescue nil
|
203
204
|
|
204
205
|
# Create a new DSL and evaluate the given _block_ in the context of
|
205
206
|
# the DSL. Returns a newly created configuration object.
|
data/lib/loquacious/undefined.rb
CHANGED
@@ -12,23 +12,23 @@ module Loquacious
|
|
12
12
|
#
|
13
13
|
class Undefined
|
14
14
|
|
15
|
-
Keepers = %r/^__|^object_id$|^initialize$|^call$|^\w+\?$/
|
16
15
|
instance_methods(true).each do |m|
|
17
|
-
next if m[
|
16
|
+
next if m[::Loquacious::KEEPERS]
|
18
17
|
undef_method m
|
19
18
|
end
|
20
19
|
private_instance_methods(true).each do |m|
|
21
|
-
next if m[
|
20
|
+
next if m[::Loquacious::KEEPERS]
|
22
21
|
undef_method m
|
23
22
|
end
|
24
23
|
Kernel.methods.each do |m|
|
25
|
-
next if m[
|
24
|
+
next if m[::Loquacious::KEEPERS]
|
26
25
|
module_eval <<-CODE
|
27
26
|
def #{m}( *args, &block )
|
28
27
|
self.method_missing('#{m}', *args, &block)
|
29
28
|
end
|
30
29
|
CODE
|
31
30
|
end
|
31
|
+
undef_method :method_missing rescue nil
|
32
32
|
|
33
33
|
@io = $stderr
|
34
34
|
@first_time = true
|
@@ -84,7 +84,7 @@ information about the undefined properties.
|
|
84
84
|
def method_missing( method, *args, &block )
|
85
85
|
key = @key.dup << method.to_s
|
86
86
|
Undefined.warn key
|
87
|
-
return Undefined.new
|
87
|
+
return Undefined.new(key)
|
88
88
|
end
|
89
89
|
|
90
90
|
end # class Undefined
|
data/lib/loquacious.rb
CHANGED
@@ -4,6 +4,9 @@ module Loquacious
|
|
4
4
|
# :stopdoc:
|
5
5
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
6
6
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
7
|
+
KEEPERS = (RUBY_PLATFORM == 'java') ?
|
8
|
+
%r/^__|^object_id$|^initialize$|^singleton_method_added$|^\w+\?$/ :
|
9
|
+
%r/^__|^object_id$|^initialize$|^\w+\?$/
|
7
10
|
# :startdoc:
|
8
11
|
|
9
12
|
class << self
|
@@ -78,6 +81,7 @@ module Loquacious
|
|
78
81
|
#
|
79
82
|
# Loquacious.remove :gem # courtesy of rubygems
|
80
83
|
# Loquacious.remove :test, :file # courtesy of rake
|
84
|
+
# Loquacious.remove :main # courtesy of main
|
81
85
|
#
|
82
86
|
def remove( *args )
|
83
87
|
args.each { |name|
|
@@ -91,6 +95,41 @@ module Loquacious
|
|
91
95
|
}
|
92
96
|
end
|
93
97
|
|
98
|
+
# A helper method that will create a deep copy of a given Configuration
|
99
|
+
# object. This method accepts either a Configuration instance or a name
|
100
|
+
# that can be used to lookup the Configuration instance (via the
|
101
|
+
# "Loquacious.configuration_for" method).
|
102
|
+
#
|
103
|
+
# Loquacious.copy(config)
|
104
|
+
# Loquacious.copy('name')
|
105
|
+
#
|
106
|
+
# Optionally a block can be given. It will be used to modify the returned
|
107
|
+
# copy with the given values. The Configuration object being copied is
|
108
|
+
# never modified by this method.
|
109
|
+
#
|
110
|
+
# Loquacious.copy(config) {
|
111
|
+
# foo 'bar'
|
112
|
+
# baz 'buz'
|
113
|
+
# }
|
114
|
+
#
|
115
|
+
def copy( config, &block )
|
116
|
+
config = Configuration.for(config) unless config.instance_of? Configuration
|
117
|
+
return unless config
|
118
|
+
|
119
|
+
rv = Configuration.new
|
120
|
+
rv.merge!(config)
|
121
|
+
|
122
|
+
# deep copy
|
123
|
+
rv.__desc.each do |key,desc|
|
124
|
+
value = rv.__send(key)
|
125
|
+
next unless value.instance_of? Configuration
|
126
|
+
rv.__send("#{key}=", ::Loquacious.copy(value))
|
127
|
+
end
|
128
|
+
|
129
|
+
rv.merge!(Configuration::DSL.evaluate(&block)) if block
|
130
|
+
rv
|
131
|
+
end
|
132
|
+
|
94
133
|
end # class << self
|
95
134
|
end # module Loquacious
|
96
135
|
|
@@ -102,4 +141,3 @@ Loquacious.libpath {
|
|
102
141
|
require 'loquacious/configuration/help'
|
103
142
|
}
|
104
143
|
|
105
|
-
# EOF
|
data/spec/loquacious_spec.rb
CHANGED
@@ -17,6 +17,60 @@ describe Loquacious do
|
|
17
17
|
it "finds things releative to 'root'" do
|
18
18
|
Loquacious.path('Rakefile').should == File.join(@root_dir, 'Rakefile')
|
19
19
|
end
|
20
|
+
|
21
|
+
describe "when copying configuration objects" do
|
22
|
+
it "creates a deep copy" do
|
23
|
+
obj = Loquacious::Configuration.new {
|
24
|
+
first 'foo'
|
25
|
+
second {
|
26
|
+
bar 'baz'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
copy = Loquacious.copy obj
|
31
|
+
copy.first = 'foobar'
|
32
|
+
copy.second.bar = 'buz'
|
33
|
+
|
34
|
+
obj.first.should == 'foo'
|
35
|
+
obj.second.bar.should == 'baz'
|
36
|
+
copy.first.should == 'foobar'
|
37
|
+
copy.second.bar.should == 'buz'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "looks up a configuration object by name" do
|
41
|
+
Loquacious.config_for('by name') {
|
42
|
+
first 'foo'
|
43
|
+
second {
|
44
|
+
bar 'baz'
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
copy = Loquacious.copy('by name')
|
49
|
+
copy.first.should == 'foo'
|
50
|
+
copy.second.bar.should == 'baz'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns nil when a configuration object cannot be found" do
|
54
|
+
Loquacious.copy('does not exist').should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "overrides options with a block" do
|
58
|
+
Loquacious.config_for('another by name') {
|
59
|
+
first 'foo'
|
60
|
+
second {
|
61
|
+
bar 'baz'
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
copy = Loquacious.copy('another by name') {
|
66
|
+
second { bar 'foobar' }
|
67
|
+
third "hey I'm new"
|
68
|
+
}
|
69
|
+
|
70
|
+
copy.first.should == 'foo'
|
71
|
+
copy.second.bar.should == 'foobar'
|
72
|
+
copy.third.should == "hey I'm new"
|
73
|
+
end
|
74
|
+
end
|
20
75
|
end
|
21
76
|
|
22
|
-
# EOF
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.7.0
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loquacious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 1.7.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Tim Pease
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-16 00:00:00 -06:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 3
|
@@ -116,23 +119,27 @@ rdoc_options:
|
|
116
119
|
require_paths:
|
117
120
|
- lib
|
118
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
119
123
|
requirements:
|
120
124
|
- - ">="
|
121
125
|
- !ruby/object:Gem::Version
|
126
|
+
hash: 3
|
122
127
|
segments:
|
123
128
|
- 0
|
124
129
|
version: "0"
|
125
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
126
132
|
requirements:
|
127
133
|
- - ">="
|
128
134
|
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
129
136
|
segments:
|
130
137
|
- 0
|
131
138
|
version: "0"
|
132
139
|
requirements: []
|
133
140
|
|
134
141
|
rubyforge_project: codeforpeople
|
135
|
-
rubygems_version: 1.3.
|
142
|
+
rubygems_version: 1.3.7
|
136
143
|
signing_key:
|
137
144
|
specification_version: 3
|
138
145
|
summary: Descriptive configuration files for Ruby written in Ruby
|