uinit-structure 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a743c0abc2104544f146a736c252aa06fd453bc6efbc6b24badbcd637a4e19
|
4
|
+
data.tar.gz: 296f8f382e991c6ea709732ae344d654d96a063855296f16c180514e4085c3a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a92cf903e3528bd04e476d0df7351e2d4987d1184a77ea43d7c4eabc4439ba9a06a2919ec201bb3cddc314f279f5cda09b7b25893c3b06d7713c0e07c22841
|
7
|
+
data.tar.gz: 3ee54c822deef14f1632acb740d5ef1c686cf99e49c12dcec94377915036688b570ba94d1c3a1b1946dc176e3b1ee74e9d9a149f634cdfaf596541289e338ac9
|
data/README.md
CHANGED
@@ -3,11 +3,18 @@
|
|
3
3
|
module Uinit
|
4
4
|
module Structure
|
5
5
|
class AttributeBuilder
|
6
|
-
def initialize(attribute = nil)
|
7
|
-
|
6
|
+
def initialize(defaults, attribute = nil)
|
7
|
+
self.attribute = attribute || Attribute.new
|
8
|
+
self.defaults = defaults
|
9
|
+
|
10
|
+
return if attribute
|
11
|
+
|
12
|
+
defaults.each do |(name, value)|
|
13
|
+
self.attribute.send(:"#{name}=", value)
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
|
-
attr_accessor :attribute
|
17
|
+
attr_accessor :attribute, :defaults
|
11
18
|
|
12
19
|
def attr(name, type = nil, default = Attribute::UNDEFINED, &)
|
13
20
|
return build_mutliple(name, type, default, &) if name.is_a?(Array)
|
@@ -103,7 +110,7 @@ module Uinit
|
|
103
110
|
|
104
111
|
def build_mutliple(name, type, default, &)
|
105
112
|
name.map do |nm|
|
106
|
-
builder = AttributeBuilder.new(attribute.clone)
|
113
|
+
builder = AttributeBuilder.new(defaults, attribute.clone)
|
107
114
|
builder.attr(nm, type, default, &)
|
108
115
|
end
|
109
116
|
end
|
@@ -15,29 +15,39 @@ module Uinit
|
|
15
15
|
|
16
16
|
memo def attributes = []
|
17
17
|
|
18
|
+
def defaults(**defaults)
|
19
|
+
self.attribute_defaults = defaults
|
20
|
+
end
|
21
|
+
|
18
22
|
def private(att_or_get_set = nil, *)
|
19
23
|
return att_or_getset.private(:get, :set) if att_or_get_set.is_a?(AttributeBuilder)
|
20
24
|
|
21
|
-
builder =
|
25
|
+
builder = build_attribute_builder.private(*[att_or_get_set, *].compact)
|
22
26
|
attributes << builder.attribute
|
23
27
|
|
24
28
|
builder
|
25
29
|
end
|
26
30
|
|
27
31
|
def attr(...)
|
28
|
-
push_attribute(
|
32
|
+
push_attribute(build_attribute_builder.attr(...))
|
29
33
|
end
|
30
34
|
|
31
35
|
def abstract(...)
|
32
|
-
push_attribute(
|
36
|
+
push_attribute(build_attribute_builder.abstract(...))
|
33
37
|
end
|
34
38
|
|
35
39
|
def using(attribute_builder)
|
36
|
-
push_attribute(
|
40
|
+
push_attribute(build_attribute_builder(attribute_builder.attribute))
|
37
41
|
end
|
38
42
|
|
39
43
|
private
|
40
44
|
|
45
|
+
attr_accessor :attribute_defaults
|
46
|
+
|
47
|
+
def build_attribute_builder(attribute = nil)
|
48
|
+
AttributeBuilder.new(attribute_defaults || {}, attribute)
|
49
|
+
end
|
50
|
+
|
41
51
|
def push_attribute(builder)
|
42
52
|
if builder.is_a?(Array)
|
43
53
|
attributes.push(*builder.map(&:attribute))
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kimoja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|