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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c15895eb9482a3f6f4da9fd7e32cf7faa7b00e8dcc313a88526a1be679532eb2
4
- data.tar.gz: 4fb76f7c50604b5f1cbd2ff0d245f1586b4e30376f15db6c685e8bea9f427e27
3
+ metadata.gz: 3931923313a282612e428ab5de5c935a7cc949dde0e3ba3e2a5d0af52480974e
4
+ data.tar.gz: 7adabb1c170af08c1cc5ba9eec5ceb4efab1fd3c4fce899d491e7fd9226bda20
5
5
  SHA512:
6
- metadata.gz: 786b0bd30d8855c54271a5a5260459182a5c25a9fe878be6dcc6676822e372eb655980c86a545c5343f736906dc084d9ba11e52ddeee397c4459d65d47aac8e0
7
- data.tar.gz: 950e1d19b84cdb1101285190c574feb1015fb3b7e9852b6da26bc65e9229272cbc51bbca20f5e2450b51ed72d84ef0ea2cc8bb61410e92cb49822197dd16e096
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
 
@@ -87,7 +87,7 @@ module Uinit
87
87
 
88
88
  def compile_json_proc(name)
89
89
  <<~RUBY
90
- get_structure_schema.#{name}.as_json.call(json, self.#{name}, :#{name})
90
+ __structure_schema.#{name}.as_json.call(json, self.#{name}, :#{name})
91
91
  RUBY
92
92
  end
93
93
  end
@@ -180,7 +180,7 @@ module Uinit
180
180
  end
181
181
 
182
182
  def lookup(att = nil)
183
- "get_structure_schema.#{attribute.name}#{att ? ".#{att}" : ''}"
183
+ "__structure_schema.#{attribute.name}#{att ? ".#{att}" : ''}"
184
184
  end
185
185
  end
186
186
  # rubocop:enable Metrics/ClassLength
@@ -30,9 +30,7 @@ module Uinit
30
30
  end
31
31
 
32
32
  <<~RUBY
33
- begin
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} = get_structure_schema.#{name}.default#{attribute.default.is_a?(Proc) ? '.call' : ''}
76
+ self.#{name} = __structure_schema.#{name}.default#{attribute.default.is_a?(Proc) ? '.call' : ''}
79
77
  RUBY
80
78
  end
81
79
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Uinit
4
4
  module Structure
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.5'
6
6
  end
7
7
  end
@@ -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
- attributes = AttributeScope.new(self).scope(&).attributes
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 get_structure_schema = self.class.structure_schema
71
- memo def get_attributes = self.class.attributes
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.3
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-29 00:00:00.000000000 Z
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport