foobara-active-record-type 0.0.7 → 0.0.9

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: 2fb8165e3bfb7ae465f431ff850dd0532cb2fc6aca0e9fa740b9c4e565fb9435
4
- data.tar.gz: 58e8c95928e288579b146a8fb4c211762c592ff5bcbcd724b8c366c7429d922d
3
+ metadata.gz: ef9d7117540d6792f07286b6d6c73ef07124f69cfdb33cd2456614c2d7712ead
4
+ data.tar.gz: 8d3479a3abd3fe8aa0e52dbaaf27b17d99c6e41e85c9edf5948097e2d3494a9c
5
5
  SHA512:
6
- metadata.gz: 046b7568fc5cfa44f594dfbbbcbccbc3c440cb2d823d1553a685ddb2594f27131c67fd51822570fc479138150cdb6833efce86ef22bb9ef91c4891a8002365e4
7
- data.tar.gz: bf00cb2ec0b879d7c4fbdad793f012d460f4da31aa134ea7f6c656054269e85f797e5c7931156d3dfa9bd39c8eb1850ba50bd75e83cbbe749fffa93442066f38
6
+ metadata.gz: 2121dcd3d9c61a860347e487631e2e9b5420bcd691f5f97d86d7ef2bd9e93320af60dc66d0c1b878e75ccfac2a819d2fe826d3f17e8b721ba5876a344d2eb7e6
7
+ data.tar.gz: fc18a7d564dd316258f0e87317575781a197e31e5cdbf0a725a6dcce622192f573c3b388d995fea0c064ba09dfca90f57e5088a073cf248a37de23c2c02d5012
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.9] - 2025-01-28
2
+
3
+ - Fix problem with attributes declaration validator breaking things
4
+
5
+ ## [0.0.8] - 2025-01-25
6
+
7
+ - Add some serializers to handle active record serialization
8
+
1
9
  ## [0.0.7] - 2025-01-22
2
10
 
3
11
  - Make use of ModelAttributeHelpers
@@ -10,17 +10,26 @@ module Foobara
10
10
  TypeDeclarations.register_type_declaration(ExtendActiveRecordTypeDeclaration.new)
11
11
 
12
12
  detached_entity = Namespace.global.foobara_lookup_type!(:detached_entity)
13
- BuiltinTypes.build_and_register!(
13
+ type = BuiltinTypes.build_and_register!(
14
14
  :active_record,
15
15
  detached_entity,
16
16
  nil,
17
17
  type_module: Foobara::ActiveRecordType
18
18
  )
19
+ type.remove_processor_by_symbol(:attributes_declaration)
19
20
 
20
21
  BuiltinTypes.install_type_declaration_extensions_for(ExtendActiveRecordTypeDeclaration)
21
22
 
22
23
  ActiveRecord::Base.include ModelAttributeHelpers::Concerns::AttributeHelpers
23
24
  ActiveRecord::Base.include ActiveRecordFoobaraMethods
25
+
26
+ if defined?(Foobara::CommandConnectors::RailsCommandConnector)
27
+ Foobara::CommandConnectors::RailsCommandConnector.default_serializers = [
28
+ Foobara::CommandConnectors::Serializers::ErrorsSerializer,
29
+ Foobara::CommandConnectors::Serializers::ActiveRecordAtomicSerializer,
30
+ Foobara::CommandConnectors::Serializers::JsonSerializer
31
+ ]
32
+ end
24
33
  end
25
34
 
26
35
  def reset_all
@@ -18,11 +18,6 @@ module Foobara
18
18
  type.element_types = active_record_class.foobara_attributes_type.element_types
19
19
  type_name = type.declaration_data[:name]
20
20
 
21
- # We don't want to check that the active record is valid as if it were a model
22
- type.validators.delete_if do |validator|
23
- validator.symbol == :attributes_declaration
24
- end
25
-
26
21
  domain = Domain.domain_through_modules(active_record_class)
27
22
  domain.foobara_register_type(type_name, type)
28
23
  end
@@ -0,0 +1,15 @@
1
+ module Foobara
2
+ module CommandConnectors
3
+ module Serializers
4
+ class ActiveRecordAggregateSerializer < AggregateSerializer
5
+ def serialize(object)
6
+ if object.is_a?(ActiveRecord::Base)
7
+ super(object.attributes)
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Foobara
2
+ module CommandConnectors
3
+ module Serializers
4
+ class ActiveRecordAtomicSerializer < AtomicSerializer
5
+ def serialize(object)
6
+ if object.is_a?(ActiveRecord::Base)
7
+ super(object.attributes)
8
+ else
9
+ super
10
+ end
11
+ end
12
+
13
+ def entities_to_primary_keys_serializer
14
+ @entities_to_primary_keys_serializer ||= ActiveRecordEntitiesToPrimaryKeysSerializer.new(declaration_data)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require "foobara/command_connectors"
2
+
3
+ module Foobara
4
+ module CommandConnectors
5
+ module Serializers
6
+ class ActiveRecordEntitiesToPrimaryKeysSerializer < EntitiesToPrimaryKeysSerializer
7
+ def serialize(object)
8
+ if object.is_a?(ActiveRecord::Base)
9
+ attribute = object.class.primary_key
10
+ object.send(attribute)
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ 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.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-23 00:00:00.000000000 Z
10
+ date: 2025-01-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord
@@ -65,6 +65,9 @@ files:
65
65
  - src/extend_active_record_type_declaration/validate_primary_key_is_symbol.rb
66
66
  - src/extend_active_record_type_declaration/validate_primary_key_present.rb
67
67
  - src/extend_active_record_type_declaration/validate_primary_key_references_attribute.rb
68
+ - src/serializers/active_record_aggregate_serializer.rb
69
+ - src/serializers/active_record_atomic_serializer.rb
70
+ - src/serializers/active_record_entities_to_primary_keys_serializer.rb
68
71
  homepage: https://github.com/foobara/active-record-type
69
72
  licenses:
70
73
  - MPL-2.0