active_type 2.7.1 → 2.8.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: df3259ce05681161eb2d36e1faeeaf8a781c2afc498558ed8748ef0f541d528e
4
- data.tar.gz: b9f43820607fc7d64939d68df97090a1cc5ec769a9550e52f7973b061b94d4cc
3
+ metadata.gz: 28986180d23a749310c496d900fc83b79ca4bfe305704f2bb93ec6a8c69cf131
4
+ data.tar.gz: 6647ff958ee1be018e654c7689fa333fa3789c1fcb972b6125a4f9e65c0a2aaa
5
5
  SHA512:
6
- metadata.gz: c299ec682c2fe1b5e55e6290236cd8c44cc5065aacc8ff260f995c5a193a6f960d071c6cff9a6a6bbcf8275dc8a89bd574ab90b75f000978c94eafbb1753870b
7
- data.tar.gz: d4cf836aebff7ca9288a0fdc8717b85854453b7c9bde7509d0a11040125fce9fefd1e0c86f33405bba4b9d5947eda80aac04772d0c8792c065ed51b03ab13b3d
6
+ metadata.gz: 18f57bad0539e91f6725ccfd63ceb6faa32a23d96b9033d0bbc240b62f475dd385d03e395f7ba82646078e64add7bc26241848f0c9177568e29699404355c346
7
+ data.tar.gz: 13de6f297c36eb2e2dc75c719f1e8a858a783576f9aaf322e4c46654ae8ee578a8299f73aee651bd64e395ec2dd3a09a6fc02f0b4cbc2977a2ba26c7556d3592
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 2.8.0 (2026-01-22)
6
+ * Added: Add support `attributes_for_inspect` on ActiveType::Object.
7
+ Tanks to @makmic.
8
+
5
9
  ## 2.7.1 (2025-11-03)
6
10
  * Fixed: Removed some unnecessary files from the packaged gem. Gets rid of symlink warnings during installation.
7
11
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveType
4
- VERSION = '2.7.1'
4
+ VERSION = '2.8.0'
5
5
  end
@@ -134,6 +134,19 @@ module ActiveType
134
134
  result
135
135
  end
136
136
 
137
+ def self.attribute_for_inspect(value)
138
+ if value.is_a?(String) && value.length > 50
139
+ "#{value[0, 50]}...".inspect
140
+ elsif value.is_a?(Date) || value.is_a?(Time)
141
+ %("#{value.to_formatted_s(:db)}")
142
+ elsif value.is_a?(Array) && value.size > 10
143
+ inspected = value.first(10).inspect
144
+ %(#{inspected[0...-1]}, ...])
145
+ else
146
+ value.inspect
147
+ end
148
+ end
149
+
137
150
  extend ActiveSupport::Concern
138
151
 
139
152
  included do
@@ -141,6 +154,14 @@ module ActiveType
141
154
  class_attribute :virtual_columns_hash
142
155
  self.virtual_columns_hash = {}
143
156
 
157
+ if respond_to?(:attributes_for_inspect)
158
+ # 7.1 had [:id] as a default, we want a consistent default across all versions
159
+ self.attributes_for_inspect = :all
160
+ else
161
+ # ActiveRecord < 7.2
162
+ class_attribute :attributes_for_inspect, instance_accessor: false, default: :all
163
+ end
164
+
144
165
  class << self
145
166
  if method_defined?(:attribute)
146
167
  alias_method :ar_attribute, :attribute
@@ -270,25 +291,28 @@ module ActiveType
270
291
  virtual_attributes[name] = value
271
292
  end
272
293
 
273
- # Returns the contents of the record as a nicely formatted string.
294
+ def attributes_for_inspect
295
+ self.class.attributes_for_inspect == :all ? attributes.keys : self.class.attributes_for_inspect
296
+ end
297
+
274
298
  def inspect
275
- inspection = attributes.collect do |name, value|
276
- "#{name}: #{VirtualAttributes.attribute_for_inspect(value)}"
277
- end.sort.compact.join(", ")
278
- "#<#{self.class} #{inspection}>"
299
+ inspect_with_attributes(attributes_for_inspect)
279
300
  end
280
301
 
281
- def self.attribute_for_inspect(value)
282
- if value.is_a?(String) && value.length > 50
283
- "#{value[0, 50]}...".inspect
284
- elsif value.is_a?(Date) || value.is_a?(Time)
285
- %("#{value.to_formatted_s(:db)}")
286
- elsif value.is_a?(Array) && value.size > 10
287
- inspected = value.first(10).inspect
288
- %(#{inspected[0...-1]}, ...])
289
- else
290
- value.inspect
291
- end
302
+ def full_inspect
303
+ inspect_with_attributes(attributes.keys)
304
+ end
305
+
306
+ # Returns the contents of the record as a nicely formatted string.
307
+ def inspect_with_attributes(attribute_names)
308
+ inspection = attribute_names.collect do |name|
309
+ name = name.to_s
310
+ if attributes.key?(name)
311
+ value = attributes[name]
312
+ "#{name}: #{VirtualAttributes.attribute_for_inspect(value)}"
313
+ end
314
+ end.compact.sort.join(", ")
315
+ "#<#{self.class} #{inspection}>"
292
316
  end
293
317
 
294
318
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.6.7
106
+ rubygems_version: 3.6.9
107
107
  specification_version: 4
108
108
  summary: Make any Ruby object quack like ActiveRecord
109
109
  test_files: []