TwP-loquacious 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,11 @@
1
+ == 1.1.0 / 2009-04-05
2
+
3
+ * 1 minor enhancement
4
+ - Added hash accessor methods for configuration attributes
5
+ * 1 bug fix
6
+ - Hash values were not being handeld properly by the DSL
7
+
1
8
  == 1.0.0 / 2009-04-04
2
9
 
3
10
  * 1 major enhancement
4
- * Birthday!
11
+ - Birthday!
data/Rakefile CHANGED
@@ -26,6 +26,7 @@ PROJ.version = Loquacious::VERSION
26
26
  PROJ.readme_file = 'README.rdoc'
27
27
  PROJ.ignore_file = '.gitignore'
28
28
  PROJ.rubyforge.name = 'codeforpeople'
29
+ PROJ.rdoc.remote_dir = 'loquacious'
29
30
 
30
31
  PROJ.spec.opts << '--color'
31
32
  PROJ.ruby_opts = %w[-W0]
@@ -131,6 +131,28 @@ module Loquacious
131
131
  self
132
132
  end
133
133
 
134
+ # Provides hash accessor notation for configuration values.
135
+ #
136
+ # config = Configuration.for('app') {
137
+ # port 1234
138
+ # }
139
+ # config[:port] #=> 1234
140
+ # config.port #=> 1234
141
+ #
142
+ def []( key )
143
+ self.__send__(key)
144
+ end
145
+
146
+ # Provides hash accessor notation for configuration values.
147
+ #
148
+ # config = Configuration.for('app')
149
+ # config[:port] = 8808
150
+ # config.port #=> 8808
151
+ #
152
+ def []=( key, value )
153
+ self.__send__(key, value)
154
+ end
155
+
134
156
  # Implementation of a doman specific language for creating configuration
135
157
  # objects. Blocks of code are evaluted by the DSL which returns a new
136
158
  # configuration object.
@@ -170,8 +192,10 @@ module Loquacious
170
192
  def method_missing( method, *args, &block )
171
193
  m = method.to_s.delete('=').to_sym
172
194
 
173
- opts = args.last.instance_of?(Hash) ? args.pop : {}
174
- self.desc(opts[:desc]) if opts.has_key? :desc
195
+ if args.length > 1
196
+ opts = args.last.instance_of?(Hash) ? args.pop : {}
197
+ self.desc(opts[:desc]) if opts.has_key? :desc
198
+ end
175
199
 
176
200
  __config.__send__(m, *args, &block)
177
201
  __config.__desc[m] = @description
data/lib/loquacious.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  module Loquacious
3
3
 
4
4
  # :stopdoc:
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
7
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
8
  # :startdoc:
data/loquacious.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{loquacious}
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Tim Pease"]
9
- s.date = %q{2009-04-04}
9
+ s.date = %q{2009-04-05}
10
10
  s.description = %q{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.}
11
11
  s.email = %q{tim.pease@gmail.com}
12
12
  s.extra_rdoc_files = ["History.txt", "README.rdoc"]
@@ -24,14 +24,14 @@ Gem::Specification.new do |s|
24
24
  s.specification_version = 2
25
25
 
26
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- s.add_runtime_dependency(%q<rspec>, [">= 1.1.12"])
28
- s.add_development_dependency(%q<bones>, [">= 2.4.2"])
27
+ s.add_runtime_dependency(%q<rspec>, [">= 1.2.2"])
28
+ s.add_development_dependency(%q<bones>, [">= 2.5.0"])
29
29
  else
30
- s.add_dependency(%q<rspec>, [">= 1.1.12"])
31
- s.add_dependency(%q<bones>, [">= 2.4.2"])
30
+ s.add_dependency(%q<rspec>, [">= 1.2.2"])
31
+ s.add_dependency(%q<bones>, [">= 2.5.0"])
32
32
  end
33
33
  else
34
- s.add_dependency(%q<rspec>, [">= 1.1.12"])
35
- s.add_dependency(%q<bones>, [">= 2.4.2"])
34
+ s.add_dependency(%q<rspec>, [">= 1.2.2"])
35
+ s.add_dependency(%q<bones>, [">= 2.5.0"])
36
36
  end
37
37
  end
@@ -44,6 +44,33 @@ describe Loquacious::Configuration do
44
44
  @obj.__desc.should equal(h)
45
45
  end
46
46
 
47
+ it 'should allow attributes to be assigned hash values' do
48
+ cfg = Loquacious::Configuration.new {
49
+ hash({:one => 1})
50
+ }
51
+ cfg.hash.should == {:one => 1}
52
+ end
53
+
54
+ it 'should provide hash accessor notation for attributes' do
55
+ cfg = Loquacious::Configuration.new {
56
+ one 1
57
+ two 2
58
+ three 3
59
+ }
60
+
61
+ cfg['one'].should == 1
62
+ cfg[:two].should == 2
63
+ cfg['three'].should == 3
64
+
65
+ cfg[:four].should be_nil
66
+ cfg.four = 4
67
+ cfg[:four].should == 4
68
+
69
+ cfg[:five] = 5
70
+ cfg.five.should == 5
71
+ cfg[:five].should == 5
72
+ end
73
+
47
74
  # -----------------------------------------------------------------------
48
75
  describe 'when merging' do
49
76
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TwP-loquacious
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-04 00:00:00 -07:00
12
+ date: 2009-04-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.1.12
23
+ version: 1.2.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bones
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.4.2
33
+ version: 2.5.0
34
34
  version:
35
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
36
  email: tim.pease@gmail.com