parameters 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,9 @@
1
+ === 0.1.9 / 2009-01-30
2
+
3
+ * Require RSpec >= 1.3.0.
4
+ * Require YARD >= 0.5.3.
5
+ * Added {Parameters::ClassMethods}.
6
+
1
7
  === 0.1.8 / 2009-09-21
2
8
 
3
9
  * Require Hoe >= 2.3.3.
@@ -1,6 +1,6 @@
1
- History.txt
1
+ History.rdoc
2
2
  Manifest.txt
3
- README.txt
3
+ README.rdoc
4
4
  Rakefile
5
5
  lib/parameters.rb
6
6
  lib/parameters/exceptions.rb
@@ -13,19 +13,15 @@ lib/parameters/parser.rb
13
13
  lib/parameters/class_param.rb
14
14
  lib/parameters/instance_param.rb
15
15
  lib/parameters/param.rb
16
+ lib/parameters/class_methods.rb
16
17
  lib/parameters/parameters.rb
17
18
  lib/parameters/version.rb
18
19
  lib/parameters/yard.rb
19
20
  lib/parameters/yard/handlers.rb
20
21
  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
22
  lib/parameters/yard/handlers/ruby/parameter_handler.rb
24
23
  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
24
  lib/parameters/yard/handlers/ruby/legacy/parameter_handler.rb
28
- tasks/spec.rb
29
25
  spec/spec_helper.rb
30
26
  spec/classes/test_parameters.rb
31
27
  spec/classes/custom_parameters.rb
@@ -17,7 +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
+ * Parse strings of the form <tt>name=value</tt> into a Hash of parameters.
21
21
 
22
22
  == EXAMPLES:
23
23
 
@@ -61,10 +61,6 @@ have configurable default values.
61
61
  # Parse user given name=value parameter strings
62
62
  oct.params = Parameters::Parser.parse(ARGV)
63
63
 
