uinit-structure 0.1.3 → 0.1.5
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/uinit/structure/attribute.rb +3 -1
- data/lib/uinit/structure/attribute_builder.rb +7 -1
- data/lib/uinit/structure/compilers/as_json.rb +1 -1
- data/lib/uinit/structure/compilers/attribute.rb +1 -1
- data/lib/uinit/structure/compilers/constructor.rb +2 -4
- data/lib/uinit/structure/version.rb +1 -1
- data/lib/uinit/structure.rb +8 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3931923313a282612e428ab5de5c935a7cc949dde0e3ba3e2a5d0af52480974e
|
4
|
+
data.tar.gz: 7adabb1c170af08c1cc5ba9eec5ceb4efab1fd3c4fce899d491e7fd9226bda20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3797d78ad3a31326fd5d50e1019ff53f0126a312c6978461471b354db1182c9c547a085601be1612d57e23d3e35bcda87cdfb0c4ef3fd32da1489ccc18809414
|
7
|
+
data.tar.gz: 491603d0e62cf0901df9adfdae267437557055f628702a9c73786a2a330b0468c74299b66b0b0cfa1154479e64320be7cdf066cdfc607457722e0ddeab0824ad
|
@@ -91,9 +91,11 @@ module Uinit
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def optional?
|
94
|
-
@default != UNDEFINED
|
94
|
+
defined?(@optional) ? @optional : @default != UNDEFINED
|
95
95
|
end
|
96
96
|
|
97
|
+
attr_writer :optional
|
98
|
+
|
97
99
|
def init=(val)
|
98
100
|
raise ArgumentError, 'init must be a boolean' unless [true, false].include?(val)
|
99
101
|
|
@@ -70,12 +70,18 @@ module Uinit
|
|
70
70
|
self
|
71
71
|
end
|
72
72
|
|
73
|
-
def optional(val)
|
73
|
+
def optional(val = true)
|
74
74
|
attribute.optional = val
|
75
75
|
|
76
76
|
self
|
77
77
|
end
|
78
78
|
|
79
|
+
def required
|
80
|
+
attribute.optional = false
|
81
|
+
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
79
85
|
def init(val)
|
80
86
|
attribute.init = val
|
81
87
|
|
@@ -30,9 +30,7 @@ module Uinit
|
|
30
30
|
end
|
31
31
|
|
32
32
|
<<~RUBY
|
33
|
-
|
34
|
-
super(hsh)
|
35
|
-
end
|
33
|
+
super(hsh)
|
36
34
|
RUBY
|
37
35
|
end
|
38
36
|
|
@@ -75,7 +73,7 @@ module Uinit
|
|
75
73
|
|
76
74
|
def compile_default_attribute(name, attribute)
|
77
75
|
<<~RUBY
|
78
|
-
self.#{name} =
|
76
|
+
self.#{name} = __structure_schema.#{name}.default#{attribute.default.is_a?(Proc) ? '.call' : ''}
|
79
77
|
RUBY
|
80
78
|
end
|
81
79
|
end
|
data/lib/uinit/structure.rb
CHANGED
@@ -24,7 +24,7 @@ module Uinit
|
|
24
24
|
class_methods do
|
25
25
|
include Memoizable
|
26
26
|
|
27
|
-
attr_reader :attributes
|
27
|
+
attr_reader :attributes, :attributes_scope
|
28
28
|
|
29
29
|
memo def structure_schema
|
30
30
|
if respond_to?(:superclass) && superclass.respond_to?(:structure_schema)
|
@@ -43,7 +43,8 @@ module Uinit
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def struct(&)
|
46
|
-
|
46
|
+
self.attributes_scope = AttributeScope.new(self)
|
47
|
+
attributes = attributes_scope.scope(&).attributes
|
47
48
|
|
48
49
|
attributes.each do |attribute|
|
49
50
|
raise NameError, 'Attribute must have a name' unless attribute.name
|
@@ -60,14 +61,16 @@ module Uinit
|
|
60
61
|
self.attributes = attributes.each_with_object(sup_attributes) do |attribute, hsh|
|
61
62
|
hsh[attribute.name] = attribute
|
62
63
|
end
|
64
|
+
|
65
|
+
self.attributes_scope = nil
|
63
66
|
end
|
64
67
|
|
65
68
|
private
|
66
69
|
|
67
|
-
attr_writer :attributes
|
70
|
+
attr_writer :attributes, :attributes_scope
|
68
71
|
end
|
69
72
|
|
70
|
-
memo def
|
71
|
-
memo def
|
73
|
+
memo def __structure_schema = self.class.structure_schema
|
74
|
+
memo def __attributes = self.class.attributes
|
72
75
|
end
|
73
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uinit-structure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kimoja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|