lib/dry/initializer/builders/initializer.rb in dry-initializer-3.0.4 vs lib/dry/initializer/builders/initializer.rb in dry-initializer-3.1.0
- old
+ new
@@ -1,57 +1,59 @@
-module Dry::Initializer::Builders
- # @private
- class Initializer
- require_relative 'signature'
- require_relative 'attribute'
+# frozen_string_literal: true
- def self.[](config)
- new(config).call
- end
+module Dry
+ module Initializer
+ module Builders
+ # @private
+ class Initializer
+ require_relative "signature"
+ require_relative "attribute"
- def call
- lines.flatten.compact.join("\n")
- end
+ def self.[](config)
+ new(config).call
+ end
- private
+ def call
+ lines.flatten.compact.join("\n")
+ end
- def initialize(config)
- @config = config
- @definitions = config.definitions.values
- end
+ private
- def lines
- [
- undef_line,
- define_line,
- params_lines,
- options_lines,
- end_line
- ]
- end
+ def initialize(config)
+ @config = config
+ @definitions = config.definitions.values
+ end
- def undef_line
- 'undef :__dry_initializer_initialize__' \
- ' if private_method_defined? :__dry_initializer_initialize__'
- end
+ def lines
+ [
+ undef_line,
+ define_line,
+ params_lines,
+ options_lines,
+ end_line
+ ]
+ end
- def define_line
- "private def __dry_initializer_initialize__(#{Signature[@config]})"
- end
+ def undef_line
+ "undef :__dry_initializer_initialize__" \
+ " if private_method_defined? :__dry_initializer_initialize__"
+ end
- def params_lines
- @definitions.reject(&:option)
- .flat_map { |item| Attribute[item] }
- .map { |line| ' ' << line }
- end
+ def define_line
+ "private def __dry_initializer_initialize__(#{Signature[@config]})"
+ end
- def options_lines
- @definitions.select(&:option)
- .flat_map { |item| Attribute[item] }
- .map { |line| ' ' << line }
- end
+ def params_lines
+ @definitions.reject(&:option).flat_map { Attribute[_1] }.map { " #{_1}" }
+ end
- def end_line
- 'end'
+ def options_lines
+ @definitions.select(&:option).flat_map { Attribute[_1] }.map { " #{_1}" }
+ end
+
+ def end_line
+ "end"
+ end
+ end
end
end
end