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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 671d17e08f4547b324b61474ef20d10e7057b063af31b4fad297b621f05e16dd
4
- data.tar.gz: 7cf66a0c5f9b4302f24f5059a50a9f2979adc0f9b870e627c213402fd6884192
3
+ metadata.gz: 308b78e110004588dedfaec131948d47f060ed15fa8a09fa241af01d15bf83d7
4
+ data.tar.gz: a17c4130c51c4d2cc6c51a48ee50b5b176bd98fd0237fe8cf26c225a9a2a971e
5
5
  SHA512:
6
- metadata.gz: b9adb3df88d04f1d5215785eac7eb71a8ab8efdd7d88c02d24aaaf7de1c1e7a13dfacab73cb0af114c74074b1ab075284118acf8a432b045e92270106fcca56a
7
- data.tar.gz: 3524d0cf555774eb8d46afd200a98fa9d4c0c81c198936810e882d8a8d8a603035b2081b6b392f9e1c33a545cfc96a414792d9ede6e421fa4bdf4b0096e96df8
6
+ metadata.gz: d8fa16c2ba0deaf38e9d0f66d273b939be62d69bb8eb85590574d0eec1d472a966513154774d8fbaff8744767ceb45a398ec1faeb6c2ed2b497e6d8a4bdf0443
7
+ data.tar.gz: 9e47b6836d783f38b90636d3713da58222a8c3668ebac313736b63cd08b40b25c304d73ffc4b8248608ac6215860083fb967244f7b5364b57f730945df841360
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.0.2]
2
+
3
+ - Fix problem where the first time a type is declared via an
4
+ active record class it has a complex declaration hash instead of a simple
5
+ registered class lookup
6
+
1
7
  ## [0.0.1]
2
8
 
3
9
  - Release as a gem
@@ -7,7 +7,9 @@ module Foobara
7
7
  end
8
8
 
9
9
  def desugarize(active_record_class)
10
- if active_record_class.superclass != ActiveRecord::Base
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: active_record_class.superclass.name,
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?(klass)
9
- klass.is_a?(Class) && klass < ActiveRecord::Base && type_registered?(klass.name)
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.name
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.1
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-04 00:00:00.000000000 Z
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