plutonium 0.27.0 → 0.28.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: 429c40389e06fd8b0dd3a490515561c4819adda14e3837107426eb74101880d4
4
- data.tar.gz: 7f11c16faa7b0e0972007afdced5713d13e4cb2a48397632938f19a56c1f6d90
3
+ metadata.gz: deab839931f92af77c0fb4ab8407874304b3078a025edfa66f7fd09699c2eba0
4
+ data.tar.gz: 5fd214919cffc4111f162a8528631ae8e58eb0a16612a9a27e5e3efe81fb99ca
5
5
  SHA512:
6
- metadata.gz: 8a74e71f54e4d3bd8bde88cb9c02c7f80bba61d5ed01ca20d62aa4559537073c35aeb94b1d9dcab3639b691279d8d8c7a88b1ae2e1da2a7ec26226e1835f251c
7
- data.tar.gz: 44aa9125097ade4af6efda8f214bf9ba31cb59792bfa6660e303bb558bfa6da469921aa4954796ee948ca8403f471de3ec013de49abb46f6c83dd6a65b2e3f10
6
+ metadata.gz: 723c3ab676d3a5d702e791fb6176a70a4c17700172916435d90cc9ce76442f7dd22bd005cc96b83f63f38ccd0b77001d0a2a04d2e32a20145f4f662cb1a25b00
7
+ data.tar.gz: baba8ae6b8123743e99f5aed06ddbb8f2ae77acd69c1765d0f093677b55ed3044d63b9b1986bbfbe51506be070f4b7cfcd656c596de637e360d473fd11a680aa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.28.0] - 2025-11-12
2
+
3
+ ### 🚀 Features
4
+
5
+ - Add sgid support and improve association serialization in API
6
+
7
+ ### 🐛 Bug Fixes
8
+
9
+ - Make controller_for inheritable and respect custom inflections
1
10
  ## [0.27.0] - 2025-11-05
2
11
 
3
12
  ### 🚀 Features
@@ -1,5 +1,48 @@
1
1
  attributes :id
2
- attributes(*permitted_attributes)
3
2
  attributes :created_at, :updated_at
4
3
 
4
+ node(:sgid) { |resource| resource.to_signed_global_id.to_s }
5
+
6
+ # Serialize attributes, converting associations to nested objects
7
+ permitted_attributes.each do |attr|
8
+ reflection = resource_class.reflect_on_association(attr)
9
+
10
+ if reflection
11
+ # Serialize association as ID(s) and sgid(s)
12
+ case reflection.macro
13
+ when :belongs_to
14
+ # Use foreign key directly for belongs_to
15
+ node(:"#{attr}_id") do |resource|
16
+ resource.public_send(reflection.foreign_key)
17
+ end
18
+ # Include sgid for form submissions
19
+ node(:"#{attr}_sgid") do |resource|
20
+ resource.public_send(:"#{attr}_sgid")&.to_s
21
+ end
22
+ when :has_many, :has_and_belongs_to_many
23
+ # Return array of IDs for collections
24
+ node(:"#{attr.to_s.singularize}_ids") do |resource|
25
+ resource.public_send(attr).pluck(:id)
26
+ end
27
+ # Include sgids for form submissions
28
+ node(:"#{attr.to_s.singularize}_sgids") do |resource|
29
+ resource.public_send(:"#{attr.to_s.singularize}_sgids").map(&:to_s)
30
+ end
31
+ when :has_one
32
+ # Return single ID for has_one
33
+ node(:"#{attr}_id") do |resource|
34
+ associated_record = resource.public_send(attr)
35
+ associated_record&.id
36
+ end
37
+ # Include sgid for form submissions
38
+ node(:"#{attr}_sgid") do |resource|
39
+ resource.public_send(:"#{attr}_sgid")&.to_s
40
+ end
41
+ end
42
+ else
43
+ # Regular attribute
44
+ attributes attr
45
+ end
46
+ end
47
+
5
48
  node(:url) { |resource| resource_url_for(resource) }
@@ -1,7 +1,50 @@
1
1
  collection @resource_records, root: resource_class.to_s.demodulize.underscore.pluralize.to_sym, object_root: false
2
2
 
3
3
  attributes :id
4
- attributes(*current_policy.permitted_attributes_for_index)
5
4
  attributes :created_at, :updated_at
6
5
 
