uinit-structure 0.1.2 → 0.1.4

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: 0503a10252f0c6e44bb61a6853d5bc59380dc0b6568e50778d14ba28b0ad0616
4
- data.tar.gz: b3235c878479a28a98d09859bddafbf011f92596c29c59a67f2862e638bb8a44
3
+ metadata.gz: 8cb370826705dbff7a6e5655c6d53e5b42dd58a2c5adfa25187b97532fb28ac8
4
+ data.tar.gz: e3e335c203daf426838917777d9205092c6ba6a574d057524c62583ac106c121
5
5
  SHA512:
6
- metadata.gz: 710a40c77b700bbd2a6a41a3dab9a6144677687f67fa255ac7b8afcdb44a024fb7439e729bc985e2b199f65ac6e8537862ef504669485d05e741e553ad25cf64
7
- data.tar.gz: 1638b06baa9a4929e9bdca10b26056469ec8ad2edcee5e7af21d367cd27834a9986aa4b97dd5329ec73ab3e2628b027e8816505308c5e7e6b892231731724f92
6
+ metadata.gz: 4fd715aab45e5660901e17d31a59b4a7d9f9f280490904103ab14a37f92886852bcd57575835f9c5e75962f9a0d4f9aae43f093095b1455aea791b1c9650aba1
7
+ data.tar.gz: ca550ec25381be0da16da74b2c807b5b48365d58aff1e8da0c571d00c2f507220f1ec2e3126bcf25410f2b91141e2b511094739bfd37c2d05aaae169824e45fe
@@ -6,13 +6,6 @@ module Uinit
6
6
  include Memoizable
7
7
  include Type::Context
8
8
 
9
- def self.scope(&)
10
- context = Class.new { include AttributeContext }.new
11
- context.instance_eval(&)
12
-
13
- context.attributes
14
- end
15
-
16
9
  memo def attributes = []
17
10
 
18
11
  def defaults(**defaults)
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Uinit
4
+ module Structure
5
+ class AttributeScope
6
+ include AttributeContext
7
+
8
+ def initialize(context)
9
+ self.context = context
10
+ end
11
+
12
+ def scope(&scope)
13
+ instance_eval(&scope) if scope
14
+
15
+ self
16
+ end
17
+
18
+ def method_missing(name, ...)
19
+ context.send(name, ...)
20
+ end
21
+
22
+ private
23
+
24
+ attr_accessor :context
25
+ end
26
+ end
27
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Uinit
4
4
  module Structure
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.4'
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 = AttributeContext.scope(&)
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,11 +61,13 @@ 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
73
  memo def get_structure_schema = self.class.structure_schema
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.2
4
+ version: 0.1.4
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-21 00:00:00.000000000 Z
11
+ date: 2024-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -81,6 +81,7 @@ files:
81
81
  - lib/uinit/structure/attribute_builder.rb
82
82
  - lib/uinit/structure/attribute_context.rb
83
83
  - lib/uinit/structure/attribute_error.rb
84
+ - lib/uinit/structure/attribute_scope.rb
84
85
  - lib/uinit/structure/attribute_type_error.rb
85
86
  - lib/uinit/structure/compilers/as_json.rb
86
87
  - lib/uinit/structure/compilers/attribute.rb