foobara-active-record-type 0.0.14 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7875c3851e75b4b6b2f5963c057a93541fcfc825d1705bdaf181e1ce9b703982
4
- data.tar.gz: 2907faeae76548a51190010dd96710795c334b793ccc9fc64c78b57cd11f15fa
3
+ metadata.gz: d414152dfd728426b476b045fed5257eb2033730df365489e237579133faed97
4
+ data.tar.gz: dda2b3cefaf392d06385fc89d6cd584db39871add5fd962e354671e989a45596
5
5
  SHA512:
6
- metadata.gz: 4ea9d7c160402a9e0e7035dc4fc83f0bb44bddd9a779b8f458044c064659822a868255c6c63afae8276025a29e0bf752ddbaf5e1e6e8a1112022d61c448076d3
7
- data.tar.gz: 48e1cfb557bc5bf9637db1da097eb1c25283e17e6f370bd24307c1633a5139a19ff4dd3ba72d77a8cf96269ef90642846154003cb67a3c8329713384d07ebff4
6
+ metadata.gz: fcf8caf0d05f288b939f97017c46ee0322ff2b4d2041c63252c66600fcc8faf68920dee1379f88fe0f912439a1d344fdbb92014864f4866a451196da19575a78
7
+ data.tar.gz: '088d5e174cf4b25fe2377779419da3af45399e144cdb2ef42104d1cf86e5874ec16a8fd8f77b928a8351bc5be42c9461d7c8db61750ed2889bc2d77b45e84d7a'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.1.0] - 2025-08-22
2
+
3
+ - Add support for Foobara 0.1.0 type declarations
4
+
1
5
  ## [0.0.14] - 2025-02-02
2
6
 
3
7
  - Fix manifest name bug
@@ -17,6 +17,7 @@ module Foobara
17
17
  type_module: Foobara::ActiveRecordType
18
18
  )
19
19
  type.remove_processor_by_symbol(:attributes_declaration)
20
+ type.remove_processor_by_symbol(:model_instance_is_valid)
20
21
 
21
22
  BuiltinTypes.install_type_declaration_extensions_for(ExtendActiveRecordTypeDeclaration)
22
23
 
@@ -24,6 +25,7 @@ module Foobara
24
25
  ActiveRecord::Base.include ActiveRecordFoobaraMethods
25
26
  ActiveRecord::Base.include Foobara::Model::Concerns::Reflection
26
27
  ActiveRecord::Base.include Foobara::DetachedEntity::Concerns::Reflection
28
+ # ActiveRecord::Base.include Foobara::Model::Concerns::Errors
27
29
 
28
30
  if defined?(Foobara::CommandConnectors::RailsCommandConnector)
