Module: Wallaby::Configurable::ClassMethods

Defined in:
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb,
lib/concerns/wallaby/configurable.rb

Overview

Clear configurables

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#application_authorizer ⇒ Class

It is the base class of #model_authorizer.

Examples:

To set application authorizer:

class Admin::ApplicationController < Wallaby::ResourcesController
  self.application_authorizer = AnotherApplicationAuthorizer
end

Returns:

  • (Class) —

    application authorizer

See Also:

Since:

  • wallaby-5.2.0



139
140
141
142
# File 'lib/concerns/wallaby/configurable.rb', line 139

def application_authorizer
  @application_authorizer ||= Guesser.class_for(name, suffix: AUTHORIZER, &:base_class?)
  @application_authorizer || superclass.try(:application_authorizer) || ModelAuthorizer
end

#application_controller ⇒ Class (readonly)

Returns application controller class.

Returns:

  • (Class) —

    application controller class



33
34
35
36
37
# File 'lib/concerns/wallaby/configurable.rb', line 33

def application_controller
  return self if base_class?

  superclass.try(:application_controller) || ResourcesController
end

#application_decorator ⇒ Class

It is the base class of #resource_decorator.

Examples:

To set application decorator:

class Admin::ApplicationController < Wallaby::ResourcesController
  self.application_decorator = AnotherApplicationDecorator
end

Returns:

  • (Class) —

    application decorator

See Also:

Since:

  • wallaby-5.2.0



69
70
71
72
# File 'lib/concerns/wallaby/configurable.rb', line 69

def application_decorator
  @application_decorator ||= Guesser.class_for(name, suffix: DECORATOR, &:base_class?)
  @application_decorator || superclass.try(:application_decorator) || ResourceDecorator
end

#application_paginator ⇒ Class

It is the base class of #model_paginator.

Examples:

To set application paginator:

class Admin::ApplicationController < Wallaby::ResourcesController
  self.application_paginator = AnotherApplicationPaginator
end

Returns:

  • (Class) —

    application paginator

See Also:

Since:

  • wallaby-5.2.0



174
175
176
177
# File 'lib/concerns/wallaby/configurable.rb', line 174

def application_paginator
  @application_paginator ||= Guesser.class_for(name, suffix: PAGINATOR, &:base_class?)
  @application_paginator || superclass.try(:application_paginator) || ModelPaginator
end

#application_servicer ⇒ Class

It is the base class of #model_servicer.

Examples:

To set application servicer:

class Admin::ApplicationController < Wallaby::ResourcesController
  self.application_servicer = AnotherApplicationServicer
end

Returns:

  • (Class) —

    application servicer

See Also:

Since:

  • wallaby-5.2.0



104
105
106
107
# File 'lib/concerns/wallaby/configurable.rb', line 104

def application_servicer
  @application_servicer ||= Guesser.class_for(name, suffix: SERVICER, &:base_class?)
  @application_servicer || superclass.try(:application_servicer) || ModelServicer
end

#email_method ⇒ Object

To configure the method on AuthenticationConcern#wallaby_user to retrieve email address.

If no configuration is given, it will attempt to call email on AuthenticationConcern#wallaby_user.

Examples:

To update the email method in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.email_method = 'email_address'
end

Since:

  • 0.2.3



297
298
299
# File 'lib/concerns/wallaby/configurable.rb', line 297

def email_method
  @email_method || superclass.try(:email_method)
end

#engine_name ⇒ String, ...

It is used to help with URLs handling (see Engine)

So when to set this engine name? When Wallaby doesn't know what is the correct engine helper to use for current path.

Examples:

To set an engine name:

class Admin::ApplicationController < Wallaby::ResourcesController
  self.engine_name = 'admin_engine'
end

Returns:

  • (String, Symbol, nil) —

    engine name

Since:

  • wallaby-5.2.0



24
25
26
# File 'lib/concerns/wallaby/configurable.rb', line 24

def engine_name
  @engine_name || superclass.try(:engine_name)
end

#logout_method ⇒ Object

To configure the logout HTTP method.

Wallaby does not implement any authentication (e.g. login/logout), therefore, logout method will be required so that Wallaby knows how navigate the user via what HTTP method when user clicks the logout button.

But once it detects Devise, it will use the HTTP method that Devise uses without the need of configuration.

Examples:

To update the logout method in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.logout_method = 'put'
end

Since:

  • 0.2.3



269
270
271
# File 'lib/concerns/wallaby/configurable.rb', line 269

def logout_method
  @logout_method || superclass.try(:logout_method)
end

#logout_path ⇒ Object

To configure the logout path.

Wallaby does not implement any authentication (e.g. login/logout), therefore, logout path will be required so that Wallaby knows where to navigate the user to when user clicks the logout button.

But once it detects Devise, it will use the path that Devise uses without the need of configuration.

Examples:

To update the logout path in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.logout_path = 'destroy_admin_user_session_path'
end

Since:

  • 0.2.3



243
244
245
# File 'lib/concerns/wallaby/configurable.rb', line 243

def logout_path
  @logout_path || superclass.try(:logout_path)
end

#max_text_length ⇒ Integer

