foobara-active-record-type 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/src/extend_active_record_type_declaration/active_record_base_class_desugarizer.rb +4 -2
- data/src/extend_active_record_type_declaration/{registered_active_record_base_class_desugarizer.rb → type_declaration_extension/registered_type_declaration/desugarizers/registered_active_record_base_class_desugarizer.rb} +4 -3
- data/src/extend_active_record_type_declaration/type_declaration_extension/registered_type_declaration/desugarizers/unregistered_active_record_base_class_desugarizer.rb +36 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 308b78e110004588dedfaec131948d47f060ed15fa8a09fa241af01d15bf83d7
|
4
|
+
data.tar.gz: a17c4130c51c4d2cc6c51a48ee50b5b176bd98fd0237fe8cf26c225a9a2a971e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8fa16c2ba0deaf38e9d0f66d273b939be62d69bb8eb85590574d0eec1d472a966513154774d8fbaff8744767ceb45a398ec1faeb6c2ed2b497e6d8a4bdf0443
|
7
|
+
data.tar.gz: 9e47b6836d783f38b90636d3713da58222a8c3668ebac313736b63cd08b40b25c304d73ffc4b8248608ac6215860083fb967244f7b5364b57f730945df841360
|
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,9 @@ module Foobara
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def desugarize(active_record_class)
|
10
|
-
|
10
|
+
active_record_superclass = active_record_class.superclass
|
11
|
+
|
12
|
+
if active_record_superclass != ActiveRecord::Base
|
11
13
|
# this will register a foobara type for the base class
|
12
14
|
type_for_declaration(active_record_class.superclass)
|
13
15
|
end
|
@@ -16,7 +18,7 @@ module Foobara
|
|
16
18
|
type: :active_record,
|
17
19
|
model_class: active_record_class.name,
|
18
20
|
name: active_record_class.name,
|
19
|
-
model_base_class:
|
21
|
+
model_base_class: active_record_superclass.name,
|
20
22
|
model_module: Util.module_for(active_record_class)&.name,
|
21
23
|
primary_key: active_record_class.primary_key,
|
22
24
|
attributes_declaration: active_record_class_to_attributes_declaration(active_record_class)
|
@@ -5,13 +5,14 @@ module Foobara
|
|
5
5
|
module RegisteredTypeDeclaration
|
6
6
|
module Desugarizers
|
7
7
|
class RegisteredActiveRecordBaseClassDesugarizer < TypeDeclarations::Desugarizer
|
8
|
-
def applicable?(
|
9
|
-
|
8
|
+
def applicable?(sugary_type_declaration)
|
9
|
+
sugary_type_declaration.is_a?(Class) && sugary_type_declaration < ActiveRecord::Base &&
|
10
|
+
sugary_type_declaration.foobara_type
|
10
11
|
end
|
11
12
|
|
12
13
|
def desugarize(active_record_class)
|
13
14
|
{
|
14
|
-
type: active_record_class.
|
15
|
+
type: active_record_class.foobara_type.foobara_manifest_reference.to_sym
|
15
16
|
}
|
16
17
|
end
|
17
18
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Foobara
|
2
|
+
module ActiveRecordType
|
3
|
+
class ExtendActiveRecordTypeDeclaration < TypeDeclarations::Handlers::ExtendDetachedEntityTypeDeclaration
|
4
|
+
module TypeDeclarationExtension
|
5
|
+
module RegisteredTypeDeclaration
|
6
|
+
module Desugarizers
|
7
|
+
class UnregisteredActiveRecordBaseClassDesugarizer < TypeDeclarations::Desugarizer
|
8
|
+
def applicable?(sugary_type_declaration)
|
9
|
+
sugary_type_declaration.is_a?(Class) && sugary_type_declaration < ActiveRecord::Base &&
|
10
|
+
!sugary_type_declaration.foobara_type
|
11
|
+
end
|
12
|
+
|
13
|
+
# We will create the foobara type from the active record class and then the
|
14
|
+
# RegisteredActiveRecordBaseClassDesugarizer
|
15
|
+
# will handle it properly.
|
16
|
+
# This will keep declarations using just the active record class simple in the first place they are used
|
17
|
+
# by acting as if it were a registered type at the time even though it wasn't yet.
|
18
|
+
def desugarize(active_record_class)
|
19
|
+
handler = handler_for_class(Foobara::ActiveRecordType::ExtendActiveRecordTypeDeclaration)
|
20
|
+
handler.process_value!(active_record_class)
|
21
|
+
|
22
|
+
{
|
23
|
+
type: active_record_class.foobara_type.foobara_manifest_reference.to_sym
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def priority
|
28
|
+
Priority::FIRST - 3
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-active-record-type
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-17 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -58,8 +58,9 @@ files:
|
|
58
58
|
- src/extend_active_record_type_declaration/hash_desugarizer.rb
|
59
59
|
- src/extend_active_record_type_declaration/model_class_desugarizer.rb
|
60
60
|
- src/extend_active_record_type_declaration/primary_key_desugarizer.rb
|
61
|
-
- src/extend_active_record_type_declaration/registered_active_record_base_class_desugarizer.rb
|
62
61
|
- src/extend_active_record_type_declaration/to_type_transformer.rb
|
62
|
+
- src/extend_active_record_type_declaration/type_declaration_extension/registered_type_declaration/desugarizers/registered_active_record_base_class_desugarizer.rb
|
63
|
+
- src/extend_active_record_type_declaration/type_declaration_extension/registered_type_declaration/desugarizers/unregistered_active_record_base_class_desugarizer.rb
|
63
64
|
- src/extend_active_record_type_declaration/validate_primary_key_is_symbol.rb
|
64
65
|
- src/extend_active_record_type_declaration/validate_primary_key_present.rb
|
65
66
|
- src/extend_active_record_type_declaration/validate_primary_key_references_attribute.rb
|