29
31
  Foobara::CommandConnectors::RailsCommandConnector.default_serializers = [
@@ -11,6 +11,14 @@ module Foobara
11
11
  {}
12
12
  end
13
13
 
14
+ def foobara_delegates
15
+ {}
16
+ end
17
+
18
+ def foobara_private_attribute_names
19
+ []
20
+ end
21
+
14
22
  # TODO: implement this or figure out how to re-use the methods from Entity/Model
15
23
  def foobara_deep_associations
16
24
  # TODO: test this
@@ -36,7 +44,13 @@ module Foobara
36
44
  end
37
45
 
38
46
  def foobara_attributes_for_create(...)
39
- TypeDeclarations::Attributes.reject(super, :created_at, :updated_at)
47
+ attributes = super
48
+
49
+ if attributes.is_a?(Types::Type)
50
+ attributes = attributes.declaration_data
51
+ end
52
+
53
+ TypeDeclarations::Attributes.reject(attributes, :created_at, :updated_at)
40
54
  end
41
55
 
42
56
  def foobara_attributes_for_update(...)
@@ -1,34 +1,42 @@
1
1
  module Foobara
2
2
  module ActiveRecordType
3
- class ExtendActiveRecordTypeDeclaration < TypeDeclarations::Handlers::ExtendDetachedEntityTypeDeclaration
3
+ class ExtendActiveRecordTypeDeclaration < TypeDeclarations::Handlers::ExtendDetachedEntityTypeDeclaration
4
4
  class ActiveRecordBaseClassDesugarizer < TypeDeclarations::Desugarizer
5
- def applicable?(klass)
6
- klass.is_a?(Class) && klass < ActiveRecord::Base
5
+ def applicable?(sugary_type_declaration)
6
+ if sugary_type_declaration.class?
7
+ sugary_type_declaration.declaration_data < ActiveRecord::Base
8
+ end
7
9
  end
8
10
 
9
- def desugarize(active_record_class)
10
- active_record_superclass = active_record_class.superclass
11
+ def desugarize(sugary_type_declaration)
12
+ klass = sugary_type_declaration.declaration_data
13
+ active_record_superclass = klass.superclass
11
14
 
12
15
  if active_record_superclass != ActiveRecord::Base
13
- if active_record_superclass.attribute_names.include?(active_record_class.primary_key)
16
+ if active_record_superclass.attribute_names.include?(klass.primary_key)
14
17
  # this will register a foobara type for the base class
15
- type_for_declaration(active_record_class.superclass)
18
+ type_for_declaration(klass.superclass)
16
19
  end
17
20
  end
18
21
 
19
- domain = Foobara::Domain.domain_through_modules(active_record_class)
22
+ domain = Foobara::Domain.domain_through_modules(klass)
20
23
 
21
- name = active_record_class.name.gsub(/^#{domain.scoped_full_name}::/, "")
24
+ name = klass.name.gsub(/^#{domain.scoped_full_name}::/, "")
22
25
 
23
- {
26
+ sugary_type_declaration.declaration_data = {
24
27
  type: :active_record,
25
- model_class: active_record_class.name,
28
+ model_class: klass.name,
26
29
  name:,
27
30
  model_base_class: active_record_superclass.name,
28
- model_module: Util.module_for(active_record_class)&.name,
29
- primary_key: active_record_class.primary_key,
30
- attributes_declaration: active_record_class_to_attributes_declaration(active_record_class)
31
+ model_module: Util.module_for(klass)&.name,
32
+ primary_key: klass.primary_key,
33
+ attributes_declaration: active_record_class_to_attributes_declaration(klass)
31
34
  }
35
+
36
+ sugary_type_declaration.is_duped = true
37
+ sugary_type_declaration.is_deep_duped = true
38
+
39
+ sugary_type_declaration
32
40
  end
33
41
 
34
42
  def column_to_foobara_type_declaration(column)
@@ -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
- active_record_class.foobara_attributes_type = handler.process_value!(attributes_type_declaration)
16
+ active_record_class.foobara_attributes_type = TypeDeclarations.strict do
17
+ handler.process_value!(TypeDeclaration.new(attributes_type_declaration))
18
+ end
17
19
 
18
20
  type.element_types = active_record_class.foobara_attributes_type.element_types
19
21
  type_name = type.declaration_data[:name]
@@ -6,14 +6,24 @@ module Foobara
6
6
  module Desugarizers
7
7
  class RegisteredActiveRecordBaseClassDesugarizer < TypeDeclarations::Desugarizer
8
8
  def applicable?(sugary_type_declaration)
9
- sugary_type_declaration.is_a?(Class) && sugary_type_declaration < ActiveRecord::Base &&
10
- sugary_type_declaration.foobara_type
9
+ if sugary_type_declaration.class?
10
+ klass = sugary_type_declaration.declaration_data
11
+
12
+ if klass < ActiveRecord::Base
13
+ klass.foobara_type
14
+ end
15
+ end
11
16
  end
12
17
 
13
- def desugarize(active_record_class)
14
- {
15
- type: active_record_class.foobara_type.foobara_manifest_reference.to_sym
16
- }
18
+ def desugarize(sugary_declaration)
19
+ klass = sugary_declaration.declaration_data
20
+ type = klass.foobara_type
21
+
22
+ sugary_declaration.type = type
23
+ sugary_declaration.declaration_data = type.foobara_manifest_reference.to_sym
24
+ sugary_declaration.is_strict = true
25
+
26
+ sugary_declaration
17
27
  end
18
28
 
19
29
  def priority
@@ -6,8 +6,10 @@ module Foobara
6
6
  module Desugarizers
7
7
  class UnregisteredActiveRecordBaseClassDesugarizer < TypeDeclarations::Desugarizer
8
8
  def applicable?(sugary_type_declaration)
9
- sugary_type_declaration.is_a?(Class) && sugary_type_declaration < ActiveRecord::Base &&
10
- !sugary_type_declaration.foobara_type
9
+ if sugary_type_declaration.class?
10
+ klass = sugary_type_declaration.declaration_data
11
+ klass < ActiveRecord::Base && !klass.foobara_type
12
+ end
11
13
  end
12
14
 
13
15
  # We will create the foobara type from the active record class and then the
@@ -15,13 +17,16 @@ module Foobara
15
17
  # will handle it properly.
16
18
  # This will keep declarations using just the active record class simple in the first place they are used
17
19
  # by acting as if it were a registered type at the time even though it wasn't yet.
18
- def desugarize(active_record_class)
20
+ def desugarize(sugary_type_declaration)
21
+ klass = sugary_type_declaration.declaration_data
22
+
19
23
  handler = handler_for_class(Foobara::ActiveRecordType::ExtendActiveRecordTypeDeclaration)
20
- handler.process_value!(active_record_class)
24
+ handler.process_value!(sugary_type_declaration)
25
+
26
+ sugary_type_declaration.declaration_data = klass.foobara_type.foobara_manifest_reference.to_sym
27
+ sugary_type_declaration.handle_symbolic_declaration
21
28
 
22
- {
23
- type: active_record_class.foobara_type.foobara_manifest_reference.to_sym
24
- }
29
+ sugary_type_declaration
25
30
  end
26
31
 
27
32
  def priority
@@ -1,9 +1,10 @@
1
1
  module Foobara
2
2
  module ActiveRecordType
3
3
  class ExtendActiveRecordTypeDeclaration < TypeDeclarations::Handlers::ExtendDetachedEntityTypeDeclaration
4
- def applicable?(*args, **opts, &)
5
- arg = args.first
6
- (arg.is_a?(Class) && arg < ActiveRecord::Base) || super
4
+ def applicable?(sugary_type_declaration)
5
+ if sugary_type_declaration.class?
6
+ sugary_type_declaration.declaration_data < ActiveRecord::Base
7
+ end || super
7
8
  end
8
9
 
9
10
  def expected_type_symbol
@@ -4,7 +4,9 @@ module Foobara
4
4
  class ActiveRecordAtomicSerializer < AtomicSerializer
5
5
  def serialize(object)
6
6
  if object.is_a?(ActiveRecord::Base)
7
- super(object.attributes)
7
+ super(
8
+ entities_to_primary_keys_serializer.serialize(object.attributes)
9
+ )
8
10
  else
9
11
  super
10
12
  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.14
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord
@@ -29,14 +29,20 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.1.1
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: 2.0.0
33
36
  type: :runtime
34
37
  prerelease: false
35
38
  version_requirements: !ruby/object:Gem::Requirement
36
39
  requirements:
37
40
  - - ">="
38
41
  - !ruby/object:Gem::Version
39
- version: '0'
42
+ version: 0.1.1
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.0
40
46
  email:
41
47
  - azimux@gmail.com
42
48
  executables: []
@@ -90,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
96
  - !ruby/object:Gem::Version
91
97
  version: '0'
92
98
  requirements: []
93
- rubygems_version: 3.6.3
99
+ rubygems_version: 3.6.9
94
100
  specification_version: 4
95
101
  summary: Provides a detached entity foobara type for Active Record classes
96
102
  test_files: []