class Integral::ActsAsIntegral::ActiveRecord::Base
ActiveRecord::Base
extension
Attributes
integral_options[RW]
Public Class Methods
acts_as_integral(options = {})
click to toggle source
Adds integral behaviour to models
# File lib/integral/acts_as_integral.rb, line 65 def self.acts_as_integral(options = {}) class << self attr_accessor :integral_options # @return [Hash] hash representing the class, used to render within the main menu def integral_backend_main_menu_item { icon: integral_icon, order: integral_options.dig(:backend_main_menu, :order), label: model_name.human.pluralize, url: url_helpers.send("backend_#{model_name.route_key}_url"), # authorize: proc { policy(self).index? }, can't use this as self is in wrong context authorize_class: self, authorize_action: :index, list_items: [ { label: I18n.t('integral.navigation.dashboard'), url: url_helpers.send("backend_#{model_name.route_key}_url"), authorize_class: self, authorize_action: :index }, { label: I18n.t('integral.actions.create'), url: url_helpers.send("new_backend_#{model_name.singular_route_key}_url"), authorize_class: self, authorize_action: :new }, { label: I18n.t('integral.navigation.listing'), url: url_helpers.send("list_backend_#{model_name.route_key}_url"), authorize_class: self, authorize_action: :list }, ] } end # @return [Hash] hash representing the class, used to render within the create menu def integral_backend_create_menu_item { icon: integral_icon, order: integral_options.dig(:backend_create_menu, :order), label: model_name.human, url: url_helpers.send("new_backend_#{model_name.singular_route_key}_url"), # authorize: proc { policy(self).index? }, can't use this as self is in wrong context authorize_class: self, authorize_action: :new, } end def url_helpers Integral::Engine.routes.url_helpers end end self.integral_options = Integral::ActsAsIntegral::DEFAULT_OPTIONS.deep_merge(options) Integral::ActsAsIntegral.add_backend_create_menu_item(self) if integral_options.dig(:backend_create_menu, :enabled) Integral::ActsAsIntegral.add_backend_main_menu_item(self) if integral_options.dig(:backend_main_menu, :enabled) Integral::ActsAsIntegral.add_backend_at_a_glance_card_item(self) if integral_options.dig(:cards, :at_a_glance) include Integral::Notification::Subscribable if integral_options.dig(:notifications, :enabled) end
url_helpers()
click to toggle source
# File lib/integral/acts_as_integral.rb, line 100 def url_helpers Integral::Engine.routes.url_helpers end