parameters 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ === 0.1.8 / 2009-09-21
2
+
3
+ * Require Hoe >= 2.3.3.
4
+ * Require YARD >= 0.2.3.5.
5
+ * Require RSpec >= 1.2.8.
6
+ * Use 'hoe/signing' for signed RubyGems.
7
+ * Moved to YARD based documentation.
8
+ * Added YARD handlers for documenting parameter method calls.
9
+ * All specs pass on JRuby 1.3.1.
10
+
1
11
  === 0.1.7 / 2009-07-19
2
12
 
3
13
  * Renamed Parameters#initialize_parameters to
data/Manifest.txt CHANGED
@@ -15,6 +15,16 @@ lib/parameters/instance_param.rb
15
15
  lib/parameters/param.rb
16
16
  lib/parameters/parameters.rb
17
17
  lib/parameters/version.rb
18
+ lib/parameters/yard.rb
19
+ lib/parameters/yard/handlers.rb
20
+ lib/parameters/yard/handlers/ruby.rb
21
+ lib/parameters/yard/handlers/ruby/eval_block_handler.rb
22
+ lib/parameters/yard/handlers/ruby/metaclass_eval_handler.rb
23
+ lib/parameters/yard/handlers/ruby/parameter_handler.rb
24
+ lib/parameters/yard/handlers/ruby/legacy.rb
25
+ lib/parameters/yard/handlers/ruby/legacy/eval_block_handler.rb
26
+ lib/parameters/yard/handlers/ruby/legacy/metaclass_eval_handler.rb
27
+ lib/parameters/yard/handlers/ruby/legacy/parameter_handler.rb
18
28
  tasks/spec.rb
19
29
  spec/spec_helper.rb
20
30
  spec/classes/test_parameters.rb
data/README.txt CHANGED
@@ -17,6 +17,7 @@ have configurable default values.
17
17
  * Change default values of parameters.
18
18
  * Give descriptions to parameters.
19
19
  * Set parameters en-mass.
20
+ * Parse strings of the form +name=value+ into a Hash of parameters.
20
21
 
21
22
  == EXAMPLES:
22
23
 
@@ -36,22 +37,34 @@ have configurable default values.
36
37
 
37
38
  end
38
39
 
40
+ # Create an object with default values for all parameters
39
41
  oct = Octagon.new
40
42
  oct.x # => 0
41
43
  oct.y # => 0.5
42
44
  oct.opacity # => 0.25
43
45
 
46
+ # Create an object with the given parameter values.
44
47
  oct = Octagon.new(:radius => 10)
45
48
  oct.radius # => 10
46
49
  oct.opacity # => 0.7
47
50
 
51
+ # Set parameter values of a class
48
52
  Octagon.radius = 33
49
53
  Octagon.opacity = 0.3
50
54
 
55
+ # Create an object with parameter defaulte values inherited from the
56
+ # class parameters
51
57
  oct = Octagon.new
52
58
  oct.radius # => 33
53
59
  oct.opacity # => 0.3
54
60
 
