app/models/effective/code_writer.rb in effective_developer-0.4.2 vs app/models/effective/code_writer.rb in effective_developer-0.4.3

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Effective::CodeWriter.new('Gemfile') do |w| # @use_effective_resources = w.find { |line| line.include?('effective_resources') }.present? # end # end @@ -7,11 +9,11 @@ class CodeWriter attr_reader :lines attr_reader :filename, :indent, :newline - def initialize(filename, indent: ' '.freeze, newline: "\n".freeze, &block) + def initialize(filename, indent: ' ', newline: "\n", &block) @filename = filename @indent = indent @newline = newline @from = [] @@ -236,17 +238,17 @@ end def open?(content) stripped = ss(content) - [' do'].any? { |end_with| stripped.split('#').first.to_s.end_with?(end_with) } || - ['class ', 'module ', 'def ', 'if '].any? { |start_with| stripped.start_with?(start_with) } + ['class ', 'module ', 'def ', 'if '].any? { |start_with| stripped.start_with?(start_with) } || + (stripped.include?(' do') && !stripped.end_with?('end')) end def close?(content) stripped = ss(content, array_method: :last) - stripped.end_with?('end'.freeze) && !stripped.include?('do ') + stripped.end_with?('end') && !stripped.include?('do ') end def whitespace?(content) ss(content).length == 0 end @@ -264,9 +266,9 @@ def ss(value, array_method: :first) value = case value when Integer then lines[value] when Array then value.send(array_method) else value - end.strip + end.to_s.split('#').first.to_s.strip end end end