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 +4 -4
- data/CHANGELOG.md +9 -0
- data/app/views/resource/_resource_details.rabl +44 -1
- data/app/views/resource/index.rabl +44 -1
- data/app/views/resource/show.rabl +44 -1
- data/lib/plutonium/resource/controller.rb +7 -3
- data/lib/plutonium/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: deab839931f92af77c0fb4ab8407874304b3078a025edfa66f7fd09699c2eba0
|
|
4
|
+
data.tar.gz: 5fd214919cffc4111f162a8528631ae8e58eb0a16612a9a27e5e3efe81fb99ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 723c3ab676d3a5d702e791fb6176a70a4c17700172916435d90cc9ce76442f7dd22bd005cc96b83f63f38ccd0b77001d0a2a04d2e32a20145f4f662cb1a25b00
|
|
7
|
+
data.tar.gz: baba8ae6b8123743e99f5aed06ddbb8f2ae77acd69c1765d0f093677b55ed3044d63b9b1986bbfbe51506be070f4b7cfcd656c596de637e360d473fd11a680aa
|
data/CHANGELOG.md
CHANGED
|
@@ -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
|
-
|
|
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
|
|
40
|
+
return _resource_class if _resource_class
|
|
38
41
|
|
|
39
|
-
|
|
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
|
data/lib/plutonium/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2025-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: zeitwerk
|