Class: RuboCop::Erb::RubyExtractor

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

Overview

Extract Ruby codes from Erb template.

Defined Under Namespace

Classes: ErbNode

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)


20
21
22
# File 'lib/rubocop/erb/ruby_extractor.rb', line 20

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)


14
15
16
# File 'lib/rubocop/erb/ruby_extractor.rb', line 14

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

Instance Method Details

#callArray<RuboCop::ProcessedSource>?

Returns:

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


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

def call
  return unless supported_file_path_pattern?

  ruby_clips.map do |ruby_clip|
    {
      offset: ruby_clip.offset,
      processed_source: ruby_clip_to_processed_source(ruby_clip)
    }
  end
end