parameters 0.1.9 → 0.2.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.
metadata CHANGED
@@ -1,68 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9wb3N0
14
- bW9kZXJuLm1vZDMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
15
- ARkWA2NvbTAeFw0wOTA2MDMwNDU5MDNaFw0xMDA2MDMwNDU5MDNaMEYxGDAWBgNV
16
- BAMMD3Bvc3Rtb2Rlcm4ubW9kMzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
17
- CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
18
- 1wvANkTDHFgVih5XLjuTwTZjgBq1lBGybXJiH6Id1lY2JOMqM5FB1DDHVvvij94i
19
- mJabN0zkzu6VKWC70y0IwOxY7CPokr0eFdK/D0y7mCq1P8QITv76i2YqAl0eYqIt
20
- W+IhIkANQ7E6uMZIZcdnfadC6lPAtlKkqtd9crvRbFgr6e3kyflmohbRnTEJHoRd
21
- 7SHHsybE6DSn7oTDs6XBTNrNIn5VfZA0z01eeos/+zBm1zKJOK2+/7xtLLDuDU9G
22
- +Rd+ltUBbvxUrMNZmDG29pnmN2xTRH+Q8HxD2AxlvM5SRpK6OeZaHV7PaCCAVZ4L
23
- T9BFl1sfMvRlABeGEkSyuQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
24
- sDAdBgNVHQ4EFgQUKwsd+PqEYmBvyaTyoL+uRuk+PhEwDQYJKoZIhvcNAQEFBQAD
25
- ggEBAB4TvHsrlbcXcKg6gX5BIb9tI+zGkpzo0Z7jnxMEcNO7NGGwmzafDBI/xZYv
26
- xkRH3/HXbGGYDOi6Q6gWt5GujSx0bOImDtYTJTH8jnzN92HzEK5WdScm1QpZKF1e
27
- cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
28
- GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
29
- /fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
30
- pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
31
- -----END CERTIFICATE-----
10
+ cert_chain: []
32
11
 
33
- date: 2010-01-30 00:00:00 -08:00
12
+ date: 2010-02-18 00:00:00 -08:00
34
13
  default_executable:
35
14
  dependencies:
36
- - !ruby/object:Gem::Dependency
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
49
- version_requirement:
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
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
65
- version:
66
15
  - !ruby/object:Gem::Dependency
67
16
  name: rspec
68
17
  type: :development
@@ -83,70 +32,53 @@ dependencies:
83
32
  - !ruby/object:Gem::Version
84
33
  version: 0.5.3
85
34
  version:
86
- - !ruby/object:Gem::Dependency
87
- name: hoe
88
- type: :development
89
- version_requirement:
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: 2.5.0
95
- version:
96
- description: |-
97
- Parameters allows you to add annotated variables to your classes which may
98
- have configurable default values.
99
- email:
100
- - postmodern.mod3@gmail.com
35
+ description: Parameters allows you to add annotated variables to your classes which may have configurable default values.
36
+ email: postmodern.mod3@gmail.com
101
37
  executables: []
102
38
 
103
39
  extensions: []
104
40
 
105
41
  extra_rdoc_files:
106
- - Manifest.txt
107
- - History.rdoc
42
+ - ChangeLog.md
43
+ - LICENSE.txt
44
+ - README.md
108
45
  files:
109
- - History.rdoc
110
- - Manifest.txt
111
- - README.rdoc
46
+ - .gitignore
47
+ - .specopts
48
+ - .yardopts
49
+ - ChangeLog.md
50
+ - LICENSE.txt
51
+ - README.md
112
52
  - Rakefile
113
53
  - lib/parameters.rb
54
+ - lib/parameters/class_methods.rb
55
+ - lib/parameters/class_param.rb
114
56
  - lib/parameters/exceptions.rb
115
57
  - lib/parameters/exceptions/missing_param.rb
116
58
  - lib/parameters/exceptions/param_not_found.rb
