Class: Kadmin::Configuration
- Inherits:
-
Object
- Object
- Kadmin::Configuration
- Defined in:
- lib/kadmin/configuration.rb
Instance Attribute Summary collapse
-
#handle_errors ⇒ Boolean
If true, any Kadmin::ApplicationController will catch errors and display a custom page.
-
#logger ⇒ Logger
An instance of a Ruby compatible logger.
-
#mount_path ⇒ String
The path the engine is mounted at (used for authentication routes).
-
#navbar_items ⇒ Array<Kadmin::Navbar::Section, Kadmin::Navbar::Link>
List of admin links or sections.
Instance Method Summary collapse
- #add_navbar_items(*items) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#navbar_items_for_user(user) ⇒ Object
filter available nav sections with the user’s accept string.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
17 18 19 20 21 22 |
# File 'lib/kadmin/configuration.rb', line 17 def initialize @mount_path = '/admin' @logger = Rails.logger @navbar_items = [] @handle_errors = false end |
Instance Attribute Details
#handle_errors ⇒ Boolean
Returns if true, any Kadmin::ApplicationController will catch errors and display a custom page.
15 16 17 |
# File 'lib/kadmin/configuration.rb', line 15 def handle_errors @handle_errors end |
#logger ⇒ Logger
Returns An instance of a Ruby compatible logger.
6 7 8 |
# File 'lib/kadmin/configuration.rb', line 6 def logger @logger end |
#mount_path ⇒ String
Returns the path the engine is mounted at (used for authentication routes).
9 10 11 |
# File 'lib/kadmin/configuration.rb', line 9 def mount_path @mount_path end |
#navbar_items ⇒ Array<Kadmin::Navbar::Section, Kadmin::Navbar::Link>
Returns list of admin links or sections.
12 13 14 |
# File 'lib/kadmin/configuration.rb', line 12 def @navbar_items end |
Instance Method Details
#add_navbar_items(*items) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/kadmin/configuration.rb', line 24 def (*items) items.each do |item| index = @navbar_items.bsearch_index { || .text >= item.text } @navbar_items.insert(index || @navbar_items.size, item) end end |
#navbar_items_for_user(user) ⇒ Object
filter available nav sections with the user’s accept string
32 33 34 35 36 37 38 |
# File 'lib/kadmin/configuration.rb', line 32 def (user) return [] if user.blank? # no user, no links return @navbar_items if user.accept.blank? && user.admin? # no accept array and super admin -> everything is accepted return @navbar_items.select do || user.accept.any? { |accept_string| .text =~ /#{accept_string.to_s.split('_').first}/i } end end |