uinit-structure 0.1.4 → 0.1.5

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: 8cb370826705dbff7a6e5655c6d53e5b42dd58a2c5adfa25187b97532fb28ac8
4
- data.tar.gz: e3e335c203daf426838917777d9205092c6ba6a574d057524c62583ac106c121
3
+ metadata.gz: 3931923313a282612e428ab5de5c935a7cc949dde0e3ba3e2a5d0af52480974e
4
+ data.tar.gz: 7adabb1c170af08c1cc5ba9eec5ceb4efab1fd3c4fce899d491e7fd9226bda20
5
5
  SHA512:
6
- metadata.gz: 4fd715aab45e5660901e17d31a59b4a7d9f9f280490904103ab14a37f92886852bcd57575835f9c5e75962f9a0d4f9aae43f093095b1455aea791b1c9650aba1
7
- data.tar.gz: ca550ec25381be0da16da74b2c807b5b48365d58aff1e8da0c571d00c2f507220f1ec2e3126bcf25410f2b91141e2b511094739bfd37c2d05aaae169824e45fe
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.4'
5
+ VERSION = '0.1.5'
6
6
  end
7
7
  end
@@ -70,7 +70,7 @@ module Uinit
70
70
  attr_writer :attributes, :attributes_scope
71
71
  end
72
72
 
73
- memo def get_structure_schema = self.class.structure_schema
74
- memo def get_attributes = self.class.attributes
73
+ memo def __structure_schema = self.class.structure_schema
74
+ memo def __attributes = self.class.attributes
75
75
  end
76
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
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