class Tolaria::ManagedClass
Wraps an ActiveRecord::Base
descendant and stores information that Tolaria
needs to track about it
Attributes
An array of the route actions allowed on this resource. Tolaria
will pass this array as the `:only` option to the router
The navigation category and order to use for this resource
An auto-generated controller name for this resource in the Admin
namespace
The default sort order for this resource
The Font Awesome icon to use for this resource
The ActiveRecord::Base
model we’re managing
Enable or disable automatic pagination for this model.
A stored symbol for the `params.permit` key for this resource
An array of options to pass to `params.permit` for this model
Items are sorted with lowest priority first in the menu
Public Class Methods
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
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
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
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
True if this managed class should be paginated
# File lib/tolaria/managed_class.rb, line 71 def paginated? self.paginated end