Class: Kadmin::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_errorsBoolean

Returns if true, any Kadmin::ApplicationController will catch errors and display a custom page.

Returns:

  • (Boolean)

    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

#loggerLogger

Returns An instance of a Ruby compatible logger.

Returns:

  • (Logger)

    An instance of a Ruby compatible logger



6
7
8
# File 'lib/kadmin/configuration.rb', line 6

def logger
  @logger
end

#mount_pathString

Returns the path the engine is mounted at (used for authentication routes).

Returns:

  • (String)

    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

Returns list of admin links or sections.

Returns:



12
13
14
# File 'lib/kadmin/configuration.rb', line 12

def navbar_items
  @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 add_navbar_items(*items)
  items.each do |item|
    index = @navbar_items.bsearch_index { |navbar_item| navbar_item.text >= item.text }
    @navbar_items.insert(index || @navbar_items.size, item)
  end
end

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 navbar_items_for_user(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 |navbar_item|
    user.accept.any? { |accept_string| navbar_item.text =~ /#{accept_string.to_s.split('_').first}/i }
  end
end