Class: Wallaby::PrefixesBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/services/wallaby/prefixes_builder.rb

Overview

Prefix builder

Instance Method Summary collapse

Constructor Details

#initialize(origin_prefixes, controller_path, resources_name, params) ⇒ PrefixesBuilder

Returns a new instance of PrefixesBuilder.

Parameters:

  • origin_prefixes (Array<string>)

    a list of all the prefixes

  • controller_path (String)

    controller path

  • resources_name (String)

    resources name

  • params (ActionController::Parameters)


9
10
11
12
13
14
# File 'lib/services/wallaby/prefixes_builder.rb', line 9

def initialize(origin_prefixes, controller_path, resources_name, params)
  @origin_prefixes = origin_prefixes
  @controller_path = controller_path
  @resources_name = resources_name
  @params = params
end

Instance Method Details

#buildArray<String>

Returns a list of all the prefixes.

Returns:

  • (Array<String>)

    a list of all the prefixes



17
18
19
20
21
22
23
24
# File 'lib/services/wallaby/prefixes_builder.rb', line 17

def build
  prefixes = minimal_prefixes
  prefixes.unshift mounted_prefix if resource_path != @controller_path
  suffix = build_suffix(@params)
  prefixes.each_with_object([]) do |prefix, result|
    result << "#{prefix}/#{suffix}" << prefix if prefix
  end
end