l43_open_object 0.4.3 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/l43/open_object/version.rb +1 -1
- data/lib/l43/{typed_object → typed_class}/behavior.rb +1 -1
- data/lib/l43/{typed_object → typed_class}/constants.rb +1 -1
- data/lib/l43/typed_class/description/hidden.rb +34 -0
- data/lib/l43/typed_class/description.rb +25 -0
- data/lib/l43/{typed_object → typed_class}/impl_helper.rb +5 -3
- data/lib/l43/{typed_object → typed_class}/implementation.rb +1 -1
- data/lib/l43/{typed_object.rb → typed_class.rb} +7 -5
- metadata +8 -7
- data/lib/l43/typed_object/description.rb +0 -45
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7f7fc44fb3888a0fd0ba528947c0941aed333c9137a3951cf386d9cf417912a7
|
|
4
|
+
data.tar.gz: edd172d163970f148337fbcdab40f2f0d0021eb5fda9f40fdbb17bc3c43caa37
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 884418b5c75ca3161d48fcf79a9b0901b3b2fbfdba7ab31cd96f30b35c408866f8bb623d65e629b831c6f374ce958878ca3b3f0ebd2f3c5496905ca862fada68
|
|
7
|
+
data.tar.gz: b46d6021ccd011e69da8cf319d74cb6807aaadeb79779c4262043d0018394bff4e1ec47f819fb0bf01b1a0bae55c109f58c306ca4f3281e4402a41d849db27f6
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module L43
|
|
4
|
+
module TypedClass
|
|
5
|
+
class Description
|
|
6
|
+
module Hidden
|
|
7
|
+
def check_types!
|
|
8
|
+
ImplHelper.check_value_errors!(args: defaults, attributes:)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def implement =
|
|
12
|
+
Implementation.new(klass:, attributes:, defaults:, callable:)
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
def attributes = @__atts_6B9l39xVLR8UnX5U.freeze
|
|
16
|
+
def callable = @__callable_6B9l39xVLR8UnX5U
|
|
17
|
+
|
|
18
|
+
attr_reader :klass
|
|
19
|
+
|
|
20
|
+
def defaults
|
|
21
|
+
@__defaults__ ||= attributes.inject({}) do |defaults, (name, desc)|
|
|
22
|
+
if desc.default == None
|
|
23
|
+
defaults
|
|
24
|
+
else
|
|
25
|
+
defaults.merge(name => desc.default)
|
|
26
|
+
end
|
|
27
|
+
end.freeze
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ostruct'
|
|
4
|
+
require_relative 'implementation'
|
|
5
|
+
module L43
|
|
6
|
+
module TypedClass
|
|
7
|
+
class Description
|
|
8
|
+
private
|
|
9
|
+
def initialize(klass)
|
|
10
|
+
@klass = klass
|
|
11
|
+
@__atts_6B9l39xVLR8UnX5U = {}
|
|
12
|
+
@__callable_6B9l39xVLR8UnX5U = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def attr(name, default: None, as: None, nullable: false, &blk)
|
|
16
|
+
@__atts_6B9l39xVLR8UnX5U.update(name => OpenStruct.new(default:, type: as, constraint: blk, nullable:))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def make_callable(&blk)
|
|
20
|
+
@__callable_6B9l39xVLR8UnX5U = blk
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module L43
|
|
4
|
-
module
|
|
4
|
+
module TypedClass
|
|
5
5
|
module ImplHelper extend self
|
|
6
6
|
def check_for_missing!(actual:, required:)
|
|
7
7
|
missing = required - actual
|
|
@@ -17,8 +17,10 @@ module L43
|
|
|
17
17
|
raise SpuriousAttribute, "the following attributes have not been defined on this class: #{spurious.inspect}"
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def check_type(type, value)
|
|
20
|
+
def check_type(type, value, nullable:)
|
|
21
21
|
return if None == type
|
|
22
|
+
return if value.nil? && nullable
|
|
23
|
+
|
|
22
24
|
case type
|
|
23
25
|
when Array
|
|
24
26
|
return true unless type.member?(value)
|
|
@@ -28,7 +30,7 @@ module L43
|
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def check_value(desc, value)
|
|
31
|
-
return :type if check_type(desc.type, value)
|
|
33
|
+
return :type if check_type(desc.type, value, nullable: desc.nullable)
|
|
32
34
|
case desc.constraint
|
|
33
35
|
when nil
|
|
34
36
|
nil
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative '
|
|
4
|
-
require_relative '
|
|
3
|
+
require_relative 'typed_class/constants'
|
|
4
|
+
require_relative 'typed_class/description'
|
|
5
|
+
require_relative 'typed_class/description/hidden'
|
|
5
6
|
module L43
|
|
6
|
-
module
|
|
7
|
+
module TypedClass
|
|
7
8
|
def def_atts(&blk)
|
|
8
9
|
desc = Description.new(self)
|
|
9
10
|
desc.instance_eval(&blk)
|
|
11
|
+
desc.extend Description::Hidden
|
|
10
12
|
desc.check_types!
|
|
11
13
|
desc.implement
|
|
12
14
|
end
|
|
@@ -21,9 +23,9 @@ module L43
|
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
def make(&blk)
|
|
24
|
-
|
|
26
|
+
typed_class = self
|
|
25
27
|
Class.new do
|
|
26
|
-
extend
|
|
28
|
+
extend typed_class
|
|
27
29
|
def_atts(&blk)
|
|
28
30
|
end
|
|
29
31
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: l43_open_object
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Dober
|
|
@@ -42,12 +42,13 @@ files:
|
|
|
42
42
|
- lib/l43/open_object/behavior.rb
|
|
43
43
|
- lib/l43/open_object/initializer.rb
|
|
44
44
|
- lib/l43/open_object/version.rb
|
|
45
|
-
- lib/l43/
|
|
46
|
-
- lib/l43/
|
|
47
|
-
- lib/l43/
|
|
48
|
-
- lib/l43/
|
|
49
|
-
- lib/l43/
|
|
50
|
-
- lib/l43/
|
|
45
|
+
- lib/l43/typed_class.rb
|
|
46
|
+
- lib/l43/typed_class/behavior.rb
|
|
47
|
+
- lib/l43/typed_class/constants.rb
|
|
48
|
+
- lib/l43/typed_class/description.rb
|
|
49
|
+
- lib/l43/typed_class/description/hidden.rb
|
|
50
|
+
- lib/l43/typed_class/impl_helper.rb
|
|
51
|
+
- lib/l43/typed_class/implementation.rb
|
|
51
52
|
homepage: https://codeberg.org/lab419/l43_open_object
|
|
52
53
|
licenses:
|
|
53
54
|
- AGPL-3.0-or-later
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'ostruct'
|
|
4
|
-
require_relative 'implementation'
|
|
5
|
-
module L43
|
|
6
|
-
module TypedObject
|
|
7
|
-
class Description
|
|
8
|
-
|
|
9
|
-
def check_types!
|
|
10
|
-
ImplHelper.check_value_errors!(args: defaults, attributes:)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def implement =
|
|
14
|
-
Implementation.new(klass:, attributes: attributes.freeze, defaults:, callable:)
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
attr_reader :allowed, :callable, :klass, :required
|
|
18
|
-
def initialize(klass)
|
|
19
|
-
@klass = klass
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def attr(name, default: None, as: None, &blk)
|
|
24
|
-
attributes.update(name => OpenStruct.new(default:, type: as, constraint: blk))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def attributes = @__attributes__ ||= {}
|
|
28
|
-
|
|
29
|
-
def defaults
|
|
30
|
-
@__defaults__ ||= attributes.inject({}) do |defaults, (name, desc)|
|
|
31
|
-
if desc.default == None
|
|
32
|
-
defaults
|
|
33
|
-
else
|
|
34
|
-
defaults.merge(name => desc.default)
|
|
35
|
-
end
|
|
36
|
-
end.freeze
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def make_callable(&blk)
|
|
40
|
-
@callable = blk
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|