61
+ # Parse user given name=value parameter strings
62
+ oct.params = Parameters::Parser.parse(ARGV)
63
+
64
+ == REQUIREMENTS:
65
+
66
+ * {YARD}[http://yard.soen.ca/] >= 0.2.3.5
67
+
55
68
  == INSTALL:
56
69
 
57
70
  $ sudo gem install parameters
data/Rakefile CHANGED
@@ -4,12 +4,21 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require 'hoe/signing'
6
6
  require './tasks/spec.rb'
7
- require './lib/parameters/version.rb'
7
+ require './tasks/yard.rb'
8
8
 
9
9
  Hoe.spec('parameters') do
10
10
  self.rubyforge_name = 'parameters'
11
11
  self.developer('Postmodern','postmodern.mod3@gmail.com')
12
12
  self.remote_rdoc_dir = '/'
13
+ self.extra_deps = [
14
+ ['yard', '>=0.2.3.5']
15
+ ]
16
+
17
+ self.extra_dev_deps = [
18
+ ['rspec', '>=1.2.8']
19
+ ]
20
+
21
+ self.spec_extras = {:has_rdoc => 'yard'}
13
22
  end
14
23
 
15
24
  # vim: syntax=Ruby
@@ -7,8 +7,16 @@ module Parameters
7
7
  attr_accessor :value
8
8
 
9
9
  #
10
- # Creates a new ClassParam object with the specified _name_,
11
- # given _description_ and _value_.
10
+ # Creates a new ClassParam object.
11
+ #
12
+ # @param [Symbol, String] name
13
+ # The name of the class parameter.
14
+ #
15
+ # @param [String, nil] description
16
+ # The description of the class parameter.
17
+ #
18
+ # @param [Object, nil] value
19
+ # The default value of the class parameter.
12
20
  #
13
21
  def initialize(name,description=nil,value=nil)
14
22
  super(name,description)
@@ -17,19 +25,21 @@ module Parameters
17
25
  end
18
26
 
19
27
  #
20
- # Returns the String representation of the class param.
28
+ # @return [String]
29
+ # The representation of the class param.
21
30
  #
22
31
  def to_s
23
- text = " #{@name}"
32
+ text = @name.to_s
24
33
 
25
34
  text << " [#{@value.inspect}]" if @value
26
- text << "\t\t#{@description}" if @description
35
+ text << "\t#{@description}" if @description
27
36
 
28
37
  return text
29
38
  end
30
39
 
31
40
  #
32
- # Inspects the class params value.
41
+ # @return [String]
42
+ # Inspection of the class params value.
33
43
  #
34
44
  def inspect
35
45
  @value.inspect
@@ -5,8 +5,17 @@ module Parameters
5
5
  attr_reader :object
6
6
 
7
7
  #
8
- # Creates a new InstanceParam object with the specified _object_ and
9
- # _name_, and the given _description_.
8
+ # Creates a new InstanceParam object.
9
+ #
10
+ # @param [Object] object
11
+ # The object containing the instance variable for the instance
12
+ # parameter.
13
+ #
14
+ # @param [Symbol, String] name
15
+ # The name of the instance parameter.
16
+ #
17
+ # @param [String, nil] description
18
+ # The description of the instance parameter.
10
19
  #
11
20
  def initialize(object,name,description=nil)
12
21
  super(name,description)
@@ -15,7 +24,8 @@ module Parameters
15
24
  end
16
25
 
17
26
  #
18
- # Returns the value of the instance param.
27
+ # @return
28
+ # The value of the instance param.
19
29
  #
20
30
  def value
21
31
  @object.instance_variable_get("@#{@name}".to_sym)
@@ -24,24 +34,32 @@ module Parameters
24
34
  #
25
35
  # Sets the value of the instance param.
26
36
  #
37
+ # @param [Object] value
38
+ # The new value of the instance param.
39
+ #
40
+ # @return [Object]
41
+ # The new value of the instance param.
42
+ #
27
43
  def value=(value)
28
44
  @object.instance_variable_set("@#{@name}".to_sym,value)
29
45
  end
30
46
 
31
47
  #
32
- # Returns a String representation of the instance param.
48
+ # @return [String]
49
+ # Representation of the instance param.
33
50
  #
34
51
  def to_s
35
- text = " #{@name}"
52
+ text = @name.to_s
36
53
 
37
54
  text << " [#{value.inspect}]" if value
38
- text << "\t\t#{@description}" if @description
55
+ text << "\t#{@description}" if @description
39
56
 
40
57
  return text
41
58
  end
42
59
 
43
60
  #
44
- # Inspects the instance params value.
61
+ # @return [String]
62
+ # Inspection of the instance params value.
45
63
  #
46
64
  def inspect
47
65
  value.inspect
@@ -8,8 +8,13 @@ module Parameters
8
8
  attr_reader :description
9
9
 
10
10
  #
11
- # Creates a new Param object with the specified _name_ and the given
12
- # _description_.
11
+ # Creates a new Param object.
12
+ #
13
+ # @param [Symbol, String] name
14
+ # The name of the parameter.
15
+ #
16
+ # @param [String, nil] description
17
+ # The description of the parameter.
13
18
  #
14
19
  def initialize(name,description=nil)
15
20
  @name = name.to_sym
@@ -5,19 +5,23 @@ require 'parameters/exceptions'
5
5
  require 'parameters/extensions/meta'
6
6
 
7
7
  module Parameters
8
- def self.included(base) # :nodoc:
8
+ def self.included(base)
9
9
  base.metaclass_eval do
10
10
  #
11
- # Returns the +Hash+ of parameters for the class.
11
+ # @return [Hash]
12
+ # Parameters for the class.
12
13
  #
13
14
  def params
14
15
  @params ||= {}
15
16
  end
16
17
 
17
18
  #
18
- # Sets the values of the class parameters described in the
19
- # _values_ +Hash+.
19
+ # Sets the values of the class parameters.
20
20
  #
21
+ # @param [Hash] values
22
+ # The names and new values to set the class params to.
23
+ #
24
+ # @example
21
25
  # Test.params = {:x => 5, :y => 2}
22
26
  # # => {:x=>5, :y=>2}
23
27
  #
@@ -34,15 +38,24 @@ module Parameters
34
38
  end
35
39
 
36
40
  #
37
- # Adds a new parameters with the specified _name_ and the given
38
- # _options_ to the Class.
41
+ # Adds a new parameters to the class.
42
+ #
43
+ # @param [Symbol, String] name
44
+ # The name of the new parameter.
45
+ #
46
+ # @param [Hash] options
47
+ # Additional options.
39
48
  #
40
- # _options_ may contain the following keys:
41
- # <tt>:description</tt>:: The description of the parameter.
42
- # <tt>:default</tt>:: The default value the parameter will have.
49
+ # @option options [String] :description
50
+ # The description for the new parameter.
43
51
  #
52
+ # @option options [Object, Proc] :default
53
+ # The default value for the new parameter.
54
+ #
55
+ # @example
44
56
  # parameter 'var'
45
57
  #
58
+ # @example
46
59
  # parameter 'var', :default => 3, :description => 'my variable'
47
60
  #
48
61
  def parameter(name,options={})
@@ -66,9 +79,16 @@ module Parameters
66
79
  end
67
80
 
68
81
  #
69
- # Returns the class parameter with the specified _name_. If no
70
- # such class parameter exists, a ParamNotFound exception will be
71
- # raised.
82
+ # Searches for the class parameter with the matching name.
83
+ #
84
+ # @param [Symbol, String] name
85
+ # The class parameter name to search for.
86
+ #
87
+ # @return [ClassParam]
88
+ # The class parameter with the matching _name_.
89
+ #
90
+ # @raise [ParamNotFound]
91
+ # No class parameter with the specified _name_ could be found.
72
92
  #
73
93
  def get_param(name)
74
94
  name = name.to_sym
@@ -85,8 +105,9 @@ module Parameters
85
105
  end
86
106
 
87
107
  #
88
- # Returns +true+ if a class parameters with the specified _name_
89
- # exists, returns +false+ otherwise.
108
+ # @return [Boolean]
109
+ # Specifies whether or not there is a class parameter with the
110
+ # specified _name_.
90
111
  #
91
112
  def has_param?(name)
92
113
  name = name.to_sym
@@ -101,8 +122,10 @@ module Parameters
101
122
  end
102
123
 
103
124
  #
104
- # Iterates over all class parameters, passing each one to the
105
- # specified _block_.
125
+ # Iterates over the parameters of the class and it's ancestors.
126
+ #
127
+ # @yield [param]
128
+ # The block that will be passed each class parameter.
106
129
  #
107
130
  def each_param(&block)
108
131
  ancestors.each do |ancestor|
@@ -115,38 +138,39 @@ module Parameters
115
138
  end
116
139
 
117
140
  #
118
- # Returns the description of the class parameters with the
119
- # specified _name_. If no such class parameter exists, a
120
- # ParamNotFound exception will be raised.
141
+ # Returns the description of the class parameters with a given name.
142
+ #
143
+ # @return [String]
144
+ # Description of the class parameter with the specified name.
145
+ #
146
+ # @raise [ParamNotFound]
147
+ # No class parameter with the specified name could be found.
121
148
  #
122
149
  def describe_param(name)
123
150
  get_param(name).description
124
151
  end
125
152
 
126
153
  #
127
- # Returns the value of the class parameters with the specified
128
- # _name_. If no such class parameter exists, a ParamNotFound
129
- # exception will be raised.
154
+ # Returns the value of the class parameters with a given name.
130
155
  #
131
- def param_value(name)
132
- get_param(name).value
133
- end
134
-
156
+ # @return [Object]
157
+ # Value of the class parameter with the specified name.
135
158
  #
136
- # Print the class parameters to the given _output_ stream.
159
+ # @raise [ParamNotFound]
160
+ # No class parameter with the specified name could be found.
137
161
  #
138
- def print_params(output=STDOUT)
139
- each_param do |param|
140
- output.puts param
141
- end
162
+ def param_value(name)
163
+ get_param(name).value
142
164
  end
143
165
  end
144
166
  end
145
167
 
146
168
  #
147
169
  # Initalizes the parameters of the object using the given
148
- # _values_, which can override the default values of
149
- # parameters.
170
+ # values, which can override the default values of parameters.
171
+ #
172
+ # @param [Hash] values
173
+ # The names and values to initialize the instance parameters to.
150
174
  #
151
175
  def initialize_params(values={})
152
176
  self.class.each_param do |param|
@@ -185,15 +209,27 @@ module Parameters
185
209
  end
186
210
 
187
211
  #
188
- # Adds a new parameters with the specified _name_ and the given
189
- # _options_ to the object.
212
+ # Adds a new parameter to the object.
213
+ #
214
+ # @param [Symbol, String] name
215
+ # The name for the new instance parameter.
216
+ #
217
+ # @param [Hash] options
218
+ # Additional options.
190
219
  #
191
- # _options_ may contain the following keys:
192
- # <tt>:description</tt>:: The description of the parameter.
193
- # <tt>:default</tt>:: The default value the parameter will have.
220
+ # @option options [String] :description
221
+ # The description for the new parameter.
194
222
  #
223
+ # @option options [Object, Proc] :default
224
+ # The default value for the new parameter.
225
+ #
226
+ # @return [InstanceParam]
227
+ # The newly created instance parameter.
228
+ #
229
+ # @example
195
230
  # obj.parameter('var')
196
231
  #
232
+ # @example
197
233
  # obj.parameter('var',:default => 3, :description => 'my variable')
198
234
  #
199
235
  def parameter(name,options={})
@@ -234,22 +270,28 @@ module Parameters
234
270
  end
235
271
 
236
272
  #
237
- # Returns a +Hash+ of the classes params.
273
+ # @return [Hash]
274
+ # The parameteres of the class and it's ancestors.
238
275
  #
239
276
  def class_params
240
277
  self.class.params
241
278
  end
242
279
 
243
280
  #
244
- # Returns a +Hash+ of the instance parameters.
281
+ # @return [Hash]
282
+ # The instance parameters of the object.
245
283
  #
246
284
  def params
247
285
  @params ||= {}
248
286
  end
249
287
 
250
288
  #
251
- # Sets the values of the parameters described in the _values_ +Hash+.
289
+ # Sets the values of existing parameters in the object.
290
+ #
291
+ # @param [Hash] values
292
+ # The names and values to set the instance parameters to.
252
293
  #
294
+ # @example
253
295
  # obj.params = {:x => 5, :y => 2}
254
296
  # # => {:x=>5, :y=>2}
255
297
  #
@@ -268,17 +310,21 @@ module Parameters
268
310
  end
269
311
 
270
312
  #
271
- # Iterates over each instance parameter, passing each one to the given
272
- # _block_.
313
+ # Iterates over each instance parameter in the object.
314
+ #
315
+ # @yield [param]
316
+ # The block that will be passed each instance parameter.
273
317
  #
274
318
  def each_param(&block)
275
319
  self.params.each_value(&block)
276
320
  end
277
321
 
278
322
  #
279
- # Returns +true+ if the a parameter with the specified _name_ exists,
280
- # returns +false+ otherwise.
323
+ # @return [Boolean]
324
+ # Specifies whether or not there is a instance parameter with the
325
+ # specified name.
281
326
  #
327
+ # @example
282
328
  # obj.has_param?('rhost') # => true
283
329
  #
284
330
  def has_param?(name)
@@ -286,9 +332,18 @@ module Parameters
286
332
  end
287
333
 
288
334
  #
289
- # Returns the parameter with the specified _name_. If no such parameter
290
- # exists, a ParamNotFound exception will be raised.
335
+ # Searches for the instance parameter with a specific name.
336
+ #
337
+ # @param [Symbol, String] name
338
+ # The name of the instance parameter to search for.
291
339
  #
340
+ # @return [InstanceParam]
341
+ # The instance parameter with the specified name.
342
+ #
343
+ # @raise [ParamNotFound]
344
+ # Could not find the instance parameter with the specified name.
345
+ #
346
+ # @example
292
347
  # obj.get_param('var') # => InstanceParam
293
348
  #
294
349
  def get_param(name)
@@ -302,9 +357,18 @@ module Parameters
302
357
  end
303
358
 
304
359
  #
305
- # Returns the description of the parameter with the specified _name_.
306
- # If no such parameter exists, a ParamNotFound exception will be raised.
360
+ # Returns the description of the parameter with a specific name.
361
+ #
362
+ # @param [Symbol, String] name
363
+ # The name of the instance parameter to search for.
364
+ #
365
+ # @return [String]
366
+ # The description of the instance parameter.
367
+ #
368
+ # @raise [ParamNotFound]
369
+ # Could not find the instance parameter with the specified name.
307
370
  #
371
+ # @example
308
372
  # obj.describe_param('rhost') # => "remote host"
309
373
  #
310
374
  def describe_param(name)
@@ -312,30 +376,35 @@ module Parameters
312
376
  end
313
377
 
314
378
  #
315
- # Returns the value of the parameter with the specified _name_. If no
316
- # such parameter exists, a ParamNotFound exception will be raised.
379
+ # Returns the value of the parameter with a specific name.
317
380
  #
381
+ # @param [Symbol, String] name
382
+ # The name of the instance parameter to search for.
383
+ #
384
+ # @return [Object]
385
+ # The value of the instance parameter with the specified name.
386
+ #
387
+ # @raise [ParamNotFound]
388
+ # Could not find the instance parameter with the specified name.
389
+ #
390
+ # @example
318
391
  # obj.param_value('rhost') # => 80
319
392
  #
320
393
  def param_value(name)
321
394
  get_param(name).value
322
395
  end
323
396
 
324
- #
325
- # Print the instance parameters to the given _output_ stream.
326
- #
327
- def print_params(output=STDOUT)
328
- each_param do |param|
329
- output.puts param
330
- end
331
- end
332
-
333
397
  protected
334
398
 
335
399
  #
336
- # Requires that the parameters with the specified _names_ have
337
- # non +nil+ values. If a parameter with a +nil+ value is found
338
- # a MissingParam exception will be raised.
400
+ # Requires that the instance parameters with specific names have
401
+ # non +nil+ values.
402
+ #
403
+ # @return [true]
404
+ # All the instance parameters have non +nil+ values.
405
+ #
406
+ # @raise [MissingParam]
407
+ # One of the instance parameters was not set.
339
408
  #
340
409
  def require_params(*names)
341
410
  names.each do |name|
@@ -3,15 +3,25 @@ require 'uri'
3
3
  module Parameters
4
4
  module Parser
5
5
  #
6
- # The Array of parameter patterns and their parsers.
6
+ # @return [Array]
7
+ # The parameter patterns and their parsers.
7
8
  #
8
9
  def Parser.formats
9
10
  @@parameters_parser_formats ||= []
10
11
  end
11
12
 
12
13
  #
13
- # Itereates over each parameter pattern and parser, passing them to the
14
- # specified _block_.
14
+ # Itereates over each parameter pattern and parser.
15
+ #
16
+ # @yield [pattern, parser]
17
+ # The block will be passed each parameter pattern and the associated
18
+ # parser.
19
+ #
20
+ # @yieldparam [Regexp, String] pattern
21
+ # The pattern to match recognize parameter values with.
22
+ #
23
+ # @yieldparam [Proc] parser
24
+ # The parser for the parameter value.
15
25
  #
16
26
  def Parser.each_format(&block)
17
27
  Parser.formats.each do |format|
@@ -20,8 +30,17 @@ module Parameters
20
30
  end
21
31
 
22
32
  #
23
- # Adds a new parameter _pattern_ using the specified _block_ as the
24
- # parser.
33
+ # Adds a new parameter parser.
34
+ #
35
+ # @param [Regexp, String] pattern
36
+ # The pattern to recognize parameter values with.
37
+ #
38
+ # @yield [value]
39
+ # The block will be used as the parser for the recognized parameter
40
+ # values.
41
+ #
42
+ # @yieldparam [String] value
43
+ # The parameter value to parser.
25
44
  #
26
45
  def Parser.recognize(pattern,&block)
27
46
  Parser.formats.unshift({
@@ -31,9 +50,21 @@ module Parameters
31
50
  end
32
51
 
33
52
  #
34
- # Parses the specified _value_ string and returns the native Ruby value.
35
- # If the _value_ matches one of the patterns within +FORMATS+,
36
- # then the associated parser will be used to parse the _value_.
53
+ # Recognizes and parses the given parameter value.
54
+ #
55
+ # @param [String] value
56
+ # The parameter value to parse.
57
+ #
58
+ # @return [Object]
59
+ # The parsed parameter value.
60
+ #
61
+ # @example
62
+ # Parser.parse_value("0x1")
63
+ # # => 1
64
+ #
65
+ # @example
66
+ # Parser.parse_value("'mesg'")
67
+ # # => "mesg"
37
68
  #
38
69
  def Parser.parse_value(value)
39
70
  Parser.each_format do |pattern,parser|
@@ -46,11 +77,19 @@ module Parameters
46
77
  end
47
78
 
48
79
  #
49
- # Parses the specified _name_and_value_ string of the form
50
- # "name=value" and extracts both the _name_ and the _value_, saving
51
- # both the _name_ and _value_ within the +params+ Hash. If the
52
- # extracted _value_ matches one of the patterns within +FORMATS+,
53
- # then the associated parser will first parse the _value_.
80
+ # Parses the a parameter string of the form +name=value+.
81
+ #
82
+ # @param [String] name_and_value
83
+ # The name and value parameter join with a +=+ character.
84
+ #
85
+ # @return [Hash{Symbol => Object}]
86
+ # A singleton Hash containing the parameter name and it's value.
87
+ #
88
+ # @example
89
+ # Parser.parse_param('var=2')
90
+ # # => {:var=>2}
91
+ #
92
+ # @since 0.1.8
54
93
  #
55
94
  def Parser.parse_param(name_and_value)
56
95
  name, value = name_and_value.split('=',2)
@@ -59,6 +98,30 @@ module Parameters
59
98
  return {name.to_sym => value}
60
99
  end
61
100
 
101
+ #
102
+ # Parses one or more parameter strings of the form +name=value+.
103
+ #
104
+ # @param [Array<String>] names_and_values
105
+ # The names and values of the parameters, joined by the +=+
106
+ # character.
107
+ #
108
+ # @return [Hash{Symbol => Object}]
109
+ # The names and values of the parameters.
110
+ #
111
+ # @example
112
+ # Parser.parse(["x=2", "y=true"])
113
+ # # => {:x=>2, :y=>true}
114
+ #
115
+ def Parser.parse(names_and_values)
116
+ params = {}
117
+
118
+ names_and_values.each do |name_and_value|
119
+ params.merge!(Parser.parse_param(name_and_value))
120
+ end
121
+
122
+ return params
123
+ end
124
+
62
125
  Parser.recognize(/^'(\\'|[^'])+'/) { |value|
63
126
  value[1...-1].gsub("\\'","'")
64
127
  }
@@ -1,3 +1,3 @@
1
1
  module Parameters
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'yard'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ class EvalBlockHandler < YARD::Handlers::Ruby::Base
7
+
8
+ handles method_call(:module_eval), method_call(:class_eval), method_call(:instance_eval)
9
+
10
+ def process
11
+ if (block = statement.jump(:brace_block, :do_block).last)
12
+ parse_block(block)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'yard/handlers/ruby/legacy/base'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ module Legacy
7
+ class EvalBlockHandler < Base
8
+
9
+ handles /(\A|\.)(module|class|instance)_eval(\s+|\()/
10
+
11
+ def process
12
+ parse_block if statement.block
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'yard/handlers/ruby/legacy/base'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ module Legacy
7
+ class MetaclassEvalHandler < Base
8
+
9
+ handles /(\A|\.)metaclass_eval(\s+|\()/
10
+
11
+ def process
12
+ if statement.block
13
+ parse_block(:namespace => namespace, :scope => :class)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require 'yard'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ module Legacy
7
+ class ParameterHandler < Base
8
+
9
+ handles /\Aparameter\s/
10
+
11
+ def process
12
+ nobj = namespace
13
+ mscope = scope
14
+ name = statement.tokens[2,1].to_s[1..-1]
15
+
16
+ register MethodObject.new(nobj, name, mscope) do |o|
17
+ o.visibility = :public
18
+ o.source = statement.source
19
+ o.signature = "def #{name}"
20
+ end
21
+
22
+ register MethodObject.new(nobj, "#{name}=", mscope) do |o|
23
+ o.visibility = :public
24
+ o.source = statement.source
25
+ o.signature = "def #{name}=(value)"
26
+ o.parameters = [['value', nil]]
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ require 'parameters/yard/handlers/ruby/legacy/eval_block_handler'
2
+ require 'parameters/yard/handlers/ruby/legacy/metaclass_eval_handler'
3
+ require 'parameters/yard/handlers/ruby/legacy/parameter_handler'
@@ -0,0 +1,18 @@
1
+ require 'yard'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ class MetaclassEvalHandler < YARD::Handlers::Ruby::Base
7
+
8
+ handles method_call(:metaclass_eval)
9
+
10
+ def process
11
+ if (block = statement.jump(:brace_block, :do_block).last)
12
+ parse_block(block, :namespace => namespace, :scope => :class)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ require 'yard'
2
+
3
+ module YARD
4
+ module Handlers
5
+ module Ruby
6
+ class ParameterHandler < Base
7
+
8
+ handles method_call(:parameter)
9
+
10
+ def process
11
+ obj = statement.parameters(false).first
12
+ nobj = namespace
13
+ mscope = scope
14
+ name = case obj.type
15
+ when :symbol_literal
16
+ obj.jump(:ident, :op, :kw, :const).source
17
+ when :string_literal
18
+ obj.jump(:string_content).source
19
+ end
20
+
21
+ register MethodObject.new(nobj, name, mscope) do |o|
22
+ o.visibility = :public
23
+ o.source = statement.source
24
+ o.signature = "def #{name}"
25
+ end
26
+
27
+ register MethodObject.new(nobj, "#{name}=", mscope) do |o|
28
+ o.visibility = :public
29
+ o.source = statement.source
30
+ o.signature = "def #{name}=(value)"
31
+ o.parameters = [['value', nil]]
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,4 @@
1
+ require 'parameters/yard/handlers/ruby/eval_block_handler'
2
+ require 'parameters/yard/handlers/ruby/metaclass_eval_handler'
3
+ require 'parameters/yard/handlers/ruby/parameter_handler'
4
+ require 'parameters/yard/handlers/ruby/legacy'
@@ -0,0 +1 @@
1
+ require 'parameters/yard/handlers/ruby'
@@ -0,0 +1 @@
1
+ require 'parameters/yard/handlers'
data/spec/parser_spec.rb CHANGED
@@ -37,4 +37,11 @@ describe Parameters::Parser do
37
37
  it "should parse params of the form 'name=value'" do
38
38
  Parameters::Parser.parse_param('var1=test').should == {:var1 => 'test'}
39
39
  end
40
+
41
+ it "should parse multiple params" do
42
+ Parameters::Parser.parse(['var', 'var1=test']).should == {
43
+ :var => nil,
44
+ :var1 => 'test'
45
+ }
46
+ end
40
47
  end
data/tasks/spec.rb CHANGED
@@ -6,4 +6,5 @@ Spec::Rake::SpecTask.new(:spec) do |t|
6
6
  t.spec_opts = ['--colour', '--format', 'specdoc']
7
7
  end
8
8
 
9
+ task :test => :spec
9
10
  task :default => :spec
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
@@ -30,9 +30,29 @@ cert_chain:
30
30
  pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-07-19 00:00:00 -07:00
33
+ date: 2009-09-25 00:00:00 -07:00
34
34
  default_executable:
35
35
  dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ type: :runtime
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 0.2.3.5
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.8
55
+ version:
36
56
  - !ruby/object:Gem::Dependency
37
57
  name: hoe
38
58
  type: :development
@@ -41,7 +61,7 @@ dependencies:
41
61
  requirements:
42
62
  - - ">="
43
63
  - !ruby/object:Gem::Version
44
- version: 2.3.2
64
+ version: 2.3.3
45
65
  version:
46
66
  description: |-
47
67
  Parameters allows you to add annotated variables to your classes which may
@@ -74,6 +94,16 @@ files:
74
94
  - lib/parameters/param.rb
75
95
  - lib/parameters/parameters.rb
76
96
  - lib/parameters/version.rb
97
+ - lib/parameters/yard.rb
98
+ - lib/parameters/yard/handlers.rb
99
+ - lib/parameters/yard/handlers/ruby.rb
100
+ - lib/parameters/yard/handlers/ruby/eval_block_handler.rb
101
+ - lib/parameters/yard/handlers/ruby/metaclass_eval_handler.rb
102
+ - lib/parameters/yard/handlers/ruby/parameter_handler.rb
103
+ - lib/parameters/yard/handlers/ruby/legacy.rb
104
+ - lib/parameters/yard/handlers/ruby/legacy/eval_block_handler.rb
105
+ - lib/parameters/yard/handlers/ruby/legacy/metaclass_eval_handler.rb
106
+ - lib/parameters/yard/handlers/ruby/legacy/parameter_handler.rb
77
107
  - tasks/spec.rb
78
108
  - spec/spec_helper.rb
79
109
  - spec/classes/test_parameters.rb
@@ -82,7 +112,7 @@ files:
82
112
  - spec/classes/other_parameters.rb
83
113
  - spec/parser_spec.rb
84
114
  - spec/parameters_spec.rb
85
- has_rdoc: true
115
+ has_rdoc: yard
86
116
  homepage: http://parameters.rubyforge.org/
87
117
  licenses: []
88
118
 
@@ -107,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
137
  requirements: []
108
138
 
109
139
  rubyforge_project: parameters
110
- rubygems_version: 1.3.4
140
+ rubygems_version: 1.3.5
111
141
  signing_key:
112
142
  specification_version: 3
113
143
  summary: Parameters allows you to add annotated variables to your classes which may have configurable default values.
metadata.gz.sig CHANGED
Binary file