Class: FileBuilder
- Inherits:
-
Object
- Object
- FileBuilder
- 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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(options = {}) ⇒ FileBuilder
constructor
A new instance of FileBuilder.
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 = if [:url] parts = [:url].split('/') if parts.count > 1 [:object] = parts.last.singularize [:class] = parts.last.singularize.capitalize end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'app/services/file_builder.rb', line 15 def @options end |
Instance Method Details
#call ⇒ Object
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 .to_h.each_with_object(parts) do |(option, _value), output| klass = OPTION_KLASS_MAP[option] next unless klass fragments = "FileBuilder::#{klass}".constantize.call(options: ) fragments.each do |part, code| output[part] ||= [] output[part] << code end end end |