plutonium 0.10.3 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -2
- data/app/assets/application.js.bk +31419 -0
- data/app/assets/plutonium-original.png +0 -0
- data/app/assets/plutonium-white.png +0 -0
- data/app/assets/plutonium.css +1 -0
- data/app/assets/plutonium.ico +0 -0
- data/app/assets/plutonium.js +12416 -0
- data/app/assets/plutonium.js.map +7 -0
- data/app/assets/plutonium.min.js +39 -0
- data/app/assets/plutonium.min.js.map +7 -0
- data/app/assets/plutonium.png +0 -0
- data/app/views/application/_flash_alerts.html.erb +2 -2
- data/app/views/application/_resource_header.html.erb +261 -697
- data/app/views/application/_resource_sidebar.html.erb +14 -12
- data/app/views/components/action_button/action_button_component.rb +3 -3
- data/app/views/components/attributes.rb +184 -0
- data/app/views/components/base.rb +19 -40
- data/app/views/components/block/block_component.html.erb +1 -1
- data/app/views/components/block/block_component.rb +11 -7
- data/app/views/components/breadcrumbs/breadcrumbs_component.rb +3 -3
- data/app/views/components/button/button_component.html.erb +2 -2
- data/app/views/components/button/button_component.rb +10 -5
- data/app/views/components/dyna_frame_content/dyna_frame_content_component.html.erb +1 -0
- data/app/views/components/dyna_frame_content/dyna_frame_content_component.rb +3 -3
- data/app/views/components/dyna_frame_host/dyna_frame_host_component.html.erb +1 -2
- data/app/views/components/dyna_frame_host/dyna_frame_host_component.rb +12 -5
- data/app/views/components/empty_card/empty_card_component.rb +3 -3
- data/app/views/components/form/form_builder.rb +1 -1
- data/app/views/components/form/form_component.rb +3 -3
- data/app/views/components/has_many_panel/has_many_panel_component.html.erb +25 -0
- data/app/views/components/has_many_panel/has_many_panel_component.rb +16 -0
- data/app/views/components/header/header_component.rb +3 -3
- data/app/views/components/interactive_action_form/interactive_action_form_component.rb +3 -3
- data/app/views/components/nav_grid_menu/nav_grid_menu_component.html.erb +24 -0
- data/app/views/components/nav_grid_menu/nav_grid_menu_component.rb +23 -0
- data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.html.erb +4 -0
- data/app/views/components/nav_grid_menu_item/nav_grid_menu_item_component.rb +20 -0
- data/app/views/components/nav_user/nav_user_component.html.erb +50 -0
- data/app/views/components/nav_user/nav_user_component.rb +32 -0
- data/app/views/components/nav_user_link/nav_user_link_component.html.erb +7 -0
- data/app/views/components/nav_user_link/nav_user_link_component.rb +23 -0
- data/app/views/components/nav_user_section/nav_user_section_component.html.erb +7 -0
- data/app/views/components/nav_user_section/nav_user_section_component.rb +18 -0
- data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.html.erb +1 -3
- data/app/views/components/nested_resource_form_fields/nested_resource_form_fields_component.rb +11 -5
- data/app/views/components/pagination/pagination_component.html.erb +1 -1
- data/app/views/components/pagination/pagination_component.rb +10 -7
- data/app/views/components/panel/panel_component.html.erb +13 -6
- data/app/views/components/panel/panel_component.rb +11 -5
- data/app/views/components/resource_header/resource_header_component.html.erb +83 -0
- data/app/views/components/resource_header/resource_header_component.rb +30 -0
- data/app/views/components/resource_layout/resource_layout_component.html.erb +49 -0
- data/app/views/components/resource_layout/resource_layout_component.rb +41 -0
- data/app/views/components/sidebar/sidebar_component.html.erb +3 -33
- data/app/views/components/sidebar/sidebar_component.rb +3 -3
- data/app/views/components/sidebar_menu/sidebar_menu_component.html.erb +4 -2
- data/app/views/components/sidebar_menu/sidebar_menu_component.rb +10 -6
- data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.html.erb +63 -71
- data/app/views/components/sidebar_menu_item/sidebar_menu_item_component.rb +27 -8
- data/app/views/components/skeleton/table/table_component.html.erb +1 -1
- data/app/views/components/skeleton/table/table_component.rb +3 -3
- data/app/views/components/table/table_component.html.erb +40 -89
- data/app/views/components/table/table_component.rb +124 -28
- data/app/views/components/table_search_input/table_search_input_component.html.erb +1 -1
- data/app/views/components/table_search_input/table_search_input_component.rb +11 -6
- data/app/views/components/table_toolbar/table_toolbar_component.html.erb +1 -1
- data/app/views/components/table_toolbar/table_toolbar_component.rb +11 -3
- data/app/views/components/toolbar/toolbar_component.html.erb +2 -2
- data/app/views/components/toolbar/toolbar_component.rb +16 -8
- data/app/views/layouts/resource.html.erb +12 -45
- data/app/views/layouts/rodauth.html.erb +20 -36
- data/app/views/resource/_interactive_resource_action_form.html.erb +1 -1
- data/app/views/resource/_resource_details.html.erb +8 -5
- data/app/views/resource/_resource_table.html.erb +70 -1
- data/app/views/resource/interactive_resource_collection_action.html.erb +1 -0
- data/app/views/resource/interactive_resource_record_action.html.erb +1 -0
- data/app/views/resource/interactive_resource_recordless_action.html.erb +1 -0
- data/app/views/resource/new.html.erb +1 -0
- data/config/initializers/simple_form.rb +22 -2
- data/esbuild.config.js +35 -31
- data/lib/generators/pu/core/assets/assets_generator.rb +44 -0
- data/lib/generators/pu/core/assets/templates/tailwind.config.js +18 -0
- data/lib/generators/pu/core/install/install_generator.rb +4 -1
- data/lib/generators/pu/gem/dotenv/templates/config/initializers/001_ensure_required_env.rb +6 -0
- data/lib/generators/pu/gen/component/component_generator.rb +13 -10
- data/lib/generators/pu/gen/component/templates/component.html.erb.tt +1 -1
- data/lib/generators/pu/gen/component/templates/component.rb.tt +10 -4
- data/lib/generators/pu/pkg/app/app_generator.rb +4 -4
- data/lib/generators/pu/pkg/app/templates/app/controllers/concerns/controller.rb.tt +28 -0
- data/lib/generators/pu/pkg/app/templates/app/controllers/controller.rb.tt +5 -0
- data/lib/generators/pu/pkg/app/templates/app/controllers/dashboard_controller.rb.tt +1 -1
- data/lib/generators/pu/res/conn/conn_generator.rb +4 -4
- data/lib/generators/pu/res/conn/templates/app/controllers/resource_controller.rb.tt +1 -1
- data/lib/generators/pu/res/model/model_generator.rb +3 -3
- data/lib/generators/pu/res/scaffold/templates/policy.rb.tt +6 -0
- data/lib/generators/pu/service/sidekiq/sidekiq_generator.rb +0 -5
- data/lib/generators/pu/service/sidekiq/templates/app/sidekiq/sidekiq_job.rb +0 -2
- data/lib/plutonium/config.rb +2 -14
- data/lib/plutonium/core/associations/renderers/basic_renderer.rb +28 -0
- data/lib/plutonium/core/associations/renderers/factory.rb +36 -0
- data/lib/plutonium/core/associations/renderers/has_many_renderer.rb +16 -0
- data/lib/plutonium/core/autodiscovery/association_renderer_discoverer.rb +31 -0
- data/lib/plutonium/core/controllers/authorizable.rb +13 -17
- data/lib/plutonium/core/controllers/base.rb +3 -7
- data/lib/plutonium/core/controllers/presentable.rb +6 -1
- data/lib/plutonium/core/definers/association_renderer_definer.rb +33 -0
- data/lib/plutonium/core/fields/inputs/checkbox_input.rb +13 -0
- data/lib/plutonium/core/fields/inputs/factory.rb +1 -0
- data/lib/plutonium/core/fields/inputs/polymorphic_belongs_to_association_input.rb +1 -1
- data/lib/plutonium/core/ui/detail.rb +1 -0
- data/lib/plutonium/helpers/application_helper.rb +8 -9
- data/lib/plutonium/helpers/assets_helper.rb +41 -0
- data/lib/plutonium/helpers/display_helper.rb +13 -0
- data/lib/plutonium/helpers/form_helper.rb +1 -1
- data/lib/plutonium/helpers.rb +1 -0
- data/lib/plutonium/icons.rb +12 -5
- data/lib/plutonium/pkg/app.rb +10 -0
- data/lib/plutonium/pundit/context.rb +18 -0
- data/lib/plutonium/pundit/policy_finder.rb +25 -0
- data/lib/plutonium/railtie.rb +26 -8
- data/lib/plutonium/reloader.rb +18 -7
- data/lib/plutonium/resource/controller.rb +4 -0
- data/lib/plutonium/resource/policy.rb +69 -47
- data/lib/plutonium/resource/presenter.rb +1 -0
- data/lib/plutonium/resource/query_object.rb +139 -130
- data/lib/plutonium/rodauth/controller_methods.rb +7 -3
- data/lib/plutonium/version.rb +1 -1
- data/lib/plutonium.rb +9 -57
- data/package-lock.json +782 -17
- data/package.json +31 -8
- data/postcss.config.js +17 -7
- data/src/.npmignore +2 -0
- data/src/js/controllers/color_mode_controller.js +41 -0
- data/src/js/controllers/frame_navigator_controller.js +99 -0
- data/src/js/controllers/has_many_panel_controller.js +8 -0
- data/src/js/controllers/nav_grid_menu_controller.js +8 -0
- data/src/js/controllers/nav_grid_menu_item_controller.js +8 -0
- data/{app/views/components/tab_bar/tab_bar_controller.js → src/js/controllers/nav_user_controller.js} +2 -2
- data/src/js/controllers/nav_user_link_controller.js +8 -0
- data/src/js/controllers/nav_user_section_controller.js +8 -0
- data/src/js/controllers/register_controllers.js +45 -0
- data/{app/assets/javascripts → src/js}/controllers/resource_dismiss_controller.js +2 -0
- data/{app/assets/javascripts → src/js}/controllers/resource_drop_down_controller.js +2 -0
- data/src/js/controllers/resource_header_controller.js +8 -0
- data/src/js/controllers/resource_layout_controller.js +8 -0
- data/src/js/controllers/sidebar_menu_controller.js +8 -0
- data/src/js/controllers/sidebar_menu_item_controller.js +8 -0
- data/src/js/core.js +4 -0
- data/{app/assets/javascripts/plutonium-app.js → src/js/plutonium.js} +1 -1
- data/{app/assets/javascripts → src/js}/turbo/turbo_debug.js +2 -4
- data/tailwind.config.js +85 -84
- metadata +73 -39
- data/app/assets/build/plutonium.js +0 -5122
- data/app/assets/javascripts/controllers/index.js +0 -34
- data/app/assets/javascripts/plutonium.js +0 -1
- data/app/views/application/_color_modes.html.erb +0 -57
- data/app/views/components/tab_bar/tab_bar_component.html.erb +0 -11
- data/app/views/components/tab_bar/tab_bar_component.rb +0 -9
- data/app/views/resource/_nav_user.html.erb +0 -4
- data/app/views/resource/_tab_menu.html.erb +0 -13
- data/css.manifest +0 -3
- data/js.manifest +0 -4
- data/lib/generators/pu/pkg/app/templates/app/controllers/app_controller.rb.tt +0 -5
- data/lib/generators/pu/pkg/app/templates/app/controllers/package_controller.rb.tt +0 -26
- data/public/plutonium-assets/application.css +0 -25086
- data/public/plutonium-assets/plutonium-app-36KN5FVJ.js +0 -6
- data/public/plutonium-assets/plutonium-app-36KN5FVJ.js.map +0 -7
- data/public/plutonium-assets/plutonium-app-6WILQCTT.js +0 -39
- data/public/plutonium-assets/plutonium-app-6WILQCTT.js.map +0 -7
- data/public/plutonium-assets/plutonium.2d4f0c333cd000051d3b.css +0 -3424
- data/public/plutonium-assets/plutonium.50232e35b5495f5ad90d.css +0 -3415
- data/public/plutonium-assets/plutonium.8bee7a8482988b0360e3.css +0 -3420
- /data/{app/assets/build → lib/generators/pu/core/assets/templates}/.keep +0 -0
- /data/{app/assets/stylesheets → src/css}/plutonium.css +0 -0
- /data/{app/views/components/form → src/js/controllers}/form_controller.js +0 -0
- /data/{app/views/components/interactive_action_form → src/js/controllers}/interactive_action_form_controller.js +0 -0
- /data/{app/views/components/nested_resource_form_fields → src/js/controllers}/nested_resource_form_fields_controller.js +0 -0
- /data/{app/views/components/table → src/js/controllers}/table_controller.js +0 -0
- /data/{app/views/components/table_search_input → src/js/controllers}/table_search_input_controller.js +0 -0
- /data/{app/views/components/table_toolbar → src/js/controllers}/table_toolbar_controller.js +0 -0
- /data/{app/views/components/toolbar → src/js/controllers}/toolbar_controller.js +0 -0
- /data/{app/assets/javascripts → src/js}/turbo/index.js +0 -0
- /data/{app/assets/javascripts → src/js}/turbo/turbo_actions.js +0 -0
- /data/{app/assets/javascripts → src/js}/turbo/turbo_frame_monkey_patch.js +0 -0
data/lib/plutonium/railtie.rb
CHANGED
@@ -6,27 +6,45 @@ module Plutonium
|
|
6
6
|
config.plutonium.cache_discovery = defined?(Rails.env) && !Rails.env.development?
|
7
7
|
config.plutonium.enable_hotreload = defined?(Rails.env) && Rails.env.development?
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
config.plutonium.assets = ActiveSupport::OrderedOptions.new
|
10
|
+
config.plutonium.assets.logo = "plutonium.png"
|
11
|
+
config.plutonium.assets.favicon = "plutonium.ico"
|
12
|
+
config.plutonium.assets.stylesheet = "plutonium.css"
|
13
|
+
config.plutonium.assets.script = "plutonium.min.js"
|
14
|
+
|
15
|
+
# If you don't want to precompile Plutonium's assets (eg. because you're using webpack),
|
16
|
+
# you can do this in an intiailzer:
|
17
|
+
#
|
18
|
+
# config.after_initialize do
|
19
|
+
# config.assets.precompile -= Plutonium::Railtie::PRECOMPILE_ASSETS
|
20
|
+
# end
|
21
|
+
PRECOMPILE_ASSETS = %w[plutonium.js plutonium.js.map plutonium.min.js plutonium.min.js.map plutonium.css]
|
22
|
+
|
23
|
+
initializer "plutonium.assets" do
|
24
|
+
next unless Rails.application.config.respond_to?(:assets)
|
25
|
+
|
26
|
+
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
|
27
|
+
Rails.application.config.assets.paths << Plutonium.root.join("app/assets").to_s
|
13
28
|
end
|
14
29
|
|
15
|
-
initializer "plutonium.
|
30
|
+
initializer "plutonium.load_components" do
|
16
31
|
load Plutonium.root.join("app", "views", "components", "base.rb")
|
17
32
|
end
|
18
33
|
|
19
|
-
initializer "plutonium.
|
34
|
+
initializer "plutonium.initializers" do
|
20
35
|
Dir.glob(Plutonium.root.join("config", "initializers", "**", "*.rb")) { |file| load file }
|
21
36
|
end
|
22
37
|
|
23
38
|
initializer "plutonium.asset_server" do
|
39
|
+
next unless Plutonium.development?
|
40
|
+
|
41
|
+
puts "=> [plutonium] starting assets server"
|
24
42
|
# setup a middleware to serve our assets
|
25
43
|
config.app_middleware.insert_before(
|
26
44
|
ActionDispatch::Static,
|
27
45
|
Rack::Static,
|
28
|
-
urls: ["/
|
29
|
-
root: Plutonium.root.join("
|
46
|
+
urls: ["/build"],
|
47
|
+
root: Plutonium.root.join("src").to_s,
|
30
48
|
cascade: true,
|
31
49
|
header_rules: [
|
32
50
|
# Cache all static files in public caches (e.g. Rack::Cache) as well as in the browser
|
data/lib/plutonium/reloader.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
require "active_support/notifications"
|
2
|
+
|
1
3
|
# Be sure to restart your server when you modify this file.
|
2
|
-
# This is a glorified initializer
|
3
4
|
|
4
5
|
module Plutonium
|
5
6
|
class Reloader
|
@@ -7,8 +8,11 @@ module Plutonium
|
|
7
8
|
def start!
|
8
9
|
puts "=> [plutonium] starting reloader"
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
ActiveSupport::Notifications.instrument("plutonium.reloader.start") do
|
12
|
+
# Task code here
|
13
|
+
@listener&.stop
|
14
|
+
@listener = initialize_listener
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
private
|
@@ -75,16 +79,23 @@ module Plutonium
|
|
75
79
|
end
|
76
80
|
|
77
81
|
def reload_engine_and_routes(file)
|
78
|
-
Plutonium.logger.debug "[plutonium] reloading
|
82
|
+
Plutonium.logger.debug "[plutonium] reloading: engine+routes"
|
79
83
|
load file
|
80
84
|
Rails.application.reload_routes!
|
81
85
|
end
|
82
86
|
|
83
87
|
def reload_framework_and_file(file)
|
84
|
-
|
88
|
+
# # Ensure that the file loads correctly before we do any reloading
|
89
|
+
# load file
|
90
|
+
|
91
|
+
Plutonium.logger.debug "[plutonium] reloading: app+framework"
|
92
|
+
Rails.application.reloader.reload!
|
85
93
|
Plutonium::ZEITWERK_LOADER.reload
|
94
|
+
# reload components
|
95
|
+
Object.send(:remove_const, "PlutoniumUi")
|
86
96
|
load Plutonium.root.join("app", "views", "components", "base.rb")
|
87
|
-
|
97
|
+
# # Ensure files that do not contain constants are loaded again e.g. initializers
|
98
|
+
# load file
|
88
99
|
end
|
89
100
|
|
90
101
|
def reload_file(file)
|
@@ -92,7 +103,7 @@ module Plutonium
|
|
92
103
|
end
|
93
104
|
|
94
105
|
def log_reload_failure(file, error)
|
95
|
-
Plutonium.logger.error "\n[plutonium]
|
106
|
+
Plutonium.logger.error "\n[plutonium] reloading failed\n\n#{error.message}\n"
|
96
107
|
end
|
97
108
|
end
|
98
109
|
end
|
@@ -95,6 +95,8 @@ module Plutonium
|
|
95
95
|
def resource_presenter(resource_class, resource_record)
|
96
96
|
presenter_class = "#{current_package}::#{resource_class}Presenter".constantize
|
97
97
|
presenter_class.new resource_context, resource_record
|
98
|
+
rescue NameError
|
99
|
+
super(resource_class, resource_record)
|
98
100
|
end
|
99
101
|
|
100
102
|
# Creates a resource query object
|
@@ -104,6 +106,8 @@ module Plutonium
|
|
104
106
|
def resource_query_object(resource_class, params)
|
105
107
|
query_object_class = "#{current_package}::#{resource_class}QueryObject".constantize
|
106
108
|
query_object_class.new resource_context, params
|
109
|
+
rescue NameError
|
110
|
+
super(resource_class, params)
|
107
111
|
end
|
108
112
|
|
109
113
|
# Applies submitted resource params if they have been passed
|
@@ -1,14 +1,18 @@
|
|
1
1
|
module Plutonium
|
2
2
|
module Resource
|
3
|
-
# Policy class to define permissions and attributes for a resource
|
3
|
+
# Policy class to define permissions and attributes for a resource.
|
4
|
+
# This class provides methods to check permissions for various actions
|
5
|
+
# and to retrieve permitted attributes for these actions.
|
4
6
|
class Policy
|
5
7
|
include Plutonium::Policy::Initializer
|
6
8
|
|
9
|
+
# Scope class to define the scope of the policy.
|
7
10
|
class Scope < Plutonium::Policy::Scope
|
8
11
|
end
|
9
12
|
|
10
|
-
# Sends a method and raises an error if the method is not implemented
|
11
|
-
#
|
13
|
+
# Sends a method and raises an error if the method is not implemented.
|
14
|
+
#
|
15
|
+
# @param method [Symbol] The method to send.
|
12
16
|
def send_with_report(method)
|
13
17
|
unless respond_to?(method)
|
14
18
|
raise NotImplementedError, "#{self.class.name} does not implement the required #{method}"
|
@@ -19,66 +23,76 @@ module Plutonium
|
|
19
23
|
|
20
24
|
# Core actions
|
21
25
|
|
22
|
-
# Checks if the create action is permitted
|
23
|
-
#
|
26
|
+
# Checks if the create action is permitted.
|
27
|
+
#
|
28
|
+
# @return [Boolean] false by default.
|
24
29
|
def create?
|
25
30
|
false
|
26
31
|
end
|
27
32
|
|
28
|
-
# Checks if the read action is permitted
|
29
|
-
#
|
33
|
+
# Checks if the read action is permitted.
|
34
|
+
#
|
35
|
+
# @return [Boolean] false by default.
|
30
36
|
def read?
|
31
37
|
false
|
32
38
|
end
|
33
39
|
|
34
|
-
# Checks if the update action is permitted
|
35
|
-
#
|
40
|
+
# Checks if the update action is permitted.
|
41
|
+
#
|
42
|
+
# @return [Boolean] Delegates to create?.
|
36
43
|
def update?
|
37
44
|
create?
|
38
45
|
end
|
39
46
|
|
40
|
-
# Checks if the destroy action is permitted
|
41
|
-
#
|
47
|
+
# Checks if the destroy action is permitted.
|
48
|
+
#
|
49
|
+
# @return [Boolean] Delegates to create?.
|
42
50
|
def destroy?
|
43
51
|
create?
|
44
52
|
end
|
45
53
|
|
46
54
|
# Inferred actions
|
47
55
|
|
48
|
-
# Checks if the index action is permitted
|
49
|
-
#
|
56
|
+
# Checks if the index action is permitted.
|
57
|
+
#
|
58
|
+
# @return [Boolean] Delegates to read?.
|
50
59
|
def index?
|
51
60
|
read?
|
52
61
|
end
|
53
62
|
|
54
|
-
# Checks if the new action is permitted
|
55
|
-
#
|
63
|
+
# Checks if the new action is permitted.
|
64
|
+
#
|
65
|
+
# @return [Boolean] Delegates to create?.
|
56
66
|
def new?
|
57
67
|
create?
|
58
68
|
end
|
59
69
|
|
60
|
-
# Checks if the show action is permitted
|
61
|
-
#
|
70
|
+
# Checks if the show action is permitted.
|
71
|
+
#
|
72
|
+
# @return [Boolean] Delegates to read?.
|
62
73
|
def show?
|
63
74
|
read?
|
64
75
|
end
|
65
76
|
|
66
|
-
# Checks if the edit action is permitted
|
67
|
-
#
|
77
|
+
# Checks if the edit action is permitted.
|
78
|
+
#
|
79
|
+
# @return [Boolean] Delegates to update?.
|
68
80
|
def edit?
|
69
81
|
update?
|
70
82
|
end
|
71
83
|
|
72
|
-
# Checks if the search action is permitted
|
73
|
-
#
|
84
|
+
# Checks if the search action is permitted.
|
85
|
+
#
|
86
|
+
# @return [Boolean] Delegates to index?.
|
74
87
|
def search?
|
75
88
|
index?
|
76
89
|
end
|
77
90
|
|
78
91
|
# Core attributes
|
79
92
|
|
80
|
-
# Returns the permitted attributes for the create action
|
81
|
-
#
|
93
|
+
# Returns the permitted attributes for the create action.
|
94
|
+
#
|
95
|
+
# @return [Array<Symbol>] The permitted attributes.
|
82
96
|
def permitted_attributes_for_create
|
83
97
|
autodetect_permitted_fields(:permitted_attributes_for_create) - [
|
84
98
|
context.resource_context.resource_class.primary_key.to_sym, # primary_key
|
@@ -86,64 +100,72 @@ module Plutonium
|
|
86
100
|
]
|
87
101
|
end
|
88
102
|
|
89
|
-
# Returns the permitted attributes for the read action
|
90
|
-
#
|
103
|
+
# Returns the permitted attributes for the read action.
|
104
|
+
#
|
105
|
+
# @return [Array<Symbol>] The permitted attributes.
|
91
106
|
def permitted_attributes_for_read
|
92
107
|
autodetect_permitted_fields(:permitted_attributes_for_read)
|
93
108
|
end
|
94
109
|
|
95
|
-
# Returns the permitted attributes for the update action
|
96
|
-
#
|
110
|
+
# Returns the permitted attributes for the update action.
|
111
|
+
#
|
112
|
+
# @return [Array<Symbol>] Delegates to permitted_attributes_for_create.
|
97
113
|
def permitted_attributes_for_update
|
98
114
|
permitted_attributes_for_create
|
99
115
|
end
|
100
116
|
|
101
117
|
# Inferred attributes
|
102
118
|
|
103
|
-
# Returns the permitted attributes for the index action
|
104
|
-
#
|
119
|
+
# Returns the permitted attributes for the index action.
|
120
|
+
#
|
121
|
+
# @return [Array<Symbol>] Delegates to permitted_attributes_for_read.
|
105
122
|
def permitted_attributes_for_index
|
106
123
|
permitted_attributes_for_read
|
107
124
|
end
|
108
125
|
|
109
|
-
# Returns the permitted attributes for the show action
|
110
|
-
#
|
126
|
+
# Returns the permitted attributes for the show action.
|
127
|
+
#
|
128
|
+
# @return [Array<Symbol>] Delegates to permitted_attributes_for_read.
|
111
129
|
def permitted_attributes_for_show
|
112
130
|
permitted_attributes_for_read
|
113
131
|
end
|
114
132
|
|
115
|
-
# Returns the permitted attributes for the new action
|
116
|
-
#
|
133
|
+
# Returns the permitted attributes for the new action.
|
134
|
+
#
|
135
|
+
# @return [Array<Symbol>] Delegates to permitted_attributes_for_create.
|
117
136
|
def permitted_attributes_for_new
|
118
137
|
permitted_attributes_for_create
|
119
138
|
end
|
120
139
|
|
121
|
-
# Returns the permitted attributes for the edit action
|
122
|
-
#
|
140
|
+
# Returns the permitted attributes for the edit action.
|
141
|
+
#
|
142
|
+
# @return [Array<Symbol>] Delegates to permitted_attributes_for_update.
|
123
143
|
def permitted_attributes_for_edit
|
124
144
|
permitted_attributes_for_update
|
125
145
|
end
|
126
146
|
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
|
131
|
-
|
147
|
+
# Returns the permitted associations.
|
148
|
+
#
|
149
|
+
# @return [Array<Symbol>] An empty array by default.
|
150
|
+
def permitted_associations
|
151
|
+
[]
|
152
|
+
end
|
132
153
|
|
133
154
|
private
|
134
155
|
|
135
|
-
# Autodetects the permitted fields for a given method
|
136
|
-
#
|
137
|
-
# @
|
156
|
+
# Autodetects the permitted fields for a given method.
|
157
|
+
#
|
158
|
+
# @param method_name [Symbol] The name of the method.
|
159
|
+
# @return [Array<Symbol>] The auto-detected permitted fields.
|
138
160
|
def autodetect_permitted_fields(method_name)
|
139
161
|
warn_about_autodetect_usage(method_name)
|
140
|
-
|
141
162
|
context.resource_context.resource_class.resource_field_names
|
142
163
|
end
|
143
164
|
|
144
|
-
# Warns about the usage of auto-detection of fields
|
145
|
-
#
|
146
|
-
# @
|
165
|
+
# Warns about the usage of auto-detection of fields.
|
166
|
+
#
|
167
|
+
# @param method [Symbol] The method name.
|
168
|
+
# @raise [RuntimeError] if not in the development environment.
|
147
169
|
def warn_about_autodetect_usage(method)
|
148
170
|
unless Rails.env.development?
|
149
171
|
raise "Resource field auto-detection: #{self.class}##{method} outside development"
|
@@ -5,6 +5,7 @@ module Plutonium
|
|
5
5
|
class Presenter
|
6
6
|
include Plutonium::Core::Definers::FieldDefiner
|
7
7
|
include Plutonium::Core::Definers::ActionDefiner
|
8
|
+
include Plutonium::Core::Definers::AssociationRendererDefiner
|
8
9
|
|
9
10
|
# Initializes the presenter with context and resource record
|
10
11
|
# @param [Object] context The context in which the presenter is used
|