Class: Coppy::Steps::InFiles

Inherits:
Object
  • Object
show all
Extended by:
DSL::Module
Defined in:
lib/coppy/steps/in_files.rb

Instance Method Summary collapse

Methods included from DSL::Module

dsl, step

Constructor Details

#initialize(*file_patterns, &block) ⇒ InFiles

Returns a new instance of InFiles.



15
16
17
18
# File 'lib/coppy/steps/in_files.rb', line 15

def initialize(*file_patterns, &block)
  @patterns = file_patterns
  @manifesto = Manifesto.load(self.class.dsl, &block)
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/coppy/steps/in_files.rb', line 20

def call(env)
  files = @patterns.flat_map { |pattern| Dir.glob(File.join env.target, pattern) }
  files.each do |file_path|
    file = File.read(file_path)
    local_env = env.subenv(
      file: file
    )
    @manifesto.execute!(local_env)
    File.open(file_path, 'w') { |f| f.write local_env.file }
  end
end