117
59
  - lib/parameters/extensions.rb
118
60
  - lib/parameters/extensions/meta.rb
119
61
  - lib/parameters/extensions/meta/object.rb
120
- - lib/parameters/parser.rb
121
- - lib/parameters/class_param.rb
122
62
  - lib/parameters/instance_param.rb
123
63
  - lib/parameters/param.rb
124
- - lib/parameters/class_methods.rb
125
64
  - lib/parameters/parameters.rb
126
65
  - lib/parameters/version.rb
127
- - lib/parameters/yard.rb
128
- - lib/parameters/yard/handlers.rb
129
- - lib/parameters/yard/handlers/ruby.rb
130
- - lib/parameters/yard/handlers/ruby/parameter_handler.rb
131
- - lib/parameters/yard/handlers/ruby/legacy.rb
132
- - lib/parameters/yard/handlers/ruby/legacy/parameter_handler.rb
133
- - spec/spec_helper.rb
134
- - spec/classes/test_parameters.rb
66
+ - parameters.gemspec
67
+ - spec/class_param_spec.rb
135
68
  - spec/classes/custom_parameters.rb
136
69
  - spec/classes/inherited_parameters.rb
137
70
  - spec/classes/other_parameters.rb
138
- - spec/parser_spec.rb
71
+ - spec/classes/test_parameters.rb
72
+ - spec/instance_param_spec.rb
139
73
  - spec/parameters_spec.rb
74
+ - spec/spec_helper.rb
140
75
  has_rdoc: yard
141
- homepage: http://parameters.rubyforge.org/
76
+ homepage: http://github.com/postmodern/parameters
142
77
  licenses: []
143
78
 
144
79
  post_install_message:
145
80
  rdoc_options:
146
- - --protected
147
- - --title
148
- - Parameters Documentation
149
- - --quiet
81
+ - --charset=UTF-8
150
82
  require_paths:
151
83
  - lib
152
84
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -163,10 +95,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
95
  version:
164
96
  requirements: []
165
97
 
166
- rubyforge_project: parameters
98
+ rubyforge_project:
167
99
  rubygems_version: 1.3.5
168
100
  signing_key:
169
101
  specification_version: 3
