Class: IronAdmin::Tool
- Inherits:
-
Object
- Object
- IronAdmin::Tool
- Defined in:
- lib/iron_admin/tool.rb
Overview
Base class for admin tools (custom pages in the admin panel).
Tools are standalone pages that don't map to a database model. External gems can subclass Tool to add custom admin functionality.
Instance Attribute Summary collapse
-
#context ⇒ ToolContext?
Request context, set by ToolsController before action execution.
Class Method Summary collapse
-
.find_tool_action(name) ⇒ ToolAction?
Finds a declared tool action by name.
- .inherited(subclass) ⇒ Object
- .label ⇒ Object
- .menu(**options) ⇒ Object
-
.tool_action(name) ⇒ Object
Declares a tool action with metadata.
- .tool_name ⇒ Object
Instance Attribute Details
#context ⇒ ToolContext?
Returns Request context, set by ToolsController before action execution.
32 33 34 |
# File 'lib/iron_admin/tool.rb', line 32 def context @context end |
Class Method Details
.find_tool_action(name) ⇒ ToolAction?
Finds a declared tool action by name.
65 66 67 |
# File 'lib/iron_admin/tool.rb', line 65 def find_tool_action(name) defined_tool_actions.find { |a| a.name == name.to_sym } end |
.inherited(subclass) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/iron_admin/tool.rb', line 35 def inherited(subclass) super subclass.defined_tool_actions = defined_tool_actions.dup return if subclass.name.nil? begin IronAdmin::ToolRegistry.register(subclass) rescue NameError # ToolRegistry may not be loaded yet during boot end end |
.label ⇒ Object
77 78 79 |
# File 'lib/iron_admin/tool.rb', line 77 def label [:label] || tool_name.humanize end |
.menu(**options) ⇒ Object
69 70 71 |
# File 'lib/iron_admin/tool.rb', line 69 def (**) self. = end |
.tool_action(name) ⇒ Object
Declares a tool action with metadata.
57 58 59 |
# File 'lib/iron_admin/tool.rb', line 57 def tool_action(name, **) self.defined_tool_actions = defined_tool_actions + [ToolAction.new(name: name, **)] end |
.tool_name ⇒ Object
73 74 75 |
# File 'lib/iron_admin/tool.rb', line 73 def tool_name name.sub(/Tool\z/, "").demodulize.underscore end |