uinit-structure 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +10 -39
- 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: 0503a10252f0c6e44bb61a6853d5bc59380dc0b6568e50778d14ba28b0ad0616
|
4
|
+
data.tar.gz: b3235c878479a28a98d09859bddafbf011f92596c29c59a67f2862e638bb8a44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 710a40c77b700bbd2a6a41a3dab9a6144677687f67fa255ac7b8afcdb44a024fb7439e729bc985e2b199f65ac6e8537862ef504669485d05e741e553ad25cf64
|
7
|
+
data.tar.gz: 1638b06baa9a4929e9bdca10b26056469ec8ad2edcee5e7af21d367cd27834a9986aa4b97dd5329ec73ab3e2628b027e8816505308c5e7e6b892231731724f92
|
@@ -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
|
-
AttributeContext.scope(&)
|
46
|
+
attributes = AttributeContext.scope(&)
|
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,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kimoja
|
@@ -11,19 +11,19 @@ cert_chain: []
|
|
11
11
|
date: 2024-09-21 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
|
@@ -110,7 +82,6 @@ files:
|
|
110
82
|
- lib/uinit/structure/attribute_context.rb
|
111
83
|
- lib/uinit/structure/attribute_error.rb
|
112
84
|
- lib/uinit/structure/attribute_type_error.rb
|
113
|
-
- lib/uinit/structure/compilers.rb
|
114
85
|
- lib/uinit/structure/compilers/as_json.rb
|
115
86
|
- lib/uinit/structure/compilers/attribute.rb
|
116
87
|
- lib/uinit/structure/compilers/base.rb
|