Class: AdminResources::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/admin_resources/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_pagesObject (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

#modelsObject (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_namesObject



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