plutonium 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 775b695dd0cd3f04c4817bef87ae0f8e5b8fabb585fc5e63e81cfae06af2b14f
|
4
|
+
data.tar.gz: 1441e95717e7f77364ea475921ca39650754081d0c713a9c8faf9a1f7c6591fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71c47b2bc994e2ce899e604360059e4f517f89224f693266e7a81ff51bc350db8aaf81b87680a4bef8cac13fe8ea1283eb57b996693cfebc5aada1c59836fcff
|
7
|
+
data.tar.gz: 6f410b2938d5909aca6ddcb960766f65a37fc706e659a733e497f51a651ffb0a2ac56a336ae046d7ce043d052b85fc4b3703c1d00a701722304db5b6cfccfba2
|
@@ -43,8 +43,6 @@ module Pu
|
|
43
43
|
template "app/definitions/resource_definition.rb",
|
44
44
|
"packages/#{package_namespace}/app/definitions/#{package_namespace}/#{resource.underscore}_definition.rb"
|
45
45
|
end
|
46
|
-
# template "app/presenters/resource_presenter.rb", "packages/#{package_namespace}/app/presenters/#{package_namespace}/#{resource.underscore}_presenter.rb" unless expected_parent_presenter
|
47
|
-
# template "app/query_objects/resource_query_object.rb", "packages/#{package_namespace}/app/query_objects/#{package_namespace}/#{resource.underscore}_query_object.rb" unless expected_parent_query_object
|
48
46
|
|
49
47
|
template "app/controllers/resource_controller.rb",
|
50
48
|
"packages/#{package_namespace}/app/controllers/#{package_namespace}/#{resource.pluralize.underscore}_controller.rb"
|
@@ -88,24 +86,6 @@ module Pu
|
|
88
86
|
expected_parent_policy || "ResourcePolicy"
|
89
87
|
end
|
90
88
|
|
91
|
-
def expected_parent_presenter
|
92
|
-
expected_parent_presenter = "::#{resource_class.classify}Presenter".safe_constantize
|
93
|
-
expected_parent_presenter if expected_parent_presenter.present? && expected_parent_presenter < ::ResourcePresenter
|
94
|
-
end
|
95
|
-
|
96
|
-
def parent_presenter
|
97
|
-
expected_parent_presenter || "ResourcePresenter"
|
98
|
-
end
|
99
|
-
|
100
|
-
def expected_parent_query_object
|
101
|
-
expected_parent_query_object = "::#{resource_class.classify}QueryObject".safe_constantize
|
102
|
-
expected_parent_query_object if expected_parent_query_object.present? && expected_parent_query_object < ::ResourceQueryObject
|
103
|
-
end
|
104
|
-
|
105
|
-
def parent_query_object
|
106
|
-
expected_parent_query_object || "ResourceQueryObject"
|
107
|
-
end
|
108
|
-
|
109
89
|
def expected_parent_definition
|
110
90
|
expected_parent_definition = "::#{resource_class.classify}Definition".safe_constantize
|
111
91
|
expected_parent_definition if expected_parent_definition.present? && expected_parent_definition < ::ResourceDefinition
|
@@ -90,17 +90,6 @@ module Plutonium
|
|
90
90
|
)
|
91
91
|
end
|
92
92
|
|
93
|
-
# Creates a resource presenter
|
94
|
-
# @param [Class] resource_class The resource class
|
95
|
-
# @param [ActiveRecord::Base] resource_record The resource record
|
96
|
-
# @return [Object] The resource presenter
|
97
|
-
def resource_presenter(resource_class, resource_record)
|
98
|
-
presenter_class = [current_package, "#{resource_class}Presenter"].compact.join("::").constantize
|
99
|
-
presenter_class.new resource_context, resource_record
|
100
|
-
rescue NameError
|
101
|
-
super
|
102
|
-
end
|
103
|
-
|
104
93
|
# Creates a resource definition
|
105
94
|
# @param [Class] resource_class The resource class
|
106
95
|
# @return [Object] The resource definition
|
@@ -111,17 +100,6 @@ module Plutonium
|
|
111
100
|
super
|
112
101
|
end
|
113
102
|
|
114
|
-
# Creates a resource query object
|
115
|
-
# @param [Class] resource_class The resource class
|
116
|
-
# @param [ActionController::Parameters] params The request parameters
|
117
|
-
# @return [Object] The resource query object
|
118
|
-
def resource_query_object(resource_class, params)
|
119
|
-
query_object_class = [current_package, "#{resource_class}QueryObject"].compact.join("::").constantize
|
120
|
-
query_object_class.new resource_context, params
|
121
|
-
rescue NameError
|
122
|
-
super
|
123
|
-
end
|
124
|
-
|
125
103
|
# Applies submitted resource params if they have been passed
|
126
104
|
def maybe_apply_submitted_resource_params!
|
127
105
|
ensure_get_request
|
@@ -8,11 +8,6 @@ module Plutonium
|
|
8
8
|
helper_method :raw_resource_query_params, :current_query_object
|
9
9
|
end
|
10
10
|
|
11
|
-
def resource_query_object(resource_class, params)
|
12
|
-
query_object_class = "#{resource_class}QueryObject".constantize
|
13
|
-
query_object_class.new resource_context, params
|
14
|
-
end
|
15
|
-
|
16
11
|
def current_query_object
|
17
12
|
@current_query_object ||=
|
18
13
|
Plutonium::Resource::QueryObject.new(resource_class, raw_resource_query_params, request.path) do |query_object|
|
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.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Froelich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -784,7 +784,6 @@ files:
|
|
784
784
|
- lib/plutonium/resource/definition.rb
|
785
785
|
- lib/plutonium/resource/interaction.rb
|
786
786
|
- lib/plutonium/resource/policy.rb
|
787
|
-
- lib/plutonium/resource/presenter.rb
|
788
787
|
- lib/plutonium/resource/query_object.rb
|
789
788
|
- lib/plutonium/resource/record.rb
|
790
789
|
- lib/plutonium/resource/register.rb
|
@@ -1,111 +0,0 @@
|
|
1
|
-
module Plutonium
|
2
|
-
module Resource
|
3
|
-
# Presenter class to define actions and fields for a resource
|
4
|
-
# @abstract
|
5
|
-
class Presenter
|
6
|
-
include Plutonium::Core::Definers::FieldDefiner
|
7
|
-
include Plutonium::Core::Definers::ActionDefiner
|
8
|
-
include Plutonium::Core::Definers::AssociationRendererDefiner
|
9
|
-
|
10
|
-
# Initializes the presenter with context and resource record
|
11
|
-
# @param [Object] context The context in which the presenter is used
|
12
|
-
# @param [ActiveRecord::Base] resource_record The resource record being presented
|
13
|
-
def initialize(context, resource_record)
|
14
|
-
@context = context
|
15
|
-
@resource_record = resource_record
|
16
|
-
|
17
|
-
define_standard_actions
|
18
|
-
define_actions
|
19
|
-
define_fields
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_reader :context, :resource_record
|
25
|
-
|
26
|
-
# Define fields for the resource
|
27
|
-
# @note Override this in child presenters for custom field definitions
|
28
|
-
def define_fields
|
29
|
-
end
|
30
|
-
|
31
|
-
# Define actions for the resource
|
32
|
-
# @note Override this in child presenters for custom action definitions
|
33
|
-
def define_actions
|
34
|
-
end
|
35
|
-
|
36
|
-
# Define standard actions for the resource
|
37
|
-
def define_standard_actions
|
38
|
-
define_action Plutonium::Core::Actions::NewAction.new(:new)
|
39
|
-
define_action Plutonium::Core::Actions::ShowAction.new(:show)
|
40
|
-
define_action Plutonium::Core::Actions::EditAction.new(:edit)
|
41
|
-
define_action Plutonium::Core::Actions::DestroyAction.new(:destroy)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Define an interactive action
|
45
|
-
# @param [Symbol] name The name of the action
|
46
|
-
# @param [Object] interaction The interaction object
|
47
|
-
# @param [Hash] options Additional options for the action
|
48
|
-
# @note This should be moved to its own definer
|
49
|
-
def define_interactive_action(name, interaction:, **)
|
50
|
-
define_action Plutonium::Core::Actions::InteractiveAction.new(name, interaction:, **)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Define a nested input for the resource
|
54
|
-
# @param [Symbol] name The name of the input
|
55
|
-
# @param [Array] inputs The inputs for the nested field
|
56
|
-
# @param [Class, nil] model_class The model class for the nested field
|
57
|
-
# @param [Hash] options Additional options for the nested field
|
58
|
-
# @yield [input] Gives the input object to the block
|
59
|
-
# @note This should be moved to its own definer
|
60
|
-
# @raise [ArgumentError] if model_class is not provided for polymorphic associations
|
61
|
-
def define_nested_input(name, inputs:, model_class: nil, **options)
|
62
|
-
nested_attribute_options = resource_class.all_nested_attributes_options[name]
|
63
|
-
|
64
|
-
nested_attribute_options_class = nested_attribute_options&.[](:class)
|
65
|
-
if nested_attribute_options_class.nil? && model_class.nil?
|
66
|
-
raise ArgumentError, "model_class is required if your field is not an association or is polymorphic. also ensure you have called `accepts_nested_attributes_for :#{name}`"
|
67
|
-
end
|
68
|
-
model_class ||= nested_attribute_options_class
|
69
|
-
|
70
|
-
macro = nested_attribute_options&.[](:macro)
|
71
|
-
allow_destroy = nested_attribute_options&.[](:allow_destroy).presence
|
72
|
-
update_only = nested_attribute_options&.[](:update_only).presence
|
73
|
-
limit = determine_nested_input_limit(macro, options[:limit], nested_attribute_options&.[](:limit))
|
74
|
-
|
75
|
-
input = Plutonium::Core::Fields::Inputs::NestedInput.new(
|
76
|
-
name,
|
77
|
-
inputs:,
|
78
|
-
allow_destroy: options.key?(:allow_destroy) ? options[:allow_destroy] : allow_destroy,
|
79
|
-
update_only: options.key?(:update_only) ? options[:update_only] : update_only,
|
80
|
-
limit: limit,
|
81
|
-
resource_class: model_class,
|
82
|
-
**options
|
83
|
-
)
|
84
|
-
yield input if block_given?
|
85
|
-
|
86
|
-
define_field_input name, input:
|
87
|
-
end
|
88
|
-
|
89
|
-
# Determines the limit for a nested input
|
90
|
-
# @param [Symbol, nil] macro The macro of the association
|
91
|
-
# @param [Integer, nil] option_limit The limit provided in options
|
92
|
-
# @param [Integer, nil] nested_attribute_limit The limit from nested attributes
|
93
|
-
# @return [Integer, nil] The determined limit
|
94
|
-
def determine_nested_input_limit(macro, option_limit, nested_attribute_limit)
|
95
|
-
if %i[belongs_to has_one].include? macro
|
96
|
-
1
|
97
|
-
elsif option_limit
|
98
|
-
option_limit
|
99
|
-
else
|
100
|
-
nested_attribute_limit
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Returns the resource class
|
105
|
-
# @return [Class] The resource class
|
106
|
-
def resource_class
|
107
|
-
context.resource_class
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|