To configure max number of characters to truncate for each text field on index page.

Examples:

To update the email method in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.max_text_length = 50
end

Returns:

  • (Integer) —

    max number of characters to truncate, default to 20

See Also:

Since:

  • 0.2.3



323
324
325
# File 'lib/concerns/wallaby/configurable.rb', line 323

def max_text_length
  @max_text_length || superclass.try(:max_text_length) || DEFAULT_MAX
end

#model_authorizer ⇒ Class

Returns model authorizer.

Examples:

To set model authorizer

class Admin::ProductionsController < Admin::ApplicationController
  self.model_authorizer = ProductAuthorizer
end

Returns:

  • (Class) —

    model authorizer

See Also:

Since:

  • wallaby-5.2.0



123
124
125
# File 'lib/concerns/wallaby/configurable.rb', line 123

def model_authorizer
  @model_authorizer ||= Guesser.class_for(name, suffix: AUTHORIZER, &:model_class)
end

#model_paginator ⇒ Class

Returns model paginator.

Examples:

To set model paginator

class Admin::ProductionsController < Admin::ApplicationController
  self.model_paginator = ProductPaginator
end

Returns:

  • (Class) —

    model paginator

See Also:

Since:

  • wallaby-5.2.0



158
159
160
# File 'lib/concerns/wallaby/configurable.rb', line 158

def model_paginator
  @model_paginator ||= Guesser.class_for(name, suffix: PAGINATOR, &:model_class)
end

#model_servicer ⇒ Class

Returns model servicer.

Examples:

To set model servicer

class Admin::ProductionsController < Admin::ApplicationController
  self.model_servicer = ProductServicer
end

Returns:

  • (Class) —

    model servicer

See Also:

Since:

  • wallaby-5.2.0



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

def model_servicer
  @model_servicer ||= Guesser.class_for(name, suffix: SERVICER, &:model_class)
end

#models ⇒ Object

To configure the models that the controller should be handling. It takes both Class and Class String.

Examples:

To update the models in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.models = User, 'Product'
end

Since:

  • 0.2.3



190
191
192
# File 'lib/concerns/wallaby/configurable.rb', line 190

def models
  @models || superclass.try(:models) || ClassArray.new
end

#models_to_exclude ⇒ Object

Note:

If models are allowlisted using #models, models exclusion will NOT be applied.

To configure the models to exclude that the controller should be handling. It takes both Class and Class String.

Examples:

To update the models to exclude in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.models_to_exclude = User, 'Product'
end

Since:

  • 0.2.3



208
209
210
211
212
# File 'lib/concerns/wallaby/configurable.rb', line 208

def models_to_exclude
  @models_to_exclude ||
    superclass.try(:models_to_exclude) ||
    DefaultModelsExcluder.execute
end

#page_size ⇒ Integer

To configure the page size for pagination on index page.

Page size can be one of the following values:

  • 10
  • 20
  • 50
  • 100

Examples:

To update the email method in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.page_size = 50
end

Returns:

  • (Integer) —

    page size, default to 20

See Also:

Since:

  • 0.2.3



357
358
359
# File 'lib/concerns/wallaby/configurable.rb', line 357

def page_size
  @page_size || superclass.try(:page_size) || DEFAULT_PAGE_SIZE
end

#resource_decorator ⇒ Class

Returns resource decorator.

Examples:

To set resource decorator

class Admin::ProductionsController < Admin::ApplicationController
  self.resource_decorator = ProductDecorator
end

Returns:

  • (Class) —

    resource decorator

See Also:

Since:

  • wallaby-5.2.0



53
54
55
# File 'lib/concerns/wallaby/configurable.rb', line 53

def resource_decorator
  @resource_decorator ||= Guesser.class_for(name, suffix: DECORATOR, &:model_class)
end

#sorting_strategy ⇒ Integer

To configure which strategy to use for sorting on index page. Options are

- `:multiple`: support multiple columns sorting
- `:single`: support single column sorting

Examples:

To update the email method in Admin::ApplicationController

class Admin::ApplicationController < Wallaby::ResourcesController
  self.sorting_strategy = :single
end

Returns:

  • (Integer) —

    sorting strategy, default to :multiple

See Also:

Since:

  • 0.2.3



386
387
388
# File 'lib/concerns/wallaby/configurable.rb', line 386

def sorting_strategy
  @sorting_strategy || superclass.try(:sorting_strategy) || :multiple
end

Instance Method Details

#all_models ⇒ Array<Class>

Returns all models.

Returns:

  • (Array<Class>) —

    all models



220
221
222
223
224
225
226
# File 'lib/concerns/wallaby/configurable.rb', line 220

def all_models
  ModelClassFilter.execute(
    all: Map.mode_map.keys,
    allowlisted: models.origin,
    denylisted: models_to_exclude.origin
  )
end

#clear ⇒ Object

Clear all configurations



404
405
406
407
408
# File 'lib/concerns/wallaby/configurable.rb', line 404

def clear
  ClassMethods.instance_methods.grep(/=/).each do |name|
    instance_variable_set :"@#{name[0...-1]}", nil
  end
end