striuct 0.3.0 → 0.3.1
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.
- data/.gitignore +32 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/History.rdoc +5 -0
- data/Manifest.txt +53 -25
- data/README.md +97 -0
- data/Rakefile +7 -21
- data/examples/README.rb +25 -0
- data/{example → examples}/example1.rb +1 -1
- data/{example → examples}/example2.rb +1 -1
- data/{example → examples}/see_trace.rb +4 -0
- data/lib/striuct/{containable/eigen → classmethods}/basic.rb +13 -5
- data/lib/striuct/classmethods/constants.rb +23 -0
- data/lib/striuct/{containable/eigen → classmethods}/constructor.rb +20 -14
- data/lib/striuct/{containable/eigen → classmethods}/handy.rb +19 -20
- data/lib/striuct/{containable/eigen → classmethods}/inner.rb +10 -32
- data/lib/striuct/{containable/eigen → classmethods}/macro.rb +37 -7
- data/lib/striuct/classmethods/requiremnets.rb +7 -0
- data/lib/striuct/{containable/eigen → classmethods}/safety.rb +6 -6
- data/lib/striuct/classmethods.rb +1 -0
- data/lib/striuct/{containable → instancemethods}/basic.rb +6 -6
- data/lib/striuct/{containable → instancemethods}/handy.rb +3 -3
- data/lib/striuct/{containable → instancemethods}/hashlike.rb +12 -6
- data/lib/striuct/{containable → instancemethods}/inner.rb +9 -8
- data/lib/striuct/instancemethods/requirements.rb +6 -0
- data/lib/striuct/{containable → instancemethods}/safety.rb +2 -2
- data/lib/striuct/instancemethods/singleton_class.rb +19 -0
- data/lib/striuct/instancemethods.rb +1 -0
- data/lib/striuct/requirements.rb +6 -0
- data/lib/striuct/singleton_class.rb +93 -0
- data/lib/striuct/specificcontainer.rb +17 -0
- data/lib/striuct/structs.rb +7 -0
- data/lib/striuct/version.rb +3 -2
- data/lib/striuct.rb +4 -9
- data/striuct.gemspec +24 -0
- data/test/{test_helper.rb → helper.rb} +3 -0
- data/test/test_striuct.rb +23 -1409
- data/test/test_striuct_define.rb +19 -0
- data/test/test_striuct_subclass_adjuster.rb +95 -0
- data/test/test_striuct_subclass_alias_member.rb +54 -0
- data/test/test_striuct_subclass_assign.rb +30 -0
- data/test/test_striuct_subclass_classlock.rb +36 -0
- data/test/test_striuct_subclass_classmethods.rb +87 -0
- data/test/test_striuct_subclass_cloning.rb +36 -0
- data/test/test_striuct_subclass_default_value.rb +129 -0
- data/test/test_striuct_subclass_for_pairs.rb +13 -0
- data/test/test_striuct_subclass_freeze.rb +19 -0
- data/test/test_striuct_subclass_functional_condition.rb +51 -0
- data/test/test_striuct_subclass_getter_validation.rb +33 -0
- data/test/test_striuct_subclass_hashlike.rb +153 -0
- data/test/test_striuct_subclass_inference.rb +51 -0
- data/test/test_striuct_subclass_inheritable.rb +58 -0
- data/test/test_striuct_subclass_instance.rb +289 -0
- data/test/test_striuct_subclass_lock.rb +40 -0
- data/test/test_striuct_subclass_safetynaming.rb +72 -0
- data/test/test_striuct_subclass_specific_conditions.rb +247 -0
- data/test/test_striuct_subclass_to_struct.rb +25 -0
- data/test/test_striuct_version.rb +9 -0
- metadata +106 -68
- data/.gemtest +0 -0
- data/README.rdoc +0 -63
- data/example/example.rb +0 -17
- data/lib/striuct/abstract.rb +0 -74
- data/lib/striuct/containable/classutil.rb +0 -22
- data/lib/striuct/containable/eigen.rb +0 -29
- data/lib/striuct/containable.rb +0 -38
- /data/{example/benchmarks.rb → benchmarks/basics.rb} +0 -0
- /data/{example → examples}/example.old.rdoc +0 -0
@@ -0,0 +1,247 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestStriuctSpecificConditions < Test::Unit::TestCase
|
4
|
+
|
5
|
+
Sth = Striuct.define do
|
6
|
+
member :list_only_int, GENERICS(Integer)
|
7
|
+
member :true_or_false, BOOL?
|
8
|
+
member :like_str, STRINGABLE?
|
9
|
+
member :has_foo, CAN(:foo)
|
10
|
+
member :has_foo_and_bar, CAN(:foo, :bar)
|
11
|
+
member :one_of_member, MEMBER_OF([1, 3])
|
12
|
+
member :has_ignore, AND(1..5, 3..10)
|
13
|
+
member :nand, NAND(1..5, 3..10)
|
14
|
+
member :all_pass, OR(1..5, 3..10)
|
15
|
+
member :catch_error, CATCH(NoMethodError){|v|v.no_name!}
|
16
|
+
member :no_exception, QUIET(->v{v.class})
|
17
|
+
member :not_integer, NOT(Integer)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_not
|
21
|
+
sth = Sth.new
|
22
|
+
|
23
|
+
obj = Object.new
|
24
|
+
|
25
|
+
sth.not_integer = obj
|
26
|
+
assert_same obj, sth.not_integer
|
27
|
+
|
28
|
+
assert_raises Validation::InvalidWritingError do
|
29
|
+
sth.not_integer = 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_still
|
35
|
+
sth = Sth.new
|
36
|
+
|
37
|
+
obj = Object.new
|
38
|
+
|
39
|
+
sth.no_exception = obj
|
40
|
+
assert_same obj, sth.no_exception
|
41
|
+
sth.no_exception = false
|
42
|
+
|
43
|
+
obj.singleton_class.class_eval do
|
44
|
+
undef_method :class
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_raises Validation::InvalidWritingError do
|
48
|
+
sth.no_exception = obj
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_catch
|
53
|
+
sth = Sth.new
|
54
|
+
|
55
|
+
obj = Object.new
|
56
|
+
|
57
|
+
sth.catch_error = obj
|
58
|
+
assert_same obj, sth.catch_error
|
59
|
+
sth.catch_error = false
|
60
|
+
|
61
|
+
obj.singleton_class.class_eval do
|
62
|
+
def no_name!
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_raises Validation::InvalidWritingError do
|
67
|
+
sth.catch_error = obj
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_or
|
72
|
+
sth = Sth.new
|
73
|
+
|
74
|
+
assert_raises Validation::InvalidWritingError do
|
75
|
+
sth.all_pass = 11
|
76
|
+
end
|
77
|
+
|
78
|
+
sth.all_pass = 1
|
79
|
+
assert_equal 1, sth.all_pass
|
80
|
+
sth.all_pass = 4
|
81
|
+
assert_equal 4, sth.all_pass
|
82
|
+
assert_equal true, sth.valid?(:all_pass)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_and
|
86
|
+
sth = Sth.new
|
87
|
+
|
88
|
+
assert_raises Validation::InvalidWritingError do
|
89
|
+
sth.has_ignore = 1
|
90
|
+
end
|
91
|
+
|
92
|
+
assert_raises Validation::InvalidWritingError do
|
93
|
+
sth.has_ignore= 2
|
94
|
+
end
|
95
|
+
|
96
|
+
sth.has_ignore = 3
|
97
|
+
assert_equal 3, sth.has_ignore
|
98
|
+
assert_equal true, sth.valid?(:has_ignore)
|
99
|
+
|
100
|
+
assert_raises Validation::InvalidWritingError do
|
101
|
+
sth.has_ignore = []
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_nand
|
106
|
+
sth = Sth.new
|
107
|
+
|
108
|
+
assert_raises Validation::InvalidWritingError do
|
109
|
+
sth.nand = 4
|
110
|
+
end
|
111
|
+
|
112
|
+
assert_raises Validation::InvalidWritingError do
|
113
|
+
sth.nand = 4.5
|
114
|
+
end
|
115
|
+
|
116
|
+
sth.nand = 2
|
117
|
+
assert_equal 2, sth.nand
|
118
|
+
assert_equal true, sth.valid?(:nand)
|
119
|
+
sth.nand = []
|
120
|
+
assert_equal [], sth.nand
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_member_of
|
124
|
+
sth = Sth.new
|
125
|
+
|
126
|
+
assert_raises Validation::InvalidWritingError do
|
127
|
+
sth.one_of_member = 4
|
128
|
+
end
|
129
|
+
|
130
|
+
sth.one_of_member = 3
|
131
|
+
assert_equal 3, sth.one_of_member
|
132
|
+
assert_equal true, sth.valid?(:one_of_member)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_generics
|
136
|
+
sth = Sth.new
|
137
|
+
|
138
|
+
assert_raises Validation::InvalidWritingError do
|
139
|
+
sth.list_only_int = [1, '2']
|
140
|
+
end
|
141
|
+
|
142
|
+
sth.list_only_int = [1, 2]
|
143
|
+
assert_equal [1, 2], sth.list_only_int
|
144
|
+
assert_equal true, sth.valid?(:list_only_int)
|
145
|
+
sth.list_only_int = []
|
146
|
+
assert_equal [], sth.list_only_int
|
147
|
+
assert_equal true, sth.valid?(:list_only_int)
|
148
|
+
sth.list_only_int << '2'
|
149
|
+
assert_equal false, sth.valid?(:list_only_int)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_boolean
|
153
|
+
sth = Sth.new
|
154
|
+
|
155
|
+
assert_raises Validation::InvalidWritingError do
|
156
|
+
sth.true_or_false = nil
|
157
|
+
end
|
158
|
+
|
159
|
+
assert_equal false, sth.valid?(:true_or_false)
|
160
|
+
|
161
|
+
sth.true_or_false = true
|
162
|
+
assert_equal true, sth.true_or_false
|
163
|
+
assert_equal true, sth.valid?(:true_or_false)
|
164
|
+
sth.true_or_false = false
|
165
|
+
assert_equal false, sth.true_or_false
|
166
|
+
assert_equal true, sth.valid?(:true_or_false)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_stringable
|
170
|
+
sth = Sth.new
|
171
|
+
obj = Object.new
|
172
|
+
|
173
|
+
assert_raises Validation::InvalidWritingError do
|
174
|
+
sth.like_str = obj
|
175
|
+
end
|
176
|
+
|
177
|
+
sth.like_str = 'str'
|
178
|
+
assert_equal true, sth.valid?(:like_str)
|
179
|
+
sth.like_str = :sym
|
180
|
+
assert_equal true, sth.valid?(:like_str)
|
181
|
+
|
182
|
+
obj.singleton_class.class_eval do
|
183
|
+
def to_str
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
sth.like_str = obj
|
188
|
+
assert_equal true, sth.valid?(:like_str)
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_responsible_arg1
|
192
|
+
sth = Sth.new
|
193
|
+
obj = Object.new
|
194
|
+
|
195
|
+
raise if obj.respond_to? :foo
|
196
|
+
|
197
|
+
assert_raises Validation::InvalidWritingError do
|
198
|
+
sth.has_foo = obj
|
199
|
+
end
|
200
|
+
|
201
|
+
obj.singleton_class.class_eval do
|
202
|
+
def foo
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
raise unless obj.respond_to? :foo
|
207
|
+
|
208
|
+
sth.has_foo = obj
|
209
|
+
assert_equal obj, sth.has_foo
|
210
|
+
assert_equal true, sth.valid?(:has_foo)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_responsible_arg2
|
214
|
+
sth = Sth.new
|
215
|
+
obj = Object.new
|
216
|
+
|
217
|
+
raise if obj.respond_to? :foo
|
218
|
+
raise if obj.respond_to? :bar
|
219
|
+
|
220
|
+
assert_raises Validation::InvalidWritingError do
|
221
|
+
sth.has_foo_and_bar = obj
|
222
|
+
end
|
223
|
+
|
224
|
+
obj.singleton_class.class_eval do
|
225
|
+
def foo
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
assert_raises Validation::InvalidWritingError do
|
230
|
+
sth.has_foo_and_bar = obj
|
231
|
+
end
|
232
|
+
|
233
|
+
raise unless obj.respond_to? :foo
|
234
|
+
|
235
|
+
obj.singleton_class.class_eval do
|
236
|
+
def bar
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
raise unless obj.respond_to? :bar
|
241
|
+
|
242
|
+
sth.has_foo_and_bar = obj
|
243
|
+
assert_equal obj, sth.has_foo_and_bar
|
244
|
+
assert_equal true, sth.valid?(:has_foo_and_bar)
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class TestStriuct_to_Struct < Test::Unit::TestCase
|
4
|
+
|
5
|
+
Sth = Striuct.define do
|
6
|
+
member :name, String
|
7
|
+
member :age, Integer
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_to_struct_class
|
11
|
+
klass = Sth.to_struct_class
|
12
|
+
assert_equal 'Striuct::Structs::Sth', klass.to_s
|
13
|
+
assert_same klass, Sth.to_struct_class
|
14
|
+
assert_kind_of Struct, Sth.new.to_struct
|
15
|
+
assert_kind_of Striuct::Structs::Sth, Sth.new.to_struct
|
16
|
+
|
17
|
+
assert_raises RuntimeError do
|
18
|
+
Striuct.new.new.to_struct
|
19
|
+
end
|
20
|
+
|
21
|
+
Striuct.new(:a, :b, :c).new.to_struct
|
22
|
+
assert_equal 1, Striuct::Structs.constants.length
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: striuct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,113 +9,129 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: validation
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.3
|
21
|
+
version: 0.0.3.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rdoc
|
27
|
-
requirement: &25170780 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ~>
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *25170780
|
29
|
+
version: 0.0.3.1
|
36
30
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
31
|
+
name: keyvalidatable
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
39
33
|
none: false
|
40
34
|
requirements:
|
41
35
|
- - ~>
|
42
36
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.
|
44
|
-
type: :
|
37
|
+
version: 0.0.2
|
38
|
+
type: :runtime
|
45
39
|
prerelease: false
|
46
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.2
|
47
46
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
49
|
-
requirement:
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
50
49
|
none: false
|
51
50
|
requirements:
|
52
51
|
- - ! '>='
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
53
|
+
version: 0.8.2.1
|
55
54
|
type: :development
|
56
55
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: hoe
|
60
|
-
requirement: &25168956 !ruby/object:Gem::Requirement
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
57
|
none: false
|
62
58
|
requirements:
|
63
|
-
- -
|
59
|
+
- - ! '>='
|
64
60
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
66
|
-
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *25168956
|
69
|
-
description: Struct++
|
61
|
+
version: 0.8.2.1
|
62
|
+
description: validatable, inheritable, And more Struct++ features :)
|
70
63
|
email:
|
71
64
|
- kachick1+ruby@gmail.com
|
72
65
|
executables: []
|
73
66
|
extensions: []
|
74
|
-
extra_rdoc_files:
|
75
|
-
- History.rdoc
|
76
|
-
- Manifest.txt
|
77
|
-
- README.rdoc
|
78
|
-
- README.ja.old.rdoc
|
79
|
-
- example/example.old.rdoc
|
67
|
+
extra_rdoc_files: []
|
80
68
|
files:
|
69
|
+
- .gitignore
|
70
|
+
- .travis.yml
|
71
|
+
- Gemfile
|
81
72
|
- History.rdoc
|
73
|
+
- LICENSE
|
82
74
|
- Manifest.txt
|
83
|
-
- README.rdoc
|
84
75
|
- README.ja.old.rdoc
|
76
|
+
- README.md
|
85
77
|
- Rakefile
|
86
|
-
-
|
78
|
+
- benchmarks/basics.rb
|
79
|
+
- examples/README.rb
|
80
|
+
- examples/example.old.rdoc
|
81
|
+
- examples/example1.rb
|
82
|
+
- examples/example2.rb
|
83
|
+
- examples/see_trace.rb
|
87
84
|
- lib/striuct.rb
|
85
|
+
- lib/striuct/classmethods.rb
|
86
|
+
- lib/striuct/classmethods/basic.rb
|
87
|
+
- lib/striuct/classmethods/constants.rb
|
88
|
+
- lib/striuct/classmethods/constructor.rb
|
89
|
+
- lib/striuct/classmethods/handy.rb
|
90
|
+
- lib/striuct/classmethods/inner.rb
|
91
|
+
- lib/striuct/classmethods/macro.rb
|
92
|
+
- lib/striuct/classmethods/requiremnets.rb
|
93
|
+
- lib/striuct/classmethods/safety.rb
|
94
|
+
- lib/striuct/instancemethods.rb
|
95
|
+
- lib/striuct/instancemethods/basic.rb
|
96
|
+
- lib/striuct/instancemethods/handy.rb
|
97
|
+
- lib/striuct/instancemethods/hashlike.rb
|
98
|
+
- lib/striuct/instancemethods/inner.rb
|
99
|
+
- lib/striuct/instancemethods/requirements.rb
|
100
|
+
- lib/striuct/instancemethods/safety.rb
|
101
|
+
- lib/striuct/instancemethods/singleton_class.rb
|
102
|
+
- lib/striuct/requirements.rb
|
103
|
+
- lib/striuct/singleton_class.rb
|
104
|
+
- lib/striuct/specificcontainer.rb
|
105
|
+
- lib/striuct/structs.rb
|
88
106
|
- lib/striuct/version.rb
|
89
|
-
-
|
90
|
-
-
|
91
|
-
- lib/striuct/containable/classutil.rb
|
92
|
-
- lib/striuct/containable/basic.rb
|
93
|
-
- lib/striuct/containable/safety.rb
|
94
|
-
- lib/striuct/containable/handy.rb
|
95
|
-
- lib/striuct/containable/hashlike.rb
|
96
|
-
- lib/striuct/containable/inner.rb
|
97
|
-
- lib/striuct/containable/eigen.rb
|
98
|
-
- lib/striuct/containable/eigen/basic.rb
|
99
|
-
- lib/striuct/containable/eigen/constructor.rb
|
100
|
-
- lib/striuct/containable/eigen/safety.rb
|
101
|
-
- lib/striuct/containable/eigen/handy.rb
|
102
|
-
- lib/striuct/containable/eigen/macro.rb
|
103
|
-
- lib/striuct/containable/eigen/inner.rb
|
104
|
-
- test/test_helper.rb
|
107
|
+
- striuct.gemspec
|
108
|
+
- test/helper.rb
|
105
109
|
- test/test_striuct.rb
|
106
|
-
-
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
110
|
-
-
|
111
|
-
-
|
112
|
-
- .
|
113
|
-
|
110
|
+
- test/test_striuct_define.rb
|
111
|
+
- test/test_striuct_subclass_adjuster.rb
|
112
|
+
- test/test_striuct_subclass_alias_member.rb
|
113
|
+
- test/test_striuct_subclass_assign.rb
|
114
|
+
- test/test_striuct_subclass_classlock.rb
|
115
|
+
- test/test_striuct_subclass_classmethods.rb
|
116
|
+
- test/test_striuct_subclass_cloning.rb
|
117
|
+
- test/test_striuct_subclass_default_value.rb
|
118
|
+
- test/test_striuct_subclass_for_pairs.rb
|
119
|
+
- test/test_striuct_subclass_freeze.rb
|
120
|
+
- test/test_striuct_subclass_functional_condition.rb
|
121
|
+
- test/test_striuct_subclass_getter_validation.rb
|
122
|
+
- test/test_striuct_subclass_hashlike.rb
|
123
|
+
- test/test_striuct_subclass_inference.rb
|
124
|
+
- test/test_striuct_subclass_inheritable.rb
|
125
|
+
- test/test_striuct_subclass_instance.rb
|
126
|
+
- test/test_striuct_subclass_lock.rb
|
127
|
+
- test/test_striuct_subclass_safetynaming.rb
|
128
|
+
- test/test_striuct_subclass_specific_conditions.rb
|
129
|
+
- test/test_striuct_subclass_to_struct.rb
|
130
|
+
- test/test_striuct_version.rb
|
131
|
+
homepage: https://github.com/kachick/striuct
|
114
132
|
licenses: []
|
115
133
|
post_install_message:
|
116
|
-
rdoc_options:
|
117
|
-
- --main
|
118
|
-
- README.rdoc
|
134
|
+
rdoc_options: []
|
119
135
|
require_paths:
|
120
136
|
- lib
|
121
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -131,11 +147,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
147
|
- !ruby/object:Gem::Version
|
132
148
|
version: '0'
|
133
149
|
requirements: []
|
134
|
-
rubyforge_project:
|
135
|
-
rubygems_version: 1.8.
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.8.24
|
136
152
|
signing_key:
|
137
153
|
specification_version: 3
|
138
154
|
summary: Struct++
|
139
155
|
test_files:
|
140
|
-
- test/
|
156
|
+
- test/helper.rb
|
141
157
|
- test/test_striuct.rb
|
158
|
+
- test/test_striuct_define.rb
|
159
|
+
- test/test_striuct_subclass_adjuster.rb
|
160
|
+
- test/test_striuct_subclass_alias_member.rb
|
161
|
+
- test/test_striuct_subclass_assign.rb
|
162
|
+
- test/test_striuct_subclass_classlock.rb
|
163
|
+
- test/test_striuct_subclass_classmethods.rb
|
164
|
+
- test/test_striuct_subclass_cloning.rb
|
165
|
+
- test/test_striuct_subclass_default_value.rb
|
166
|
+
- test/test_striuct_subclass_for_pairs.rb
|
167
|
+
- test/test_striuct_subclass_freeze.rb
|
168
|
+
- test/test_striuct_subclass_functional_condition.rb
|
169
|
+
- test/test_striuct_subclass_getter_validation.rb
|
170
|
+
- test/test_striuct_subclass_hashlike.rb
|
171
|
+
- test/test_striuct_subclass_inference.rb
|
172
|
+
- test/test_striuct_subclass_inheritable.rb
|
173
|
+
- test/test_striuct_subclass_instance.rb
|
174
|
+
- test/test_striuct_subclass_lock.rb
|
175
|
+
- test/test_striuct_subclass_safetynaming.rb
|
176
|
+
- test/test_striuct_subclass_specific_conditions.rb
|
177
|
+
- test/test_striuct_subclass_to_struct.rb
|
178
|
+
- test/test_striuct_version.rb
|
179
|
+
has_rdoc:
|
data/.gemtest
DELETED
File without changes
|
data/README.rdoc
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
= Striuct
|
2
|
-
|
3
|
-
* http://github.com/kachick/striuct
|
4
|
-
* http://rubygems.org/gems/striuct
|
5
|
-
* http://rubyforge.org/projects/striuct
|
6
|
-
|
7
|
-
== Description
|
8
|
-
|
9
|
-
Struct++
|
10
|
-
|
11
|
-
== Features
|
12
|
-
|
13
|
-
* Base APIs look like Struct.
|
14
|
-
* Easy and Flexible Validations
|
15
|
-
* Hook just before running setters
|
16
|
-
* Default value
|
17
|
-
* Member aliasing
|
18
|
-
* Inheritable
|
19
|
-
* Pure Ruby :)
|
20
|
-
|
21
|
-
== Usage
|
22
|
-
|
23
|
-
* setup
|
24
|
-
require 'striuct'
|
25
|
-
|
26
|
-
=== Example
|
27
|
-
|
28
|
-
Person = Striuct.define do
|
29
|
-
member :name, AND(String, /\A\w+( \w+)?\z/)
|
30
|
-
end
|
31
|
-
|
32
|
-
class User < Person
|
33
|
-
member :id, AND(Integer, 1..99999)
|
34
|
-
end
|
35
|
-
|
36
|
-
user = User.new
|
37
|
-
user.members #=> [:name, :id]
|
38
|
-
user.name = :Ken #=> error
|
39
|
-
user.name = '' #=> error
|
40
|
-
user.name = 'Ken' #=> pass
|
41
|
-
|
42
|
-
=== More Example
|
43
|
-
|
44
|
-
example/*
|
45
|
-
|
46
|
-
== Requirements
|
47
|
-
|
48
|
-
* Ruby 1.9.2 or later
|
49
|
-
|
50
|
-
tested release versions
|
51
|
-
|
52
|
-
* 1.9.3-p125
|
53
|
-
* 1.9.2-p290
|
54
|
-
|
55
|
-
== Installation
|
56
|
-
|
57
|
-
* gem install striuct
|
58
|
-
|
59
|
-
== License
|
60
|
-
|
61
|
-
Copyright (C) 2011 Kenichi Kamiya
|
62
|
-
|
63
|
-
The MIT License (See the file LICENSE.)
|
data/example/example.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$VERBOSE = true
|
2
|
-
|
3
|
-
require '../lib/striuct'
|
4
|
-
|
5
|
-
Person = Striuct.define do
|
6
|
-
member :name, AND(String, /\A\w+( \w+)?\z/)
|
7
|
-
end
|
8
|
-
|
9
|
-
class User < Person
|
10
|
-
member :id, AND(Integer, 1..99999)
|
11
|
-
end
|
12
|
-
|
13
|
-
user = User.new
|
14
|
-
p user.members #=> [:name, :id]
|
15
|
-
p user.name = :Ken #=> error
|
16
|
-
p user.name = '' #=> error
|
17
|
-
p user.name = 'Ken' #=> pass
|
data/lib/striuct/abstract.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require_relative 'containable'
|
2
|
-
|
3
|
-
class Striuct; class << self
|
4
|
-
# @group Constructor
|
5
|
-
|
6
|
-
alias_method :new_instance, :new
|
7
|
-
private :new_instance
|
8
|
-
|
9
|
-
# @param [Symbol, String] *names
|
10
|
-
# @return [Class] - with Subclass, Subclass:Eigen
|
11
|
-
def new(*names, &block)
|
12
|
-
# warning for Ruby's Struct.new user
|
13
|
-
first = names.first
|
14
|
-
if first.instance_of?(String) and /\A[A-Z]/ =~ first
|
15
|
-
warn "no define constant #{first}"
|
16
|
-
end
|
17
|
-
|
18
|
-
Class.new self do
|
19
|
-
names.each do |name|
|
20
|
-
member name
|
21
|
-
end
|
22
|
-
|
23
|
-
class_eval(&block) if block_given?
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# @yieldreturn [Class] (see Striuct.new) - reject floating class
|
28
|
-
# @return [void]
|
29
|
-
def define(&block)
|
30
|
-
raise ArgumentError, 'must with block' unless block_given?
|
31
|
-
|
32
|
-
new(&block).tap do |subclass|
|
33
|
-
subclass.instance_eval do
|
34
|
-
raise 'not yet finished' if members.empty?
|
35
|
-
close
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# @groupend
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
alias_method :original_inherited, :inherited
|
45
|
-
|
46
|
-
def inherited(subclass)
|
47
|
-
attributes = (
|
48
|
-
if equal? ::Striuct
|
49
|
-
[[], {}, {}, {}, {}, {}, {}, {}, :prevent]
|
50
|
-
else
|
51
|
-
[*[@names, @conditions, @flavors, @defaults,\
|
52
|
-
@inferences, @aliases, @setter_validations, @getter_validations].map(&:dup), @protect_level]
|
53
|
-
end
|
54
|
-
)
|
55
|
-
|
56
|
-
eigen = self
|
57
|
-
|
58
|
-
subclass.class_eval do
|
59
|
-
original_inherited subclass
|
60
|
-
include Containable if ::Striuct.equal? eigen
|
61
|
-
|
62
|
-
@names, @conditions, @flavors, @defaults,\
|
63
|
-
@inferences, @aliases, @setter_validations, @getter_validations, @protect_level = *attributes
|
64
|
-
|
65
|
-
singleton_class.instance_eval do
|
66
|
-
define_method :initialize_copy do |original|
|
67
|
-
@names, @flavors, @defaults, @aliases, @setter_validations, @getter_validations =
|
68
|
-
*[@names, @flavors, @defaults, @aliases, @setter_validations, @getter_validations].map(&:dup)
|
69
|
-
@conditions, @inferences = @conditions.dup, @inferences.dup
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end; end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
class Striuct; module Containable
|
2
|
-
|
3
|
-
|
4
|
-
# @author Kenichi Kamiya
|
5
|
-
module ClassUtil
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def delegate_class_method(name)
|
10
|
-
define_method name do |*args, &block|
|
11
|
-
self.class.__send__ name, *args, &block
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def delegate_class_methods(name, *names)
|
16
|
-
[name, *names].each{|_name|delegate_class_method _name}
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
end; end
|