64
- == REQUIREMENTS:
65
-
66
- * {YARD}[http://yard.soen.ca/] >= 0.2.3.5
67
-
68
64
  == INSTALL:
69
65
 
70
66
  $ sudo gem install parameters
@@ -73,7 +69,7 @@ have configurable default values.
73
69
 
74
70
  The MIT License
75
71
 
76
- Copyright (c) 2008-2009 Hal Brodigan
72
+ Copyright (c) 2008-2010 Hal Brodigan
77
73
 
78
74
  Permission is hereby granted, free of charge, to any person obtaining
79
75
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -3,22 +3,21 @@
3
3
  require 'rubygems'
4
4
  require 'hoe'
5
5
  require 'hoe/signing'
6
- require './tasks/spec.rb'
7
- require './tasks/yard.rb'
6
+
7
+ Hoe.plugin :yard
8
8
 
9
9
  Hoe.spec('parameters') do
10
- self.rubyforge_name = 'parameters'
11
10
  self.developer('Postmodern','postmodern.mod3@gmail.com')
12
- self.remote_rdoc_dir = '/'
13
- self.extra_deps = [
14
- ['yard', '>=0.2.3.5']
15
- ]
16
11
 
17
- self.extra_dev_deps = [
18
- ['rspec', '>=1.2.8']
19
- ]
12
+ self.rspec_options += ['--colour', '--format', 'specdoc']
20
13
 
21
- self.spec_extras = {:has_rdoc => 'yard'}
14
+ self.yard_options += ['--protected']
15
+ self.remote_yard_dir = '/'
16
+
17
+ self.extra_dev_deps += [
18
+ ['rspec', '>=1.3.0'],
19
+ ['yard', '>=0.5.3']
20
+ ]
22
21
  end
23
22
 
24
23
  # vim: syntax=Ruby
@@ -0,0 +1,163 @@
1
+ require 'parameters/exceptions'
2
+ require 'parameters/class_param'
3
+ require 'parameters/extensions/meta'
4
+
5
+ module Parameters
6
+ module ClassMethods
7
+ #
8
+ # @return [Hash]
9
+ # Parameters for the class.
10
+ #
11
+ def params
12
+ @params ||= {}
13
+ end
14
+
15
+ #
16
+ # Sets the values of the class parameters.
17
+ #
18
+ # @param [Hash] values
19
+ # The names and new values to set the class params to.
20
+ #
21
+ # @example
22
+ # Test.params = {:x => 5, :y => 2}
23
+ # # => {:x=>5, :y=>2}
24
+ #
25
+ def params=(values)
26
+ values.each do |name,value|
27
+ if has_param?(name)
28
+ if (value.kind_of?(Parameters::ClassParam) || value.kind_of?(Parameters::InstanceParam))
29
+ value = value.value
30
+ end
31
+
32
+ get_param(name).value = value
33
+ end
34
+ end
35
+ end
36
+
37
+ #
38
+ # Adds a new parameters to the class.
39
+ #
40
+ # @param [Symbol, String] name
41
+ # The name of the new parameter.
42
+ #
43
+ # @param [Hash] options
44
+ # Additional options.
45
+ #
46
+ # @option options [String] :description
47
+ # The description for the new parameter.
48
+ #
49
+ # @option options [Object, Proc] :default
50
+ # The default value for the new parameter.
51
+ #
52
+ # @example
53
+ # parameter 'var'
54
+ #
55
+ # @example
56
+ # parameter 'var', :default => 3, :description => 'my variable'
57
+ #
58
+ def parameter(name,options={})
59
+ name = name.to_sym
60
+
61
+ # add the parameter to the class params list
62
+ params[name] = Parameters::ClassParam.new(name,options[:description],options[:default])
63
+
64
+ # define the reader class method for the parameter
65
+ meta_def(name) do
66
+ params[name].value
67
+ end
68
+
69
+ # define the writer class method for the parameter
70
+ meta_def("#{name}=") do |value|
71
+ params[name].value = value
72
+ end
73
+
74
+ # define the getter/setter instance methods for the parameter
75
+ attr_accessor(name)
76
+ end
77
+
78
+ #
79
+ # Searches for the class parameter with the matching name.
80
+ #
81
+ # @param [Symbol, String] name
82
+ # The class parameter name to search for.
83
+ #
84
+ # @return [ClassParam]
85
+ # The class parameter with the matching _name_.
86
+ #
87
+ # @raise [ParamNotFound]
88
+ # No class parameter with the specified _name_ could be found.
89
+ #
90
+ def get_param(name)
91
+ name = name.to_sym
92
+
93
+ ancestors.each do |ancestor|
94
+ if ancestor.include?(Parameters)
95
+ if ancestor.params.has_key?(name)
96
+ return ancestor.params[name]
97
+ end
98
+ end
99
+ end
100
+
101
+ raise(Parameters::ParamNotFound,"parameter #{name.to_s.dump} was not found in class #{self.name.dump}",caller)
102
+ end
103
+
104
+ #
105
+ # @return [Boolean]
106
+ # Specifies whether or not there is a class parameter with the
107
+ # specified _name_.
108
+ #
109
+ def has_param?(name)
110
+ name = name.to_sym
111
+
112
+ ancestors.each do |ancestor|
113
+ if ancestor.include?(Parameters)
114
+ return true if ancestor.params.has_key?(name)
115
+ end
116
+ end
117
+
118
+ return false
119
+ end
120
+
121
+ #
122
+ # Iterates over the parameters of the class and it's ancestors.
123
+ #
124
+ # @yield [param]
125
+ # The block that will be passed each class parameter.
126
+ #
127
+ def each_param(&block)
128
+ ancestors.each do |ancestor|
129
+ if ancestor.include?(Parameters)
130
+ ancestor.params.each_value(&block)
131
+ end
132
+ end
133
+
134
+ return self
135
+ end
136
+
137
+ #
138
+ # Returns the description of the class parameters with a given name.
139
+ #
140
+ # @return [String]
141
+ # Description of the class parameter with the specified name.
142
+ #
143
+ # @raise [ParamNotFound]
144
+ # No class parameter with the specified name could be found.
145
+ #
146
+ def describe_param(name)
147
+ get_param(name).description
148
+ end
149
+
150
+ #
151
+ # Returns the value of the class parameters with a given name.
152
+ #
153
+ # @return [Object]
154
+ # Value of the class parameter with the specified name.
155
+ #
156
+ # @raise [ParamNotFound]
157
+ # No class parameter with the specified name could be found.
158
+ #
159
+ def param_value(name)
160
+ get_param(name).value
161
+ end
162
+ end
163
+ end
@@ -4,14 +4,6 @@ class Object # :nodoc:
4
4
  def metaclass; class << self; self; end; end
5
5
  def meta_eval(&blk); metaclass.instance_eval(&blk); end
6
6
 
7
- # A class_eval version of meta_eval
8
- def metaclass_eval(&blk); metaclass.class_eval(&blk); end
9
-
10
- # A class_def version of meta_def
11
- def metaclass_def(name, &blk)
12
- metaclass_eval { define_method(name, &blk) }
13
- end
14
-
15
7
  # Adds methods to a metaclass
16
8
  def meta_def(name, &blk)
17
9
  meta_eval { define_method(name, &blk) }
@@ -1,4 +1,5 @@
1
1
  require 'parameters/exceptions'
2
+ require 'parameters/class_methods'
2
3
  require 'parameters/class_param'
3
4
  require 'parameters/instance_param'
4
5
  require 'parameters/exceptions'
@@ -6,163 +7,7 @@ require 'parameters/extensions/meta'
6
7
 
7
8
  module Parameters
8
9
  def self.included(base)
9
- base.metaclass_eval do
10
- #
11
- # @return [Hash]
12
- # Parameters for the class.
13
- #
14
- def params
15
- @params ||= {}
16
- end
17
-
18
- #
19
- # Sets the values of the class parameters.
20
- #
21
- # @param [Hash] values
22
- # The names and new values to set the class params to.
23
- #
24
- # @example
25
- # Test.params = {:x => 5, :y => 2}
26
- # # => {:x=>5, :y=>2}
27
- #
28
- def params=(values)
29
- values.each do |name,value|
30
- if has_param?(name)
31
- if (value.kind_of?(Parameters::ClassParam) || value.kind_of?(Parameters::InstanceParam))
32
- value = value.value
33
- end
34
-
35
- get_param(name).value = value
36
- end
37
- end
38
- end
39
-
40
- #
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.
48
- #
49
- # @option options [String] :description
50
- # The description for the new parameter.
51
- #
52
- # @option options [Object, Proc] :default
53
- # The default value for the new parameter.
54
- #
55
- # @example
56
- # parameter 'var'
57
- #
58
- # @example
59
- # parameter 'var', :default => 3, :description => 'my variable'
60
- #
61
- def parameter(name,options={})
62
- name = name.to_sym
63
-
64
- # add the parameter to the class params list
65
- params[name] = Parameters::ClassParam.new(name,options[:description],options[:default])
66
-
67
- # define the reader class method for the parameter
68
- meta_def(name) do
69
- params[name].value
70
- end
71
-
72
- # define the writer class method for the parameter
73
- meta_def("#{name}=") do |value|
74
- params[name].value = value
75
- end
76
-
77
- # define the getter/setter instance methods for the parameter
78
- attr_accessor(name)
79
- end
80
-
81
- #
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.
92
- #
93
- def get_param(name)
94
- name = name.to_sym
95
-
96
- ancestors.each do |ancestor|
97
- if ancestor.include?(Parameters)
98
- if ancestor.params.has_key?(name)
99
- return ancestor.params[name]
100
- end
101
- end
102
- end
103
-
104
- raise(Parameters::ParamNotFound,"parameter #{name.to_s.dump} was not found in class #{self.name.dump}",caller)
105
- end
106
-
107
- #
108
- # @return [Boolean]
109
- # Specifies whether or not there is a class parameter with the
110
- # specified _name_.
111
- #
112
- def has_param?(name)
113
- name = name.to_sym
114
-
115
- ancestors.each do |ancestor|
116
- if ancestor.include?(Parameters)
117
- return true if ancestor.params.has_key?(name)
118
- end
119
- end
120
-
121
- return false
122
- end
123
-
124
- #
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.
129
- #
130
- def each_param(&block)
131
- ancestors.each do |ancestor|
132
- if ancestor.include?(Parameters)
133
- ancestor.params.each_value(&block)
134
- end
135
- end
136
-
137
- return self
138
- end
139
-
140
- #
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.
148
- #
149
- def describe_param(name)
150
- get_param(name).description
151
- end
152
-
153
- #
154
- # Returns the value of the class parameters with a given name.
155
- #
156
- # @return [Object]
157
- # Value of the class parameter with the specified name.
158
- #
159
- # @raise [ParamNotFound]
160
- # No class parameter with the specified name could be found.
161
- #
162
- def param_value(name)
163
- get_param(name).value
164
- end
165
- end
10
+ base.extend ClassMethods
166
11
  end
167
12
 
168
13
  #
@@ -1,3 +1,3 @@
1
1
  module Parameters
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -1,4 +1,2 @@
1
- require 'parameters/yard/handlers/ruby/eval_block_handler'
2
- require 'parameters/yard/handlers/ruby/metaclass_eval_handler'
3
1
  require 'parameters/yard/handlers/ruby/parameter_handler'
4
2
  require 'parameters/yard/handlers/ruby/legacy'
@@ -1,3 +1 @@
1
- require 'parameters/yard/handlers/ruby/legacy/eval_block_handler'
2
- require 'parameters/yard/handlers/ruby/legacy/metaclass_eval_handler'
3
1
  require 'parameters/yard/handlers/ruby/legacy/parameter_handler'
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- gem 'rspec', '>=1.1.3'
2
+ gem 'rspec', '>=1.3.0'
3
3
  require 'spec'
4
4
 
5
5
  require 'parameters/version'
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
@@ -30,18 +30,38 @@ cert_chain:
30
30
  pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-09-25 00:00:00 -07:00
33
+ date: 2010-01-30 00:00:00 -08:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
- name: yard
38
- type: :runtime
37
+ name: rubyforge
38
+ type: :development
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.0.3
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: gemcutter
48
+ type: :development
39
49
  version_requirement:
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
51
  requirements:
42
52
  - - ">="
43
53
  - !ruby/object:Gem::Version
44
- version: 0.2.3.5
54
+ version: 0.3.0
55
+ version:
56
+ - !ruby/object:Gem::Dependency
57
+ name: hoe-yard
58
+ type: :development
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.1.2
45
65
  version:
46
66
  - !ruby/object:Gem::Dependency
47
67
  name: rspec
@@ -51,7 +71,17 @@ dependencies:
51
71
  requirements:
52
72
  - - ">="
53
73
  - !ruby/object:Gem::Version
54
- version: 1.2.8
74
+ version: 1.3.0
75
+ version:
76
+ - !ruby/object:Gem::Dependency
77
+ name: yard
78
+ type: :development
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.5.3
55
85
  version:
56
86
  - !ruby/object:Gem::Dependency
57
87
  name: hoe
@@ -61,7 +91,7 @@ dependencies:
61
91
  requirements:
62
92
  - - ">="
63
93
  - !ruby/object:Gem::Version
64
- version: 2.3.3
94
+ version: 2.5.0
65
95
  version:
66
96
  description: |-
67
97
  Parameters allows you to add annotated variables to your classes which may
@@ -73,13 +103,12 @@ executables: []
73
103
  extensions: []
74
104
 
75
105
  extra_rdoc_files:
76
- - History.txt
77
106
  - Manifest.txt
78
- - README.txt
107
+ - History.rdoc
79
108
  files:
80
- - History.txt
109
+ - History.rdoc
81
110
  - Manifest.txt
82
- - README.txt
111
+ - README.rdoc
83
112
  - Rakefile
84
113
  - lib/parameters.rb
85
114
  - lib/parameters/exceptions.rb
@@ -92,19 +121,15 @@ files:
92
121
  - lib/parameters/class_param.rb
93
122
  - lib/parameters/instance_param.rb
94
123
  - lib/parameters/param.rb
124
+ - lib/parameters/class_methods.rb
95
125
  - lib/parameters/parameters.rb
96
126
  - lib/parameters/version.rb
97
127
  - lib/parameters/yard.rb
98
128
  - lib/parameters/yard/handlers.rb
99
129
  - 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
130
  - lib/parameters/yard/handlers/ruby/parameter_handler.rb
103
131
  - 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
132
  - lib/parameters/yard/handlers/ruby/legacy/parameter_handler.rb
107
- - tasks/spec.rb
108
133
  - spec/spec_helper.rb
109
134
  - spec/classes/test_parameters.rb
110
135
  - spec/classes/custom_parameters.rb
@@ -118,8 +143,10 @@ licenses: []
118
143
 
119
144
  post_install_message:
120
145
  rdoc_options:
121
- - --main
122
- - README.txt
146
+ - --protected
147
+ - --title
148
+ - Parameters Documentation
149
+ - --quiet
123
150
  require_paths:
124
151
  - lib
125
152
  required_ruby_version: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file
@@ -1,18 +0,0 @@
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
@@ -1,19 +0,0 @@
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
@@ -1,21 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,10 +0,0 @@
1
- require 'spec/rake/spectask'
2
-
3
- desc "Run all specifications"
4
- Spec::Rake::SpecTask.new(:spec) do |t|
5
- t.libs += ['lib', 'spec']
6
- t.spec_opts = ['--colour', '--format', 'specdoc']
7
- end
8
-
9
- task :test => :spec
10
- task :default => :spec