Class: FileBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/services/file_builder.rb

Defined Under Namespace

Classes: Authorisation, BuildStrongParams, ClassDefinition, ControllerAction, SkipCsrf, TrackEvent

Constant Summary collapse

OPTION_KLASS_MAP =
{
  'authorisation' => 'Authorisation',
  'url' => 'ClassDefinition',
  'request' => 'BuildStrongParams',
  'controller_action' => 'ControllerAction',
  'skip-csrf' => 'SkipCsrf'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FileBuilder

Returns a new instance of FileBuilder.



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/services/file_builder.rb', line 2

def initialize(options = {})
  @options = options

  if options[:url]
    parts = options[:url].split('/')

    if parts.count > 1
      options[:object] = parts.last.singularize
      options[:class] = parts.last.singularize.capitalize
    end
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'app/services/file_builder.rb', line 15

def options
  @options
end

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/file_builder.rb', line 25

def call
  options.to_h.each_with_object(parts) do |(option, _value), output|
    klass = OPTION_KLASS_MAP[option]

    next unless klass

    fragments = "FileBuilder::#{klass}".constantize.call(options: options)

    fragments.each do |part, code|
      output[part] ||= []

      output[part] << code
    end
  end
end