uinit-structure 0.1.1 → 0.1.3
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_context.rb +0 -7
- data/lib/uinit/structure/attribute_scope.rb +27 -0
- 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 +1 -1
- data/lib/uinit/structure/version.rb +1 -1
- data/lib/uinit/structure.rb +21 -9
- data/uinit-structure.gemspec +2 -5
- metadata +12 -40
- data/lib/uinit/structure/compilers.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c15895eb9482a3f6f4da9fd7e32cf7faa7b00e8dcc313a88526a1be679532eb2
|
4
|
+
data.tar.gz: 4fb76f7c50604b5f1cbd2ff0d245f1586b4e30376f15db6c685e8bea9f427e27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 786b0bd30d8855c54271a5a5260459182a5c25a9fe878be6dcc6676822e372eb655980c86a545c5343f736906dc084d9ba11e52ddeee397c4459d65d47aac8e0
|
7
|
+
data.tar.gz: 950e1d19b84cdb1101285190c574feb1015fb3b7e9852b6da26bc65e9229272cbc51bbca20f5e2450b51ed72d84ef0ea2cc8bb61410e92cb49822197dd16e096
|
@@ -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
|
@@ -75,7 +75,7 @@ module Uinit
|
|
75
75
|
|
76
76
|
def compile_default_attribute(name, attribute)
|
77
77
|
<<~RUBY
|
78
|
-
self.#{name} =
|
78
|
+
self.#{name} = get_structure_schema.#{name}.default#{attribute.default.is_a?(Proc) ? '.call' : ''}
|
79
79
|
RUBY
|
80
80
|
end
|
81
81
|
end
|
data/lib/uinit/structure.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'zeitwerk'
|
4
4
|
|
5
|
+
require 'active_support'
|
6
|
+
|
5
7
|
require 'uinit/type'
|
6
8
|
require 'uinit/memoizable'
|
7
9
|
|
@@ -14,17 +16,16 @@ end
|
|
14
16
|
|
15
17
|
module Uinit
|
16
18
|
module Structure
|
19
|
+
extend ActiveSupport::Concern
|
17
20
|
include Memoizable
|
18
21
|
|
19
|
-
def self.included(base)
|
20
|
-
base.extend(ClassMethods)
|
21
|
-
end
|
22
|
-
|
23
22
|
class Schema; end
|
24
23
|
|
25
|
-
|
24
|
+
class_methods do
|
26
25
|
include Memoizable
|
27
26
|
|
27
|
+
attr_reader :attributes
|
28
|
+
|
28
29
|
memo def structure_schema
|
29
30
|
if respond_to?(:superclass) && superclass.respond_to?(:structure_schema)
|
30
31
|
return Class.new(superclass.structure_schema.class).new
|
@@ -42,7 +43,9 @@ module Uinit
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def struct(&)
|
45
|
-
|
46
|
+
attributes = AttributeScope.new(self).scope(&).attributes
|
47
|
+
|
48
|
+
attributes.each do |attribute|
|
46
49
|
raise NameError, 'Attribute must have a name' unless attribute.name
|
47
50
|
|
48
51
|
structure_schema.class.define_method(attribute.name) { attribute }
|
@@ -51,11 +54,20 @@ module Uinit
|
|
51
54
|
|
52
55
|
Compilers::Constructor.compile(structure_module, structure_schema)
|
53
56
|
Compilers::AsJson.compile(structure_module, structure_schema)
|
57
|
+
|
58
|
+
sup_attributes = superclass < Structure ? superclass.attributes.dup : {}
|
59
|
+
|
60
|
+
self.attributes = attributes.each_with_object(sup_attributes) do |attribute, hsh|
|
61
|
+
hsh[attribute.name] = attribute
|
62
|
+
end
|
54
63
|
end
|
55
|
-
end
|
56
64
|
|
57
|
-
|
65
|
+
private
|
66
|
+
|
67
|
+
attr_writer :attributes
|
68
|
+
end
|
58
69
|
|
59
|
-
memo def
|
70
|
+
memo def get_structure_schema = self.class.structure_schema
|
71
|
+
memo def get_attributes = self.class.attributes
|
60
72
|
end
|
61
73
|
end
|
data/uinit-structure.gemspec
CHANGED
@@ -26,13 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.metadata['changelog_uri'] = 'https://github.com/Kimoja/uinit-structure/blob/main/CHANGELOG.md'
|
27
27
|
spec.metadata['bug_tracker_uri'] = 'https://github.com/Kimoja/uinit-structure/issues'
|
28
28
|
|
29
|
-
spec.
|
30
|
-
|
29
|
+
spec.add_dependency 'activesupport', '~> 7.1.3'
|
31
30
|
spec.add_dependency 'uinit-memoizable', '~> 0.1.0'
|
32
31
|
spec.add_dependency 'uinit-type', '~> 0.1.0'
|
32
|
+
spec.add_dependency 'zeitwerk', '~> 2.6'
|
33
33
|
|
34
|
-
spec.add_development_dependency 'bundler'
|
35
|
-
spec.add_development_dependency 'rspec'
|
36
|
-
spec.add_development_dependency 'rubocop'
|
37
34
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
38
35
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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.3
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 7.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: uinit-memoizable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,47 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop
|
56
|
+
name: zeitwerk
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
86
58
|
requirements:
|
87
|
-
- - "
|
59
|
+
- - "~>"
|
88
60
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
-
type: :
|
61
|
+
version: '2.6'
|
62
|
+
type: :runtime
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
|
-
- - "
|
66
|
+
- - "~>"
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
68
|
+
version: '2.6'
|
97
69
|
description: Typed structure
|
98
70
|
email:
|
99
71
|
- joakim.carrilho@cheerz.com
|
@@ -109,8 +81,8 @@ files:
|
|
109
81
|
- lib/uinit/structure/attribute_builder.rb
|
110
82
|
- lib/uinit/structure/attribute_context.rb
|
111
83
|
- lib/uinit/structure/attribute_error.rb
|
84
|
+
- lib/uinit/structure/attribute_scope.rb
|
112
85
|
- lib/uinit/structure/attribute_type_error.rb
|
113
|
-
- lib/uinit/structure/compilers.rb
|
114
86
|
- lib/uinit/structure/compilers/as_json.rb
|
115
87
|
- lib/uinit/structure/compilers/attribute.rb
|
116
88
|
- lib/uinit/structure/compilers/base.rb
|