Class: Wallaby::Configuration

Inherits:
Object
  • Object
show all
Includes:
Classifier
Defined in:
lib/wallaby/configuration.rb,
lib/wallaby/configuration/models.rb,
lib/wallaby/configuration/mapping.rb,
lib/wallaby/configuration/sorting.rb,
lib/wallaby/configuration/features.rb,
lib/wallaby/configuration/metadata.rb,
lib/wallaby/configuration/security.rb,
lib/wallaby/configuration/pagination.rb

Overview

Global configuration

Defined Under Namespace

Classes: Features, Mapping, Metadata, Models, Pagination, Security, Sorting

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Classifier

#class_name_of, #to_class

Instance Attribute Details

#base_controllerClass

To globally configure the base controller class that ResourcesController should inherit from.

If no configuration is given, ResourcesController defaults to inherit from ::ApplicationController from the host Rails app.

Examples:

To update base controller to ‘CoreController` in `config/initializers/wallaby.rb`

Wallaby.config do |config|
  config.base_controller = ::CoreController
end

Returns:

  • (Class)

    base controller class



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

def base_controller
  to_class @base_controller ||= '::ApplicationController'
end

#loggerObject



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

def logger
  @logger ||= Rails.logger
end

#model_pathsArray<String>

To configure the model folders that Preloader needs to load before everything else. Default is ‘%w(app/models)`

Examples:

To set the model paths

Wallaby.config do |config|
  config.model_paths = ["app/models", "app/core"]
end

Returns:

  • (Array<String>)

    model paths

Since:

  • 0.2.2



39
40
41
# File 'lib/wallaby/configuration.rb', line 39

def model_paths
  @model_paths ||= %w[app/models]
end

#raise_on_name_errorObject

Returns the value of attribute raise_on_name_error.



10
11
12
# File 'lib/wallaby/configuration.rb', line 10

def raise_on_name_error
  @raise_on_name_error
end

#resources_controllerClass

To globally configure the application controller class that Engine should use.

If no configuration is given, Engine defaults to use Admin::ApplicationController or ResourcesController from the host Rails app.

Examples:

To update base controller to ‘CoreController` in `config/initializers/wallaby.rb`

Wallaby.config do |config|
  config.resources_controller = ::CoreController
end

Returns:

  • (Class)

    base controller class

Since:

  • 0.2.3



79
80
81
82
83
84
85
# File 'lib/wallaby/configuration.rb', line 79

def resources_controller
  to_class(
    @resources_controller ||=
      (to_class('Admin::ApplicationController') && \
        'Admin::ApplicationController') || 'Wallaby::ResourcesController'
  )
end

Instance Method Details

#clearObject

Clear all configurations



152
153
154
# File 'lib/wallaby/configuration.rb', line 152

def clear
  instance_variables.each { |name| instance_variable_set name, nil }
end

#custom_modelsConfiguration::Models

Returns models configuration for custom mode.

Returns:



88
89
90
# File 'lib/wallaby/configuration.rb', line 88

def custom_models
  @custom_models ||= ClassArray.new
end

#custom_models=(models) ⇒ Object

To globally configure the models for custom mode.

Examples:

To update the model classes in ‘config/initializers/wallaby.rb`

Wallaby.config do |config|
  config.custom_models = [Product, Order]
end

Parameters:

  • models (Array<[Class, String]>)

    a list of model classes/name strings



98
99
100
# File 'lib/wallaby/configuration.rb', line 98

def custom_models=(models)
  @custom_models = ClassArray.new models.flatten
end

#featuresConfiguration::Features

Returns features configuration.

Returns:



140
141
142
# File 'lib/wallaby/configuration.rb', line 140

def features
  @features ||= Features.new
end

#mappingConfiguration::Mapping

Returns mapping configuration.

Returns:



125
126
127
# File 'lib/wallaby/configuration.rb', line 125

def mapping
  @mapping ||= Mapping.new
end

#metadataConfiguration::Metadata

Returns metadata configuration.

Returns:



130
131
132
# File 'lib/wallaby/configuration.rb', line 130

def 
  @metadata ||= Metadata.new
end

#modelsConfiguration::Models

Returns models configuration.

Returns:



103
104
105
106
107
# File 'lib/wallaby/configuration.rb', line 103

def models
  Deprecator.alert 'config.models.presence', from: '0.3.0', alternative: <<~INSTRUCTION
    Please use controller_class.models instead.
  INSTRUCTION
end

#models=(models) ⇒ Object

To globally configure the models that Wallaby should handle.

Examples:

To update the model classes in ‘config/initializers/wallaby.rb`

Wallaby.config do |config|
  config.models = [Product, Order]
end

Parameters:

  • models (Array<[Class, String]>)

    a list of model classes/name strings



115
116
117
# File 'lib/wallaby/configuration.rb', line 115

def models=(models)
  self.models.set models
end

#paginationConfiguration::Pagination

Returns pagination configuration.

Returns:



135
136
137
# File 'lib/wallaby/configuration.rb', line 135

def pagination
  @pagination ||= Pagination.new
end

#securityConfiguration::Security

Returns security configuration.

Returns:



120
121
122
# File 'lib/wallaby/configuration.rb', line 120

def security
  @security ||= Security.new
end

#sortingConfiguration::Sorting

Returns sorting configuration.

Returns:



145
146
147
148
149
# File 'lib/wallaby/configuration.rb', line 145

def sorting
  Deprecator.alert 'config.sorting.strategy', from: '0.3.0', alternative: <<~INSTRUCTION
    Please use controller_class.sorting_strategy instead.
  INSTRUCTION
end