parameters 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +10 -0
- data/ChangeLog.md +7 -0
- data/LICENSE.txt +1 -2
- data/README.md +15 -14
- data/Rakefile +6 -5
- data/gemspec.yml +5 -4
- data/lib/parameters/class_methods.rb +61 -22
- data/lib/parameters/class_param.rb +23 -0
- data/lib/parameters/instance_param.rb +21 -1
- data/lib/parameters/param.rb +17 -337
- data/lib/parameters/parameters.rb +54 -62
- data/lib/parameters/types.rb +17 -0
- data/lib/parameters/types/array.rb +83 -0
- data/lib/parameters/types/boolean.rb +47 -0
- data/lib/parameters/types/class.rb +45 -0
- data/lib/parameters/types/date.rb +28 -0
- data/lib/parameters/types/date_time.rb +29 -0
- data/lib/parameters/types/float.rb +26 -0
- data/lib/parameters/types/hash.rb +98 -0
- data/lib/parameters/types/integer.rb +31 -0
- data/lib/parameters/types/object.rb +50 -0
- data/lib/parameters/types/proc.rb +35 -0
- data/lib/parameters/types/regexp.rb +26 -0
- data/lib/parameters/types/set.rb +28 -0
- data/lib/parameters/types/string.rb +22 -0
- data/lib/parameters/types/symbol.rb +26 -0
- data/lib/parameters/types/time.rb +33 -0
- data/lib/parameters/types/type.rb +65 -0
- data/lib/parameters/types/types.rb +96 -0
- data/lib/parameters/types/uri.rb +41 -0
- data/lib/parameters/version.rb +2 -1
- data/parameters.gemspec +124 -7
- data/spec/class_param_spec.rb +1 -199
- data/spec/instance_param_spec.rb +3 -205
- data/spec/parameters_spec.rb +81 -58
- data/spec/spec_helper.rb +1 -1
- data/spec/types/array_spec.rb +39 -0
- data/spec/types/boolean_spec.rb +42 -0
- data/spec/types/class_spec.rb +31 -0
- data/spec/types/date_spec.rb +20 -0
- data/spec/types/date_time_spec.rb +20 -0
- data/spec/types/float_spec.rb +12 -0
- data/spec/types/hash_spec.rb +71 -0
- data/spec/types/integer_spec.rb +18 -0
- data/spec/types/object_spec.rb +24 -0
- data/spec/types/proc_spec.rb +21 -0
- data/spec/types/regexp_spec.rb +12 -0
- data/spec/types/set_spec.rb +40 -0
- data/spec/types/string_spec.rb +12 -0
- data/spec/types/symbol_spec.rb +12 -0
- data/spec/types/time_spec.rb +25 -0
- data/spec/types/types_spec.rb +82 -0
- data/spec/types/uri_spec.rb +23 -0
- metadata +107 -90
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parameters/types/integer'
|
3
|
+
|
4
|
+
describe Parameters::Types::Integer do
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
describe "coerce" do
|
8
|
+
it "should call #to_i" do
|
9
|
+
subject.coerce(10.0).should == 10
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when coercing a String" do
|
13
|
+
it "should pass 0 to #to_i" do
|
14
|
+
subject.coerce('0x10').should == 16
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parameters/types/object'
|
3
|
+
|
4
|
+
describe Parameters::Types::Object do
|
5
|
+
describe "to_ruby" do
|
6
|
+
it "should lookup the Ruby Class that the Type is named after" do
|
7
|
+
described_class.to_ruby.should == ::Object
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#===" do
|
12
|
+
it "should always return true" do
|
13
|
+
subject.should === 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#coerce" do
|
18
|
+
let(:obj) { Object.new }
|
19
|
+
|
20
|
+
it "should pass through values" do
|
21
|
+
subject.coerce(obj).should == obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'classes/custom_type'
|
3
|
+
require 'parameters/types/proc'
|
4
|
+
|
5
|
+
describe Parameters::Types::Proc do
|
6
|
+
let(:callback) { proc { |value| "0x%x" % value } }
|
7
|
+
|
8
|
+
subject { described_class.new(callback) }
|
9
|
+
|
10
|
+
describe "#===" do
|
11
|
+
it "should always return false" do
|
12
|
+
subject.should_not === "0x10"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#coerce" do
|
17
|
+
it "should pass the value to the callback" do
|
18
|
+
subject.coerce(16).should == "0x10"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parameters/types/set'
|
3
|
+
require 'parameters/types/integer'
|
4
|
+
|
5
|
+
describe Parameters::Types::Set do
|
6
|
+
let(:array) { [1, 2, 3] }
|
7
|
+
let(:set) { Set[1, 2, 3] }
|
8
|
+
|
9
|
+
subject { described_class }
|
10
|
+
|
11
|
+
describe "coerce" do
|
12
|
+
it "should call #to_set" do
|
13
|
+
subject.coerce(array).should == set
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "instance" do
|
18
|
+
let(:numbers) { %w[1 2 3] }
|
19
|
+
|
20
|
+
subject { described_class.new(Parameters::Types::Integer.new) }
|
21
|
+
|
22
|
+
it "should have a Ruby type" do
|
23
|
+
subject.to_ruby.should == Set[Integer]
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#===" do
|
27
|
+
it "should check the type of each element" do
|
28
|
+
subject.should_not === numbers
|
29
|
+
|
30
|
+
subject.should === set
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#coerce" do
|
35
|
+
it "should coerce each element" do
|
36
|
+
subject.coerce(numbers).should == set
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parameters/types/time'
|
3
|
+
|
4
|
+
describe Parameters::Types::Time do
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
describe "coerce" do
|
8
|
+
let(:string) { '2011-12-03 19:39:09 -0800' }
|
9
|
+
let(:timestamp) { 1322969949 }
|
10
|
+
let(:time) { Time.at(1322969949) }
|
11
|
+
let(:date) { DateTime.parse(string) }
|
12
|
+
|
13
|
+
it "should accept Integers" do
|
14
|
+
subject.coerce(timestamp).should == time
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should call #to_time when possible" do
|
18
|
+
subject.coerce(date).should == time
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should parse Strings" do
|
22
|
+
subject.coerce(string).should == time
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'classes/custom_type'
|
3
|
+
require 'parameters/types'
|
4
|
+
|
5
|
+
describe Parameters::Types do
|
6
|
+
describe "type_defined?" do
|
7
|
+
it "should lookup constants" do
|
8
|
+
subject.type_defined?('Array').should == true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should ignore top-level constants" do
|
12
|
+
subject.type_defined?('Kernel').should == false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "type_get" do
|
17
|
+
it "should lookup constants" do
|
18
|
+
subject.type_get('Array').should == Parameters::Types::Array
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should ignore top-level constants" do
|
22
|
+
lambda {
|
23
|
+
subject.type_get('Kernel')
|
24
|
+
}.should raise_error(NameError)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "[]" do
|
29
|
+
it "should map known Classes to Types" do
|
30
|
+
subject[Array].should == Parameters::Types::Array
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should map Arrays to the Array type" do
|
34
|
+
type = subject[Array[Integer]]
|
35
|
+
|
36
|
+
type.class.should == Parameters::Types::Array
|
37
|
+
type.element_type.should == Parameters::Types::Integer
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should map Sets to the Set type" do
|
41
|
+
type = subject[Set[Symbol]]
|
42
|
+
|
43
|
+
type.class.should == Parameters::Types::Set
|
44
|
+
type.element_type.should == Parameters::Types::Symbol
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should map Hashes to the Hash type" do
|
48
|
+
type = subject[Hash[Symbol => Integer]]
|
49
|
+
|
50
|
+
type.class.should == Parameters::Types::Hash
|
51
|
+
type.key_type.should == Parameters::Types::Symbol
|
52
|
+
type.value_type.should == Parameters::Types::Integer
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should map unknown Classes to the Class type" do
|
56
|
+
type = subject[CustomType]
|
57
|
+
|
58
|
+
type.class.should == Parameters::Types::Class
|
59
|
+
type.base_class.should == CustomType
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should map Procs to the Proc type" do
|
63
|
+
type = subject[proc { |value| "0x%x" % value }]
|
64
|
+
|
65
|
+
type.class.should == Parameters::Types::Proc
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should map true to the Boolean type" do
|
69
|
+
subject[true].should == Parameters::Types::Boolean
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should map nil to the Object type" do
|
73
|
+
subject[nil].should == Parameters::Types::Object
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise a TypeError for unmappable Objects" do
|
77
|
+
lambda {
|
78
|
+
subject[Object.new]
|
79
|
+
}.should raise_error(TypeError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'parameters/types/uri'
|
3
|
+
|
4
|
+
describe Parameters::Types::URI do
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
let(:url) { 'http://www.example.com/' }
|
8
|
+
let(:uri) { URI.parse(url) }
|
9
|
+
|
10
|
+
describe "===" do
|
11
|
+
it "should check if the value is kind of URI::Generic" do
|
12
|
+
subject.should_not === URI
|
13
|
+
|
14
|
+
subject.should === uri
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "coerce" do
|
19
|
+
it "should parse Strings" do
|
20
|
+
subject.coerce(url).should == uri
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,91 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: parameters
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 2
|
8
|
-
- 3
|
9
|
-
version: 0.2.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Postmodern
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: ore
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
|
-
requirements:
|
26
|
-
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
- 2
|
31
|
-
- 0
|
32
|
-
version: 0.2.0
|
33
|
-
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
36
15
|
name: ore-tasks
|
37
|
-
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &21296660 !ruby/object:Gem::Requirement
|
39
17
|
none: false
|
40
|
-
requirements:
|
18
|
+
requirements:
|
41
19
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
- 0
|
45
|
-
- 1
|
46
|
-
- 2
|
47
|
-
version: 0.1.2
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.4'
|
48
22
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: rspec
|
52
23
|
prerelease: false
|
53
|
-
|
24
|
+
version_requirements: *21296660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &21296120 !ruby/object:Gem::Requirement
|
54
28
|
none: false
|
55
|
-
requirements:
|
29
|
+
requirements:
|
56
30
|
- - ~>
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
- 2
|
60
|
-
- 0
|
61
|
-
- 0
|
62
|
-
version: 2.0.0
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.4'
|
63
33
|
type: :development
|
64
|
-
version_requirements: *id003
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: yard
|
67
34
|
prerelease: false
|
68
|
-
|
35
|
+
version_requirements: *21296120
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: yard
|
38
|
+
requirement: &21295620 !ruby/object:Gem::Requirement
|
69
39
|
none: false
|
70
|
-
requirements:
|
40
|
+
requirements:
|
71
41
|
- - ~>
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
- 0
|
75
|
-
- 6
|
76
|
-
- 0
|
77
|
-
version: 0.6.0
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.7'
|
78
44
|
type: :development
|
79
|
-
|
80
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *21295620
|
47
|
+
description: Parameters allows you to add annotated variables to your classes which
|
48
|
+
may have configurable default values.
|
81
49
|
email: postmodern.mod3@gmail.com
|
82
50
|
executables: []
|
83
|
-
|
84
51
|
extensions: []
|
85
|
-
|
86
|
-
|
52
|
+
extra_rdoc_files:
|
53
|
+
- ChangeLog.md
|
54
|
+
- LICENSE.txt
|
87
55
|
- README.md
|
88
|
-
files:
|
56
|
+
files:
|
57
|
+
- .gemtest
|
58
|
+
- .gitignore
|
89
59
|
- .rspec
|
90
60
|
- .yardopts
|
91
61
|
- ChangeLog.md
|
@@ -105,6 +75,25 @@ files:
|
|
105
75
|
- lib/parameters/instance_param.rb
|
106
76
|
- lib/parameters/param.rb
|
107
77
|
- lib/parameters/parameters.rb
|
78
|
+
- lib/parameters/types.rb
|
79
|
+
- lib/parameters/types/array.rb
|
80
|
+
- lib/parameters/types/boolean.rb
|
81
|
+
- lib/parameters/types/class.rb
|
82
|
+
- lib/parameters/types/date.rb
|
83
|
+
- lib/parameters/types/date_time.rb
|
84
|
+
- lib/parameters/types/float.rb
|
85
|
+
- lib/parameters/types/hash.rb
|
86
|
+
- lib/parameters/types/integer.rb
|
87
|
+
- lib/parameters/types/object.rb
|
88
|
+
- lib/parameters/types/proc.rb
|
89
|
+
- lib/parameters/types/regexp.rb
|
90
|
+
- lib/parameters/types/set.rb
|
91
|
+
- lib/parameters/types/string.rb
|
92
|
+
- lib/parameters/types/symbol.rb
|
93
|
+
- lib/parameters/types/time.rb
|
94
|
+
- lib/parameters/types/type.rb
|
95
|
+
- lib/parameters/types/types.rb
|
96
|
+
- lib/parameters/types/uri.rb
|
108
97
|
- lib/parameters/version.rb
|
109
98
|
- parameters.gemspec
|
110
99
|
- spec/class_param_spec.rb
|
@@ -117,39 +106,67 @@ files:
|
|
117
106
|
- spec/instance_param_spec.rb
|
118
107
|
- spec/parameters_spec.rb
|
119
108
|
- spec/spec_helper.rb
|
120
|
-
|
109
|
+
- spec/types/array_spec.rb
|
110
|
+
- spec/types/boolean_spec.rb
|
111
|
+
- spec/types/class_spec.rb
|
112
|
+
- spec/types/date_spec.rb
|
113
|
+
- spec/types/date_time_spec.rb
|
114
|
+
- spec/types/float_spec.rb
|
115
|
+
- spec/types/hash_spec.rb
|
116
|
+
- spec/types/integer_spec.rb
|
117
|
+
- spec/types/object_spec.rb
|
118
|
+
- spec/types/proc_spec.rb
|
119
|
+
- spec/types/regexp_spec.rb
|
120
|
+
- spec/types/set_spec.rb
|
121
|
+
- spec/types/string_spec.rb
|
122
|
+
- spec/types/symbol_spec.rb
|
123
|
+
- spec/types/time_spec.rb
|
124
|
+
- spec/types/types_spec.rb
|
125
|
+
- spec/types/uri_spec.rb
|
121
126
|
homepage: http://github.com/postmodern/parameters
|
122
|
-
licenses:
|
127
|
+
licenses:
|
123
128
|
- MIT
|
124
129
|
post_install_message:
|
125
130
|
rdoc_options: []
|
126
|
-
|
127
|
-
require_paths:
|
131
|
+
require_paths:
|
128
132
|
- lib
|
129
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
134
|
none: false
|
131
|
-
requirements:
|
132
|
-
- -
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
|
135
|
-
|
136
|
-
version: "0"
|
137
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.8.7
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
140
|
none: false
|
139
|
-
requirements:
|
140
|
-
- -
|
141
|
-
- !ruby/object:Gem::Version
|
142
|
-
|
143
|
-
- 0
|
144
|
-
version: "0"
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
145
|
requirements: []
|
146
|
-
|
147
|
-
|
148
|
-
rubygems_version: 1.3.7
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.8.10
|
149
148
|
signing_key:
|
150
149
|
specification_version: 3
|
151
150
|
summary: Allows you to add annotated variables to your classes
|
152
|
-
test_files:
|
153
|
-
- spec/parameters_spec.rb
|
154
|
-
- spec/instance_param_spec.rb
|
151
|
+
test_files:
|
155
152
|
- spec/class_param_spec.rb
|
153
|
+
- spec/instance_param_spec.rb
|
154
|
+
- spec/parameters_spec.rb
|
155
|
+
- spec/types/array_spec.rb
|
156
|
+
- spec/types/boolean_spec.rb
|
157
|
+
- spec/types/class_spec.rb
|
158
|
+
- spec/types/date_spec.rb
|
159
|
+
- spec/types/date_time_spec.rb
|
160
|
+
- spec/types/float_spec.rb
|
161
|
+
- spec/types/hash_spec.rb
|
162
|
+
- spec/types/integer_spec.rb
|
163
|
+
- spec/types/object_spec.rb
|
164
|
+
- spec/types/proc_spec.rb
|
165
|
+
- spec/types/regexp_spec.rb
|
166
|
+
- spec/types/set_spec.rb
|
167
|
+
- spec/types/string_spec.rb
|
168
|
+
- spec/types/symbol_spec.rb
|
169
|
+
- spec/types/time_spec.rb
|
170
|
+
- spec/types/types_spec.rb
|
171
|
+
- spec/types/uri_spec.rb
|
172
|
+
has_rdoc:
|