striuct 0.4.4.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/MIT-LICENSE.txt +21 -0
- data/README.md +45 -62
- data/lib/striuct.rb +7 -3
- data/lib/striuct/{requirements.rb → bootstrap.rb} +6 -2
- data/lib/striuct/classmethods/README.md +2 -2
- data/lib/striuct/classmethods/adjustment.rb +77 -13
- data/lib/striuct/classmethods/attributes.rb +94 -90
- data/lib/striuct/classmethods/conflict_management.rb +109 -106
- data/lib/striuct/classmethods/constructor.rb +55 -65
- data/lib/striuct/classmethods/copy.rb +45 -43
- data/lib/striuct/classmethods/default.rb +23 -21
- data/lib/striuct/classmethods/enum.rb +46 -44
- data/lib/striuct/classmethods/fix.rb +23 -21
- data/lib/striuct/classmethods/hashdeepdupulicatable.rb +15 -15
- data/lib/striuct/classmethods/inner.rb +57 -64
- data/lib/striuct/classmethods/length.rb +12 -10
- data/lib/striuct/classmethods/macro.rb +98 -111
- data/lib/striuct/classmethods/names.rb +69 -65
- data/lib/striuct/classmethods/predicate.rb +131 -138
- data/lib/striuct/classmethods/requirements.rb +2 -2
- data/lib/striuct/classmethods/to_struct.rb +21 -18
- data/lib/striuct/classmethods/validation.rb +15 -13
- data/lib/striuct/instancemethods/README.md +2 -2
- data/lib/striuct/instancemethods/assign.rb +29 -27
- data/lib/striuct/instancemethods/cast.rb +28 -26
- data/lib/striuct/instancemethods/compare.rb +26 -24
- data/lib/striuct/instancemethods/default.rb +31 -29
- data/lib/striuct/instancemethods/delegate_class_methods.rb +36 -32
- data/lib/striuct/instancemethods/enum.rb +86 -84
- data/lib/striuct/instancemethods/getter.rb +39 -37
- data/lib/striuct/instancemethods/hashy.rb +99 -97
- data/lib/striuct/instancemethods/lock.rb +46 -44
- data/lib/striuct/instancemethods/object.rb +50 -48
- data/lib/striuct/instancemethods/requirements.rb +9 -13
- data/lib/striuct/instancemethods/safety.rb +11 -9
- data/lib/striuct/instancemethods/setter.rb +46 -49
- data/lib/striuct/instancemethods/to_s.rb +39 -37
- data/lib/striuct/instancemethods/validation.rb +46 -29
- data/lib/striuct/instancemethods/values.rb +52 -33
- data/lib/striuct/singleton_class.rb +25 -18
- data/lib/striuct/structs.rb +3 -3
- metadata +23 -213
- data/.gitignore +0 -35
- data/.travis.yml +0 -20
- data/.yardopts +0 -1
- data/Gemfile +0 -11
- data/History.old(~0.3.n).rdoc +0 -289
- data/MIT-LICENSE +0 -22
- data/Rakefile +0 -10
- data/benchmark/basics.rb +0 -56
- data/example/README.rb +0 -53
- data/example/example1.rb +0 -235
- data/example/example2.rb +0 -22
- data/example/see_trace.rb +0 -32
- data/lib/striuct/instancemethods/keyvalidatable.rb +0 -9
- data/striuct.gemspec +0 -45
- data/test/helper.rb +0 -5
- data/test/test_sglc-constructor.rb +0 -36
- data/test/test_subc-c-add_members.rb +0 -13
- data/test/test_subc-c-close_member.rb +0 -36
- data/test/test_subc-c-constructor.rb +0 -92
- data/test/test_subc-c-copy.rb +0 -71
- data/test/test_subc-c-freeze.rb +0 -36
- data/test/test_subc-c-inheritable.rb +0 -58
- data/test/test_subc-c-safety_naming.rb +0 -73
- data/test/test_subc-f-alias_member.rb +0 -54
- data/test/test_subc-f-enum.rb +0 -139
- data/test/test_subc-f-predicate.rb +0 -711
- data/test/test_subc-f-to_struct.rb +0 -61
- data/test/test_subc-f-validation_util.rb +0 -59
- data/test/test_subc-f_debug.rb +0 -39
- data/test/test_subc-f_name.rb +0 -525
- data/test/test_subc-i-accessor.rb +0 -138
- data/test/test_subc-i-adjuster.rb +0 -95
- data/test/test_subc-i-assign.rb +0 -53
- data/test/test_subc-i-basic.rb +0 -32
- data/test/test_subc-i-cast.rb +0 -27
- data/test/test_subc-i-compare.rb +0 -52
- data/test/test_subc-i-copy.rb +0 -23
- data/test/test_subc-i-default_value.rb +0 -129
- data/test/test_subc-i-freeze.rb +0 -19
- data/test/test_subc-i-hashlike.rb +0 -144
- data/test/test_subc-i-keyvalidatable.rb +0 -25
- data/test/test_subc-i-lock.rb +0 -40
- data/test/test_subc-i-must.rb +0 -30
- data/test/test_subc-i-to_s_family.rb +0 -26
- data/test/test_subc-i-validation_inference.rb +0 -51
- data/test/test_subc-i-validation_specific_conditions.rb +0 -297
- data/test/test_subc-i-validation_with_getter.rb +0 -33
- data/test/test_version.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d820670e757190ed2db502b8d6e0c53a7689f299262695f3ca18cec69dd5270b
|
4
|
+
data.tar.gz: 8a27cca712c9a63c2a5207090a6a8d0d8dcecd24a13bf07fa16c243a3b24c366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c90d1e6cc1ac20015660134d88d863dc935d6db44128e0f49f7c807b6b357d4821055d989e9e9e3a8bb4c49382acbab04509bf0445389a454c72c3fb729cbd85
|
7
|
+
data.tar.gz: a7154a914174099a8b5d32fe4b534811c14187f3fb9e8735cba701764b7d9aee640de1c276711dcedb85915f33efc9fecac87dde0ae8a09d704d0bbf84f3f11b
|
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Kenichi Kamiya
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,51 +1,40 @@
|
|
1
|
-
striuct
|
2
|
-
=======
|
1
|
+
# striuct
|
3
2
|
|
4
|
-
|
3
|
+
![Build Status](https://github.com/kachick/striuct/actions/workflows/test_behaviors.yml/badge.svg?branch=main)
|
5
4
|
[![Gem Version](https://badge.fury.io/rb/striuct.png)](http://badge.fury.io/rb/striuct)
|
6
5
|
|
7
|
-
Description
|
8
|
-
-----------
|
9
|
-
|
10
6
|
Struct++
|
11
7
|
|
12
|
-
|
13
|
-
--------
|
8
|
+
## Usage
|
14
9
|
|
15
|
-
|
10
|
+
Require Ruby 2.6 or later
|
16
11
|
|
17
|
-
|
18
|
-
* Prevent to conflict member names
|
19
|
-
* Lock setters for each member
|
12
|
+
Add this line to your `Gemfile`
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
* Default value
|
25
|
-
* Member aliasing
|
26
|
-
* Inheritable
|
27
|
-
* Handling between nil <-> unassigned
|
28
|
-
* More flendly API for Hash
|
14
|
+
```ruby
|
15
|
+
gem 'striuct', '>= 0.8.0', '< 0.9.0'
|
16
|
+
```
|
29
17
|
|
30
|
-
|
18
|
+
Then add below code into your Ruby code
|
31
19
|
|
32
|
-
|
33
|
-
|
20
|
+
```ruby
|
21
|
+
require 'striuct'
|
22
|
+
```
|
34
23
|
|
35
|
-
|
36
|
-
-----
|
24
|
+
### Overview
|
37
25
|
|
38
|
-
|
26
|
+
#### Case 1
|
39
27
|
|
40
28
|
```ruby
|
41
29
|
require 'striuct'
|
42
30
|
|
43
31
|
class Person < Striuct
|
44
|
-
member :
|
45
|
-
alias_member :name, :
|
32
|
+
member :full_name, AND(String, /\A.+\z/) # Flexible Validation
|
33
|
+
alias_member :name, :full_name # Use other name
|
46
34
|
end
|
47
35
|
|
48
|
-
|
36
|
+
# Inheritable
|
37
|
+
class User < Person
|
49
38
|
member :id, Integer, # Looks typed validation
|
50
39
|
default_proc: ->{User.next_id} # With default value
|
51
40
|
|
@@ -56,26 +45,26 @@ class User < Person # Inheritable
|
|
56
45
|
end
|
57
46
|
|
58
47
|
john = User.new 'john'
|
59
|
-
john[:name] #=> 'john'
|
48
|
+
john[:name] #=> 'john'
|
60
49
|
john.name = '' #=> Exception # Validate with setter
|
61
50
|
john.id #=> 1
|
62
51
|
ken = User[name: 'ken'] # Construct from hash
|
63
52
|
ken.id #=> 2
|
64
53
|
```
|
65
|
-
|
54
|
+
|
55
|
+
#### Case 2
|
66
56
|
|
67
57
|
```ruby
|
68
58
|
class Foo < Striuct
|
69
59
|
member :foo
|
70
|
-
member :bar, Numeric
|
71
|
-
inference: true # And use inference Validation
|
60
|
+
member :bar, Numeric
|
72
61
|
member :with_adjuster, Integer,
|
73
62
|
&->v{Integer v} # Use adjuster before a setter
|
74
63
|
end
|
75
64
|
|
76
65
|
foo = Foo.new
|
77
66
|
|
78
|
-
# nil <->
|
67
|
+
# nil <-> unassigned
|
79
68
|
foo.foo #=> nil
|
80
69
|
foo.assigned?(:foo) #=> false
|
81
70
|
foo.foo = nil
|
@@ -85,7 +74,6 @@ foo.assigned?(:foo) #=> true
|
|
85
74
|
foo.lock(:foo)
|
86
75
|
foo.foo = nil #=> error
|
87
76
|
|
88
|
-
# Inference Validation
|
89
77
|
foo.bar = 1.2 #=> pass # memorize 1.2's class is Float
|
90
78
|
foo.bar = 1 #=> error # 1 is not Float
|
91
79
|
|
@@ -94,7 +82,7 @@ foo.with_adjuster = '5'
|
|
94
82
|
foo.with_adjuster #=> 5 # Casted via adjuster
|
95
83
|
```
|
96
84
|
|
97
|
-
|
85
|
+
#### Case 3
|
98
86
|
|
99
87
|
```ruby
|
100
88
|
class UseMustOption < Striuct
|
@@ -104,37 +92,32 @@ end
|
|
104
92
|
UseMustOption.new #=> InvalidOperationError "`foo` require a value under `must` option "
|
105
93
|
```
|
106
94
|
|
95
|
+
## Features
|
107
96
|
|
108
|
-
###
|
109
|
-
|
110
|
-
* That from validation library.
|
111
|
-
See the [validation-API](http://kachick.github.com/validation/yard/frames.html)
|
112
|
-
|
113
|
-
Requirements
|
114
|
-
-------------
|
97
|
+
### Strict
|
115
98
|
|
116
|
-
*
|
99
|
+
* Easy and Flexible Validations
|
100
|
+
* Basically use `#===` for the validation
|
101
|
+
* The pattern builder DSL is just using [eqq](https://github.com/kachick/eqq)
|
102
|
+
* When passed the Proc, it will be evaluated in the instance context
|
103
|
+
* Prevent to conflict member names
|
104
|
+
* Lock setters for each member
|
117
105
|
|
118
|
-
|
119
|
-
-------
|
106
|
+
### Useful
|
120
107
|
|
121
|
-
|
122
|
-
|
123
|
-
|
108
|
+
* Hook just before setters
|
109
|
+
* Default value
|
110
|
+
* Member aliasing
|
111
|
+
* Inheritable
|
112
|
+
* Handling between nil <-> unassigned
|
113
|
+
* Similar API for Hash
|
124
114
|
|
125
|
-
|
126
|
-
----
|
115
|
+
### Finally
|
127
116
|
|
128
|
-
*
|
129
|
-
*
|
130
|
-
* [API](http://kachick.github.com/striuct/yard/frames.html)
|
131
|
-
* [issues](https://github.com/kachick/striuct/issues)
|
132
|
-
* [CI](http://travis-ci.org/#!/kachick/striuct)
|
133
|
-
* [gem](https://rubygems.org/gems/striuct)
|
117
|
+
* Base API looks like Struct
|
118
|
+
* Pure Ruby :)
|
134
119
|
|
135
|
-
|
136
|
-
--------
|
120
|
+
## Link
|
137
121
|
|
138
|
-
|
139
|
-
|
140
|
-
See MIT-LICENSE for further details.
|
122
|
+
* [Repository](https://github.com/kachick/striuct)
|
123
|
+
* [API documents](https://kachick.github.io/striuct/)
|
data/lib/striuct.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# striuct - Struct++
|
2
4
|
# Copyright (c) 2011-2012 Kenichi Kamiya
|
3
5
|
|
4
6
|
# @abstract
|
5
7
|
class Striuct
|
6
|
-
|
7
8
|
class Error < StandardError; end
|
8
9
|
class InvalidOperationError < Error; end
|
9
|
-
|
10
|
+
class InvalidValueError < Error; end
|
11
|
+
class InvalidWritingError < InvalidValueError; end
|
12
|
+
class InvalidReadingError < InvalidValueError; end
|
13
|
+
class InvalidAdjustingError < InvalidValueError; end
|
10
14
|
end
|
11
15
|
|
12
|
-
require_relative 'striuct/
|
16
|
+
require_relative 'striuct/bootstrap'
|
@@ -1,5 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'eqq'
|
5
|
+
|
2
6
|
require_relative 'structs'
|
3
7
|
require_relative 'classmethods/requirements'
|
4
8
|
require_relative 'instancemethods/requirements'
|
5
|
-
require_relative 'singleton_class'
|
9
|
+
require_relative 'singleton_class'
|
@@ -1,15 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Striuct
|
4
|
+
module ClassMethods
|
5
|
+
# @group Adjuster
|
6
|
+
|
7
|
+
# Adjuster Builders
|
8
|
+
# Apply adjuster when passed pattern.
|
9
|
+
# @param pattern [Proc, Method, #===]
|
10
|
+
# @param adjuster [Proc, #to_proc]
|
11
|
+
# @return [Proc]
|
12
|
+
def WHEN(pattern, adjuster)
|
13
|
+
unless Eqq.valid?(pattern)
|
14
|
+
raise ArgumentError, 'wrong object for pattern'
|
15
|
+
end
|
16
|
+
|
17
|
+
unless Striuct.adjustable?(adjuster)
|
18
|
+
raise ArgumentError, 'wrong object for adjuster'
|
19
|
+
end
|
20
|
+
|
21
|
+
->v { _valid?(pattern, v) ? adjuster.call(v) : v }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Sequential apply all adjusters.
|
25
|
+
# @param adjuster1 [Proc, #to_proc]
|
26
|
+
# @param adjuster2 [Proc, #to_proc]
|
27
|
+
# @param adjusters [Proc, #to_proc]
|
28
|
+
# @return [Proc]
|
29
|
+
def INJECT(adjuster1, adjuster2, *adjusters)
|
30
|
+
adjusters = [adjuster1, adjuster2, *adjusters]
|
12
31
|
|
13
|
-
|
32
|
+
unless adjusters.all? { |f| adjustable?(f) }
|
33
|
+
raise ArgumentError, 'wrong object for adjuster'
|
34
|
+
end
|
14
35
|
|
15
|
-
|
36
|
+
->v {
|
37
|
+
adjusters.reduce(v) { |ret, adjuster| adjuster.call(ret) }
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
# Accept any parser when that respond to parse method.
|
42
|
+
# @param parser [#parse]
|
43
|
+
# @return [Proc]
|
44
|
+
def PARSE(parser)
|
45
|
+
if !::Integer.equal?(parser) && !parser.respond_to?(:parse)
|
46
|
+
raise ArgumentError, 'wrong object for parser'
|
47
|
+
end
|
48
|
+
|
49
|
+
->v {
|
50
|
+
if ::Integer.equal?(parser)
|
51
|
+
::Kernel.Integer(v)
|
52
|
+
else
|
53
|
+
parser.parse(
|
54
|
+
case v
|
55
|
+
when String
|
56
|
+
v
|
57
|
+
when ->_ { v.respond_to?(:to_str) }
|
58
|
+
v.to_str
|
59
|
+
when ->_ { v.respond_to?(:read) }
|
60
|
+
v.read
|
61
|
+
else
|
62
|
+
raise TypeError, 'wrong object for parsing source'
|
63
|
+
end
|
64
|
+
)
|
65
|
+
end
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
70
|
+
def adjuster_for(key)
|
71
|
+
autonym = autonym_for_key(key)
|
72
|
+
raise KeyError unless with_adjuster?(autonym)
|
73
|
+
|
74
|
+
_attributes_for(autonym).adjuster
|
75
|
+
end
|
76
|
+
|
77
|
+
# @endgroup
|
78
|
+
end
|
79
|
+
end
|
@@ -1,112 +1,116 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
define_method :"with_#{role}?" do
|
23
|
-
@hash.has_key? role
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Striuct
|
4
|
+
module ClassMethods
|
5
|
+
# Attributes for autonym of each member
|
6
|
+
class Attributes
|
7
|
+
VALUES = [:condition,
|
8
|
+
:adjuster].freeze
|
9
|
+
|
10
|
+
BOOLEANS = [
|
11
|
+
:must,
|
12
|
+
:safety_setter,
|
13
|
+
:safety_getter
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@hash = {
|
18
|
+
must: false,
|
19
|
+
safety_setter: false,
|
20
|
+
safety_getter: false
|
21
|
+
}
|
24
22
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
|
24
|
+
VALUES.each do |role|
|
25
|
+
define_method :"with_#{role}?" do
|
26
|
+
@hash.key?(role)
|
27
|
+
end
|
28
|
+
|
29
|
+
define_method role do
|
30
|
+
@hash.fetch(role)
|
31
|
+
end
|
28
32
|
end
|
29
|
-
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
def condition=(condition)
|
35
|
+
unless Eqq.valid?(condition)
|
36
|
+
raise TypeError, 'wrong object for condition'
|
37
|
+
end
|
38
|
+
|
39
|
+
@hash[:condition] = condition
|
34
40
|
end
|
35
41
|
|
36
|
-
|
37
|
-
|
42
|
+
def adjuster=(adjuster)
|
43
|
+
unless Striuct.adjustable?(adjuster)
|
44
|
+
raise ArgumentError, 'wrong object for adjuster'
|
45
|
+
end
|
38
46
|
|
39
|
-
|
40
|
-
unless ::Validation.adjustable? adjuster
|
41
|
-
raise ArgumentError, 'wrong object for adjuster'
|
47
|
+
@hash[:adjuster] = adjuster
|
42
48
|
end
|
43
49
|
|
44
|
-
|
45
|
-
|
50
|
+
BOOLEANS.each do |role|
|
51
|
+
define_method :"with_#{role}?" do
|
52
|
+
@hash.fetch(role)
|
53
|
+
end
|
54
|
+
|
55
|
+
define_method :"#{role}=" do |arg|
|
56
|
+
raise TypeError unless arg.equal?(true) || arg.equal?(false)
|
46
57
|
|
47
|
-
|
48
|
-
|
49
|
-
@hash.fetch role
|
58
|
+
@hash[role] = arg
|
59
|
+
end
|
50
60
|
end
|
51
|
-
|
52
|
-
define_method :"#{role}=" do |arg|
|
53
|
-
raise TypeError unless arg.equal?(true) or arg.equal?(false)
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
|
62
|
+
def with_default?
|
63
|
+
@hash.key?(:default_value)
|
64
|
+
end
|
58
65
|
|
59
|
-
|
60
|
-
|
61
|
-
|
66
|
+
def default_value
|
67
|
+
@hash.fetch(:default_value)
|
68
|
+
end
|
62
69
|
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
def default_type
|
71
|
+
@hash.fetch(:default_type)
|
72
|
+
end
|
66
73
|
|
67
|
-
|
68
|
-
|
69
|
-
|
74
|
+
# @param [Symbol] type - :value / :lazy
|
75
|
+
def set_default(value, type)
|
76
|
+
raise TypeError unless type.equal?(:value) || type.equal?(:lazy)
|
70
77
|
|
71
|
-
|
72
|
-
def set_default(value, type)
|
73
|
-
raise TypeError unless type.equal?(:value) or type.equal?(:lazy)
|
74
|
-
check_default_lazy_proc value if type.equal?(:lazy)
|
75
|
-
|
76
|
-
@hash[:default_type] = type
|
77
|
-
@hash[:default_value] = value
|
78
|
-
end
|
78
|
+
check_default_lazy_proc(value) if type.equal?(:lazy)
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
arity = _proc.arity
|
83
|
-
unless arity <= 2
|
84
|
-
raise ArgumentError, "wrong number of block parameter #{arity} for 0..2"
|
80
|
+
@hash[:default_type] = type
|
81
|
+
@hash[:default_value] = value
|
85
82
|
end
|
86
|
-
end
|
87
83
|
|
88
|
-
|
89
|
-
|
90
|
-
@hash.freeze
|
91
|
-
ret
|
92
|
-
end
|
84
|
+
def check_default_lazy_proc(proc)
|
85
|
+
raise TypeError unless proc.respond_to?(:call)
|
93
86
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def initialize_copy(original)
|
103
|
-
ret = super original
|
104
|
-
@hash = @hash.dup
|
105
|
-
ret
|
106
|
-
end
|
87
|
+
arity = proc.arity
|
88
|
+
unless arity <= 2
|
89
|
+
raise ArgumentError, "wrong number of block parameter #{arity} for 0..2"
|
90
|
+
end
|
91
|
+
end
|
107
92
|
|
108
|
-
|
93
|
+
def freeze
|
94
|
+
ret = super
|
95
|
+
@hash.freeze
|
96
|
+
ret
|
97
|
+
end
|
98
|
+
|
99
|
+
def dup
|
100
|
+
ret = super
|
101
|
+
@hash = @hash.dup
|
102
|
+
ret
|
103
|
+
end
|
109
104
|
|
110
|
-
|
105
|
+
private
|
111
106
|
|
112
|
-
|
107
|
+
def initialize_copy(original)
|
108
|
+
ret = super(original)
|
109
|
+
@hash = @hash.dup
|
110
|
+
ret
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
private_constant :Attributes
|
115
|
+
end
|
116
|
+
end
|