6
+ node(:sgid) { |resource| resource.to_signed_global_id.to_s }
7
+
8
+ # Serialize attributes, converting associations to nested objects
9
+ current_policy.permitted_attributes_for_index.each do |attr|
10
+ reflection = resource_class.reflect_on_association(attr)
11
+
12
+ if reflection
13
+ # Serialize association as ID(s) and sgid(s)
14
+ case reflection.macro
15
+ when :belongs_to
16
+ # Use foreign key directly for belongs_to
17
+ node(:"#{attr}_id") do |resource|
18
+ resource.public_send(reflection.foreign_key)
19
+ end
20
+ # Include sgid for form submissions
21
+ node(:"#{attr}_sgid") do |resource|
22
+ resource.public_send(:"#{attr}_sgid")&.to_s
23
+ end
24
+ when :has_many, :has_and_belongs_to_many
25
+ # Return array of IDs for collections
26
+ node(:"#{attr.to_s.singularize}_ids") do |resource|
27
+ resource.public_send(attr).pluck(:id)
28
+ end
29
+ # Include sgids for form submissions
30
+ node(:"#{attr.to_s.singularize}_sgids") do |resource|
31
+ resource.public_send(:"#{attr.to_s.singularize}_sgids").map(&:to_s)
32
+ end
33
+ when :has_one
34
+ # Return single ID for has_one
35
+ node(:"#{attr}_id") do |resource|
36
+ associated_record = resource.public_send(attr)
37
+ associated_record&.id
38
+ end
39
+ # Include sgid for form submissions
40
+ node(:"#{attr}_sgid") do |resource|
41
+ resource.public_send(:"#{attr}_sgid")&.to_s
42
+ end
43
+ end
44
+ else
45
+ # Regular attribute
46
+ attributes attr
47
+ end
48
+ end
49
+
7
50
  node(:url) { |resource| resource_url_for(resource) }
@@ -1,7 +1,50 @@
1
1
  object @resource_record
2
2
 
3
3
  attributes :id
4
- attributes(*current_policy.permitted_attributes_for_show)
5
4
  attributes :created_at, :updated_at
6
5
 
6
+ node(:sgid) { |resource| resource.to_signed_global_id.to_s }
7
+
8
+ # Serialize attributes, converting associations to nested objects
9
+ current_policy.permitted_attributes_for_show.each do |attr|
10
+ reflection = resource_class.reflect_on_association(attr)
11
+
12
+ if reflection
13
+ # Serialize association as ID(s) and sgid(s)
14
+ case reflection.macro
15
+ when :belongs_to
16
+ # Use foreign key directly for belongs_to
17
+ node(:"#{attr}_id") do |resource|
18
+ resource.public_send(reflection.foreign_key)
19
+ end
20
+ # Include sgid for form submissions
21
+ node(:"#{attr}_sgid") do |resource|
22
+ resource.public_send(:"#{attr}_sgid")&.to_s
23
+ end
24
+ when :has_many, :has_and_belongs_to_many
25
+ # Return array of IDs for collections
26
+ node(:"#{attr.to_s.singularize}_ids") do |resource|
27
+ resource.public_send(attr).pluck(:id)
28
+ end
29
+ # Include sgids for form submissions
30
+ node(:"#{attr.to_s.singularize}_sgids") do |resource|
31
+ resource.public_send(:"#{attr.to_s.singularize}_sgids").map(&:to_s)
32
+ end
33
+ when :has_one
34
+ # Return single ID for has_one
35
+ node(:"#{attr}_id") do |resource|
36
+ associated_record = resource.public_send(attr)
37
+ associated_record&.id
38
+ end
39
+ # Include sgid for form submissions
40
+ node(:"#{attr}_sgid") do |resource|
41
+ resource.public_send(:"#{attr}_sgid")&.to_s
42
+ end
43
+ end
44
+ else
45
+ # Regular attribute
46
+ attributes attr
47
+ end
48
+ end
49
+
7
50
  node(:url) { |resource| resource_url_for(resource) }
@@ -20,6 +20,9 @@ module Plutonium
20
20
  after_action { pagy_headers_merge(@pagy) if @pagy }
21
21
 
22
22
  helper_method :current_parent, :resource_record!, :resource_record?, :resource_param_key, :resource_class
23
+
24
+ # Use class_attribute for proper inheritance
25
+ class_attribute :_resource_class, instance_accessor: false
23
26
  end
24
27
 
25
28
  class_methods do
@@ -28,15 +31,16 @@ module Plutonium
28
31
  # Sets the resource class for the controller
29
32
  # @param [ActiveRecord::Base] resource_class The resource class
30
33
  def controller_for(resource_class)
31
- @resource_class = resource_class
34
+ self._resource_class = resource_class
32
35
  end
33
36
 
34
37
  # Gets the resource class for the controller
35
38
  # @return [ActiveRecord::Base] The resource class
36
39
  def resource_class
37
- return @resource_class if @resource_class
40
+ return _resource_class if _resource_class
38
41
 
39
- name.to_s.gsub(/^#{current_package}::/, "").gsub(/Controller$/, "").classify.constantize
42
+ # Use singularize + camelize to respect custom inflections
43
+ name.to_s.gsub(/^#{current_package}::/, "").gsub(/Controller$/, "").singularize.camelize.constantize
40
44
  rescue NameError
41
45
  raise NameError, "Failed to determine the resource class. Please call `controller_for(MyResource)` in #{name}."
42
46
  end
@@ -1,5 +1,5 @@
1
1
  module Plutonium
2
- VERSION = "0.27.0"
2
+ VERSION = "0.28.0"
3
3
  NEXT_MAJOR_VERSION = VERSION.split(".").tap { |v|
4
4
  v[1] = v[1].to_i + 1
5
5
  v[2] = 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plutonium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Froelich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-05 00:00:00.000000000 Z
11
+ date: 2025-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk