Class: AdminResources::Configuration
- Inherits:
-
Object
- Object
- AdminResources::Configuration
- Defined in:
- lib/admin_resources/configuration.rb
Instance Attribute Summary collapse
-
#custom_pages ⇒ Object
readonly
Returns the value of attribute custom_pages.
-
#models ⇒ Object
readonly
Returns the value of attribute models.
Instance Method Summary collapse
-
#add_page(label, path:, icon: nil) ⇒ Object
Register a custom sidebar page that routes to the host app Usage: config.add_page “STL Models”, path: “/admin/stl_models”, icon: “📦”.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #model_names ⇒ Object
-
#register(model_name, columns: nil, has_many_through: nil, custom_actions: nil) ⇒ Object
Register a model for admin management Usage: config.register “User”, columns: %w[id email created_at] Usage: config.register “User” (defaults to first 6 columns) Usage: config.register “Product”, has_many_through: [{ association: :desk_buddy_versions, join_model: “ProductVersion”, foreign_key: :product_id, through_key: :desk_buddy_version_id }] Usage: config.register “Order”, custom_actions: [{ name: :ship, label: “Mark Shipped”, method: :patch, confirm: “Mark this order as shipped?” }].
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 |
# File 'lib/admin_resources/configuration.rb', line 7 def initialize @models = {} @custom_pages = [] end |
Instance Attribute Details
#custom_pages ⇒ Object (readonly)
Returns the value of attribute custom_pages.
5 6 7 |
# File 'lib/admin_resources/configuration.rb', line 5 def custom_pages @custom_pages end |
#models ⇒ Object (readonly)
Returns the value of attribute models.
5 6 7 |
# File 'lib/admin_resources/configuration.rb', line 5 def models @models end |
Instance Method Details
#add_page(label, path:, icon: nil) ⇒ Object
Register a custom sidebar page that routes to the host app Usage: config.add_page “STL Models”, path: “/admin/stl_models”, icon: “📦”
32 33 34 |
# File 'lib/admin_resources/configuration.rb', line 32 def add_page(label, path:, icon: nil) @custom_pages << { label: label, path: path, icon: icon } end |
#model_names ⇒ Object
26 27 28 |
# File 'lib/admin_resources/configuration.rb', line 26 def model_names @models.keys end |
#register(model_name, columns: nil, has_many_through: nil, custom_actions: nil) ⇒ Object
Register a model for admin management Usage: config.register “User”, columns: %w[id email created_at] Usage: config.register “User” (defaults to first 6 columns) Usage: config.register “Product”, has_many_through: [{ association: :desk_buddy_versions, join_model: “ProductVersion”, foreign_key: :product_id, through_key: :desk_buddy_version_id }] Usage: config.register “Order”, custom_actions: [{ name: :ship, label: “Mark Shipped”, method: :patch, confirm: “Mark this order as shipped?” }]
17 18 19 20 21 22 23 24 |
# File 'lib/admin_resources/configuration.rb', line 17 def register(model_name, columns: nil, has_many_through: nil, custom_actions: nil) name = model_name.to_s.classify @models[name] = { columns: columns&.map(&:to_s), has_many_through: has_many_through || [], custom_actions: custom_actions || [] } end |