foobara-active-record-type 0.0.1 → 0.0.3
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/active_record_foobara_methods.rb +1 -1
- data/src/extend_active_record_type_declaration/active_record_base_class_desugarizer.rb +8 -4
- data/src/extend_active_record_type_declaration/to_type_transformer.rb +3 -1
- 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: 3499a493db193b496a20ae4dd0d1dd1d7ad5193701346ee2de9abc397b107ff9
|
4
|
+
data.tar.gz: 59db77d01419543a0230aecb0d5f49aa6f1ba541bb820d7ffd743ee41211d2ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a72802f7ae7ef65f5174285ae4dde77f7876b3463ea3d6a69bc7366a91838b5e1a22b94a8c6352b3725755195121855f391a30163378ceb065cfd16c6d9b9622
|
7
|
+
data.tar.gz: b49ed2b61b22d34e1b0179c841e2deb05ac5b0886fa71826bcb781f1572e6c52323ed729cd2ae7b058d5e078a184fb872e8dff4329fdd8184c557f7ef15332f0
|
data/CHANGELOG.md
CHANGED
@@ -7,16 +7,20 @@ module Foobara
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def desugarize(active_record_class)
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
active_record_superclass = active_record_class.superclass
|
11
|
+
|
12
|
+
if active_record_superclass != ActiveRecord::Base
|
13
|
+
if active_record_superclass.attribute_names.include?(active_record_class.primary_key)
|
14
|
+
# this will register a foobara type for the base class
|
15
|
+
type_for_declaration(active_record_class.superclass)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
{
|
16
20
|
type: :active_record,
|
17
21
|
model_class: active_record_class.name,
|
18
22
|
name: active_record_class.name,
|
19
|
-
model_base_class:
|
23
|
+
model_base_class: active_record_superclass.name,
|
20
24
|
model_module: Util.module_for(active_record_class)&.name,
|
21
25
|
primary_key: active_record_class.primary_key,
|
22
26
|
attributes_declaration: active_record_class_to_attributes_declaration(active_record_class)
|
@@ -13,7 +13,9 @@ module Foobara
|
|
13
13
|
handler = handler_for_class(TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration)
|
14
14
|
attributes_type_declaration = type.declaration_data[:attributes_declaration]
|
15
15
|
|
16
|
-
|
16
|
+
active_record_class.foobara_attributes_type = handler.process_value!(attributes_type_declaration)
|
17
|
+
|
18
|
+
type.element_types = active_record_class.foobara_attributes_type.element_types
|
17
19
|
type_name = type.declaration_data[:name]
|
18
20
|
|
19
21
|
# We don't want to check that the active record is valid as if it were a model
|
@@ -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.3
|
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-18 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
|