170
- summary: Parameters allows you to add annotated variables to your classes which may have configurable default values.
171
- test_files: []
172
-
102
+ summary: Allows you to add annotated variables to your classes
103
+ test_files:
104
+ - spec/parameters_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/class_param_spec.rb
107
+ - spec/instance_param_spec.rb
108
+ - spec/classes/inherited_parameters.rb
109
+ - spec/classes/test_parameters.rb
110
+ - spec/classes/custom_parameters.rb
111
+ - spec/classes/other_parameters.rb
data.tar.gz.sig DELETED
Binary file
@@ -1,73 +0,0 @@
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
-
7
- === 0.1.8 / 2009-09-21
8
-
9
- * Require Hoe >= 2.3.3.
10
- * Require YARD >= 0.2.3.5.
11
- * Require RSpec >= 1.2.8.
12
- * Use 'hoe/signing' for signed RubyGems.
13
- * Moved to YARD based documentation.
14
- * Added YARD handlers for documenting parameter method calls.
15
- * All specs pass on JRuby 1.3.1.
16
-
17
- === 0.1.7 / 2009-07-19
18
-
19
- * Renamed Parameters#initialize_parameters to
20
- Parameters#initialize_params.
21
- * Adjust spacing in the output of ClassParam#to_s
22
- and InstanceParam#to_s.
23
- * Specifically check if the instance variable is nil
24
- before initializing it to the default value of the parameter.
25
- * Handle default value callbacks in Parameters#parameter.
26
- * Check the arity of all default value callbacks, before
27
- passing self to them.
28
- * Parameters#require_params now specifically tests if
29
- the instance variable of the parameter is nil.
30
- * Added more specs.
31
-
32
- === 0.1.6 / 2009-05-11
33
-
34
- * Fixed a bug in Parameters.params= and Parameters#params=, where they
35
- were not handling Parameters::ClassParam or Parameters::InstanceParam
36
- objects properly.
37
- * Added more specs.
38
-
39
- === 0.1.5 / 2009-05-06
40
-
41
- * Added Parameters::Parser for parsing parameter values passed in from
42
- the command-line or the web.
43
- * Changed Parameters::MissingParam and Parameters::ParamNotFound to
44
- inherit from StandardError.
45
- * All specs pass on Ruby 1.9.1-p0.
46
-
47
- === 0.1.4 / 2009-01-17
48
-
49
- * All specs now pass with RSpec 1.1.12.
50
- * All specs pass on Ruby 1.9.1-rc1.
51
-
52
- === 0.1.3 / 2009-01-14
53
-
54
- * Allow the use of lambdas to generate the default values of parameters.
55
- * Fixed typos in the README.txt.
56
-
57
- === 0.1.2 / 2009-01-06
58
-
59
- * When printing parameter values, print the inspected version of the value.
60
-
61
- === 0.1.1 / 2008-12-27
62
-
63
- * Added the require_params helper method.
64
- * Added print_params methods for displaying parameters of a class or an
65
- object.
66
-
67
- === 0.1.0 / 2008-12-03
68
-
69
- * Initial release.
70
- * Added Parameters.params= and Parameters#params= methods.
71
- * Allow Parameters#initialize to accept a Hash of parameter values.
72
- * Added more specs.
73
-
@@ -1,31 +0,0 @@
1
- History.rdoc
2
- Manifest.txt
3
- README.rdoc
4
- Rakefile
5
- lib/parameters.rb
6
- lib/parameters/exceptions.rb
7
- lib/parameters/exceptions/missing_param.rb
8
- lib/parameters/exceptions/param_not_found.rb
9
- lib/parameters/extensions.rb
10
- lib/parameters/extensions/meta.rb
11
- lib/parameters/extensions/meta/object.rb
12
- lib/parameters/parser.rb
13
- lib/parameters/class_param.rb
14
- lib/parameters/instance_param.rb
15
- lib/parameters/param.rb
16
- lib/parameters/class_methods.rb
17
- lib/parameters/parameters.rb
18
- lib/parameters/version.rb
19
- lib/parameters/yard.rb
20
- lib/parameters/yard/handlers.rb
21
- lib/parameters/yard/handlers/ruby.rb
22
- lib/parameters/yard/handlers/ruby/parameter_handler.rb
23
- lib/parameters/yard/handlers/ruby/legacy.rb
24
- lib/parameters/yard/handlers/ruby/legacy/parameter_handler.rb
25
- spec/spec_helper.rb
26
- spec/classes/test_parameters.rb
27
- spec/classes/custom_parameters.rb
28
- spec/classes/inherited_parameters.rb
29
- spec/classes/other_parameters.rb
30
- spec/parser_spec.rb
31
- spec/parameters_spec.rb
@@ -1,91 +0,0 @@
1
- = Parameters
2
-
3
- * http://parameters.rubyforge.org/
4
- * http://github.com/postmodern/parameters/
5
- * Postmodern (postmodern.mod3 at gmail.com)
6
-
7
- == DESCRIPTION:
8
-
9
- Parameters allows you to add annotated variables to your classes which may
10
- have configurable default values.
11
-
12
- == FEATURES:
13
-
14
- * Give parameters default values.
15
- * Default values maybe either objects or lambdas used to generate the
16
- default value.
17
- * Change default values of parameters.
18
- * Give descriptions to parameters.
19
- * Set parameters en-mass.
20
- * Parse strings of the form <tt>name=value</tt> into a Hash of parameters.
21
-
22
- == EXAMPLES:
23
-
24
- class Octagon
25
-
26
- include Parameters
27
-
28
- parameter :x, :default => 0
29
-
30
- parameter :y, :default => 0.5
31
-
32
- parameter :radius, :description => 'The radius of the Octagon'
33
-
34
- parameter :opacity,
35
- :default => lambda { rand },
36
- :description => 'The opacity of the Octagon'
37
-
38
- end
39
-
40
- # Create an object with default values for all parameters
41
- oct = Octagon.new
42
- oct.x # => 0
43
- oct.y # => 0.5
44
- oct.opacity # => 0.25
45
-
46
- # Create an object with the given parameter values.
47
- oct = Octagon.new(:radius => 10)
48
- oct.radius # => 10
49
- oct.opacity # => 0.7
50
-
51
- # Set parameter values of a class
52
- Octagon.radius = 33
53
- Octagon.opacity = 0.3
54
-
55
- # Create an object with parameter defaulte values inherited from the
56
- # class parameters
57
- oct = Octagon.new
58
- oct.radius # => 33
59
- oct.opacity # => 0.3
60
-
61
- # Parse user given name=value parameter strings
62
- oct.params = Parameters::Parser.parse(ARGV)
63
-
64
- == INSTALL:
65
-
66
- $ sudo gem install parameters
67
-
68
- == LICENSE:
69
-
70
- The MIT License
71
-
72
- Copyright (c) 2008-2010 Hal Brodigan
73
-
74
- Permission is hereby granted, free of charge, to any person obtaining
75
- a copy of this software and associated documentation files (the
76
- 'Software'), to deal in the Software without restriction, including
77
- without limitation the rights to use, copy, modify, merge, publish,
78
- distribute, sublicense, and/or sell copies of the Software, and to
79
- permit persons to whom the Software is furnished to do so, subject to
80
- the following conditions:
81
-
82
- The above copyright notice and this permission notice shall be
83
- included in all copies or substantial portions of the Software.
84
-
85
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
86
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
87
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
88
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
89
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
90
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
91
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,136 +0,0 @@
1
- require 'uri'
2
-
3
- module Parameters
4
- module Parser
5
- #
6
- # @return [Array]
7
- # The parameter patterns and their parsers.
8
- #
9
- def Parser.formats
10
- @@parameters_parser_formats ||= []
11
- end
12
-
13
- #
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.
25
- #
26
- def Parser.each_format(&block)
27
- Parser.formats.each do |format|
28
- block.call(format[:pattern],format[:parser])
29
- end
30
- end
31
-
32
- #
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.
44
- #
45
- def Parser.recognize(pattern,&block)
46
- Parser.formats.unshift({
47
- :pattern => pattern,
48
- :parser => block
49
- })
50
- end
51
-
52
- #
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"
68
- #
69
- def Parser.parse_value(value)
70
- Parser.each_format do |pattern,parser|
71
- if value.match(pattern)
72
- return parser.call(value)
73
- end
74
- end
75
-
76
- return value
77
- end
78
-
79
- #
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
93
- #
94
- def Parser.parse_param(name_and_value)
95
- name, value = name_and_value.split('=',2)
96
-
97
- value = Parser.parse_value(value) if value
98
- return {name.to_sym => value}
99
- end
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
-
125
- Parser.recognize(/^'(\\'|[^'])+'/) { |value|
126
- value[1...-1].gsub("\\'","'")
127
- }
128
- Parser.recognize(/^[a-zA-Z][a-zA-Z0-9]*:\/\//) { |value| URI(value) }
129
- Parser.recognize('false') { |value| false }
130
- Parser.recognize('true') { |value| true }
131
- Parser.recognize(/^[0-9]+$/) { |value| value.to_i }
132
- Parser.recognize(/^0[0-7]+$/) { |value| value.oct }
133
- Parser.recognize(/^0x[0-9a-fA-F]+$/) { |value| value.hex }
134
-
135
- end
136
- end