Class: RuboCop::Slim::RubyExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/slim/ruby_extractor.rb

Overview

Extract Ruby codes from Slim template.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(processed_source) ⇒ RubyExtractor

Returns a new instance of RubyExtractor.

Parameters:

  • processed_source (RuboCop::ProcessedSource)


19
20
21
# File 'lib/rubocop/slim/ruby_extractor.rb', line 19

def initialize(processed_source)
  @processed_source = processed_source
end

Class Method Details

.call(processed_source) ⇒ Array<RuboCop::ProcessedSource>?

Parameters:

  • processed_source (RuboCop::ProcessedSource)

Returns:

  • (Array<RuboCop::ProcessedSource>, nil)


13
14
15
# File 'lib/rubocop/slim/ruby_extractor.rb', line 13

def call(processed_source)
  new(processed_source).call
end

Instance Method Details

#callArray<RuboCop::ProcessedSource>?

Returns:

  • (Array<RuboCop::ProcessedSource>, nil)


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubocop/slim/ruby_extractor.rb', line 24

def call
  return unless supported_file_path_pattern?

  ruby_clips.map do |ruby_clip|
    {
      offset: ruby_clip.offset,
      processed_source: ProcessedSourceBuilder.call(
        code: ruby_clip.code,
        processed_source: @processed_source
      )
    }
  end
end