class Tolaria::ManagedClass

Wraps an ActiveRecord::Base descendant and stores information that Tolaria needs to track about it

Attributes

allowed_actions[RW]

An array of the route actions allowed on this resource. Tolaria will pass this array as the `:only` option to the router

category[RW]

The navigation category and order to use for this resource

controller_name[RW]

An auto-generated controller name for this resource in the Admin namespace

default_order[RW]

The default sort order for this resource

icon[RW]

The Font Awesome icon to use for this resource

klass[RW]

The ActiveRecord::Base model we’re managing

navigation_label[RW]

A String to override the model's label in the primary admin navigation

paginated[RW]

Enable or disable automatic pagination for this model.

param_key[RW]

A stored symbol for the `params.permit` key for this resource

permitted_params[RW]

An array of options to pass to `params.permit` for this model

priority[RW]

Items are sorted with lowest priority first in the menu

Public Class Methods

create(klass, icon:"file-o", permit_params:[], priority:10, category:"Settings", default_order:"id DESC", paginated:true, allowed_actions:[:index, :show, :new, :create, :edit, :update, :destroy], navigation_label: klass.model_name.human.pluralize.titleize) click to toggle source

A factory method that registers a new model in Tolaria and configures its menu and param settings. Developers should use `ActiveRecord::Base.manage_with_tolaria`

# File lib/tolaria/managed_class.rb, line 42
def self.create(klass, icon:"file-o", permit_params:[], priority:10, category:"Settings", default_order:"id DESC", paginated:true, allowed_actions:[:index, :show, :new, :create, :edit, :update, :destroy], navigation_label: klass.model_name.human.pluralize.titleize)

  managed_class = self.new
  managed_class.klass = klass

  # Assign the passed in setting
  managed_class.icon = icon.to_s.freeze
  managed_class.priority = priority.to_i
  managed_class.category = category.to_s.freeze
  managed_class.default_order = default_order.to_s.freeze
  managed_class.paginated = paginated.present?
  managed_class.permitted_params = permit_params.freeze
  managed_class.allowed_actions = allowed_actions.freeze
  managed_class.navigation_label = navigation_label.freeze

  # Set auto-generated attributes
  managed_class.controller_name = "#{managed_class.model_name.collection.camelize}Controller".freeze
  managed_class.param_key = managed_class.model_name.singular.to_sym

  return managed_class

end

Public Instance Methods

allows?(action) click to toggle source

True if the given symbol is in the managed class's allowed_actions array.

# File lib/tolaria/managed_class.rb, line 66
def allows?(action)
  self.allowed_actions.include?(action)
end
model_name() click to toggle source

Defer to the ActiveRecord::Base model_name system for producing pleasant user-interface names for this resource

# File lib/tolaria/managed_class.rb, line 82
def model_name
  self.klass.model_name
end
no_resources?() click to toggle source

True if there are no resources in the database for this class

# File lib/tolaria/managed_class.rb, line 76
def no_resources?
  self.klass.count.eql?(0)
end
paginated?() click to toggle source

True if this managed class should be paginated

# File lib/tolaria/managed_class.rb, line 71
def paginated?
  self.paginated
end