Class: QuickAdmin::Configuration

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

Overview

Configuration class for QuickAdmin. Holds all configuration options for the admin interface.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes a new Configuration with default values.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/quick_admin/configuration.rb', line 23

def initialize
  @authentication = nil           # No authentication by default
  @css_framework = :none          # Use built-in styles
  @text_editor = :textarea        # Simple textarea editor
  @turbo_enabled = true           # Turbo enabled for modern UX
  @stimulus_enabled = true        # Stimulus enabled for controllers
  @per_page = 25                  # Reasonable default pagination
  @mount_path = '/admin'          # Standard admin path
  @app_name = 'QuickAdmin'        # Default app name
  @sign_out_path = nil            # Auto-detect from Devise or set manually
  @sign_out_method = :delete      # Default HTTP method for sign out
  @current_user_method = :current_user  # Method to get current user
  @authenticate_method = nil      # Auto-detect or set manually (e.g., :authenticate_admin!)
end

Instance Attribute Details

#app_nameString

application name shown in UI (default: 'QuickAdmin')

Returns:

  • (String)

    the current value of app_name



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def app_name
  @app_name
end

#authenticate_methodObject

Returns the value of attribute authenticate_method.



17
18
19
# File 'lib/quick_admin/configuration.rb', line 17

def authenticate_method
  @authenticate_method
end

#authenticationSymbol?

authentication method (:devise, :custom, or nil)

Returns:

  • (Symbol, nil)

    the current value of authentication



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def authentication
  @authentication
end

#css_frameworkSymbol

CSS framework to use (:tailwind, :bootstrap, or :none)

Returns:

  • (Symbol)

    the current value of css_framework



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def css_framework
  @css_framework
end

#current_user_methodSymbol

method to get current user (default: :current_user)

Returns:

  • (Symbol)

    the current value of current_user_method



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def current_user_method
  @current_user_method
end

#mount_pathString

URL path where admin is mounted (default: '/admin')

Returns:

  • (String)

    the current value of mount_path



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def mount_path
  @mount_path
end

#per_pageInteger

number of records per page (default: 25)

Returns:

  • (Integer)

    the current value of per_page



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def per_page
  @per_page
end

#sign_out_methodSymbol

HTTP method for sign out (default: :delete)

Returns:

  • (Symbol)

    the current value of sign_out_method



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def sign_out_method
  @sign_out_method
end

#sign_out_pathString, Proc

path for sign out link (default: auto-detect)

Returns:

  • (String, Proc)

    the current value of sign_out_path



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def sign_out_path
  @sign_out_path
end

#stimulus_enabledBoolean

whether to enable Stimulus (default: true)

Returns:

  • (Boolean)

    the current value of stimulus_enabled



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def stimulus_enabled
  @stimulus_enabled
end

#text_editorSymbol

text editor for rich text fields (:trix, :lexical, or :textarea)

Returns:

  • (Symbol)

    the current value of text_editor



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def text_editor
  @text_editor
end

#turbo_enabledBoolean

whether to enable Turbo (default: true)

Returns:

  • (Boolean)

    the current value of turbo_enabled



16
17
18
# File 'lib/quick_admin/configuration.rb', line 16

def turbo_enabled
  @turbo_enabled
end

Instance Method Details

#bootstrap_enabled?Boolean

Checks if Bootstrap CSS framework is enabled.

Returns:

  • (Boolean)

    true if bootstrap is configured



52
53
54
# File 'lib/quick_admin/configuration.rb', line 52

def bootstrap_enabled?
  css_framework == :bootstrap
end

#devise_enabled?Boolean

Checks if Devise authentication is enabled and available.

Returns:

  • (Boolean)

    true if devise is configured and gem is loaded



40
41
42
# File 'lib/quick_admin/configuration.rb', line 40

def devise_enabled?
  authentication == :devise && defined?(Devise)
end

#lexical_enabled?Boolean

Checks if Lexical editor is enabled.

Returns:

  • (Boolean)

    true if lexical is configured



64
65
66
# File 'lib/quick_admin/configuration.rb', line 64

def lexical_enabled?
  text_editor == :lexical
end

#resolved_current_user_methodSymbol

Returns the resolved current user method. Auto-detects based on available Devise models.

Returns:

  • (Symbol)

    the method name to get current user



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/quick_admin/configuration.rb', line 90

def resolved_current_user_method
  return current_user_method if current_user_method != :current_user
  
  # Auto-detect based on Devise models
  if defined?(Devise)
    if defined?(Admin)
      :current_admin
    else
      :current_user
    end
  else
    current_user_method
  end
end

#resolved_sign_out_pathString?

Returns the resolved sign out path. Auto-detects Devise path if not explicitly set.

Returns:

  • (String, nil)

    the sign out path or nil if not available



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/quick_admin/configuration.rb', line 71

def resolved_sign_out_path
  return sign_out_path if sign_out_path.present?
  
  # Auto-detect Devise sign out path (even if not explicitly configured)
  if defined?(Devise)
    # Check for Admin model first, then User
    if defined?(Admin)
      '/admins/sign_out'
    else
      '/users/sign_out'
    end
  else
    nil
  end
end

#tailwind_enabled?Boolean

Checks if Tailwind CSS framework is enabled.

Returns:

  • (Boolean)

    true if tailwind is configured



46
47
48
# File 'lib/quick_admin/configuration.rb', line 46

def tailwind_enabled?
  css_framework == :tailwind
end

#trix_enabled?Boolean

Checks if Trix editor is enabled and available.

Returns:

  • (Boolean)

    true if trix is configured and gem is loaded



58
59
60
# File 'lib/quick_admin/configuration.rb', line 58

def trix_enabled?
  text_editor == :trix && defined?(Trix)
end