Class: Rails::Webpack::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/webpack/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, collections) ⇒ Processor

Returns a new instance of Processor.



2
3
4
5
6
7
8
9
10
# File 'lib/rails/webpack/processor.rb', line 2

def initialize(file, collections)
  @contents = File.read(file).lines.map(&:rstrip)
  @file = file
  @collections = collections
  @generated = []
  @scope = []
  @depth = 0
  @indent = ' ' * 2
end

Instance Method Details

#flushObject



24
25
26
# File 'lib/rails/webpack/processor.rb', line 24

def flush
  File.write @file, @generated.join("\n")
end

#process(config_list) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails/webpack/processor.rb', line 12

def process(config_list)
  @contents.each do |line|
    next if comments(line)
    next if blank_lines(line)
    @depth = line.match(/(^(#{@indent}){0,})/)[1].length / @indent.length
    @scope[@depth] = line.split(':').first.strip
    @fullname = @scope[0, @depth + 1].join('.')
    next if process_configs(config_list)
    @generated << line
  end
end