foobara-active-record-type 0.0.6 → 0.0.8

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: c68604cfe7a45eebcd95e02929f5756dbc0c703547f6deb9c0a7adb940cb938e
4
- data.tar.gz: 507df2c192c22ce5f58514314569cfe1314c24a35a0ded7ca62f020d6a3def3a
3
+ metadata.gz: 173e73fbfbc613a24ac317aacedbed070c7a311f79ce96f1afce275aa839f854
4
+ data.tar.gz: 84a8e463d431d639c16c80b983e4a10d663775f68b005d32fb2c71ad526e6d48
5
5
  SHA512:
6
- metadata.gz: cd16b65c7084969996655dd9bd24ed93c2481c80f1c17465d0b97f7b920cd6f30b007fe07c316037d1c91ad77921d4482c89b44988822767ed77e8056eb1601a
7
- data.tar.gz: 3f9963f87e6708158528ce25cd38544c37c7274c4d6b80e866afba080748e2794859b51097d871702a0ef13d88a8c8faf2796f6fcaca1896f18dd0e4bc035993
6
+ metadata.gz: 44346b0a6091909ec26e95df4cfd9d0d5987f0e34af5bbc0bcc9bc228384b7bb26ad1e56e3cfa55d985185f4adc30c7f892991610913eac9024033c1cd3ea769
7
+ data.tar.gz: f9769cac666e008a142e03f3a464dfd975962f6ba99eca98a412c35e0c12eb271043fc3cdbe28ce0aae8cf68d0c74219fb2f1fd46e7bb15481262685de7d4c84
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
- ## [0.0.6] - 2025-01-22
1
+ ## [0.0.8] - 2025-01-25
2
+
3
+ - Add some serializers to handle active record serialization
4
+
5
+ ## [0.0.7] - 2025-01-22
2
6
 
3
7
  - Make use of ModelAttributeHelpers
8
+ - Handle boolean column type
9
+ - Fix ActiveRecordThunk#== bug
4
10
 
5
11
  ## [0.0.3] - 2025-01-17
6
12
 
@@ -21,6 +21,14 @@ module Foobara
21
21
 
22
22
  ActiveRecord::Base.include ModelAttributeHelpers::Concerns::AttributeHelpers
23
23
  ActiveRecord::Base.include ActiveRecordFoobaraMethods
24
+
25
+ if defined?(Foobara::CommandConnectors::RailsCommandConnector)
26
+ Foobara::CommandConnectors::RailsCommandConnector.default_serializers = [
27
+ Foobara::CommandConnectors::Serializers::ErrorsSerializer,
28
+ Foobara::CommandConnectors::Serializers::ActiveRecordAtomicSerializer,
29
+ Foobara::CommandConnectors::Serializers::JsonSerializer
30
+ ]
31
+ end
24
32
  end
25
33
 
26
34
  def reset_all
@@ -51,6 +51,12 @@ module Foobara
51
51
  end
52
52
  # rubocop:enable Style/TrivialAccessors
53
53
 
54
+ def ==(other)
55
+ return false unless @foobara_primary_key
56
+
57
+ other.instance_of?(@foobara_active_record_class) && @foobara_primary_key == other.id
58
+ end
59
+
54
60
  private
55
61
 
56
62
  # TODO: there are probably several other methods that don't require loading
@@ -10,7 +10,7 @@ module Foobara
10
10
  column_type = column.sql_type_metadata.type
11
11
 
12
12
  type_declaration = case column_type
13
- when :integer, :string, :datetime
13
+ when :integer, :string, :datetime, :boolean
14
14
  column_type
15
15
  else
16
16
  # :nocov:
@@ -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.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-22 00:00:00.000000000 Z
10
+ date: 2025-01-25 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