Class: Awestruct::CLI::Manifest::AddRequires

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/cli/manifest.rb

Overview

Adds a requires for each library in libs to the top of the file specified by path

Instance Method Summary collapse

Constructor Details

#initialize(path, libs) ⇒ AddRequires

Returns a new instance of AddRequires.



170
171
172
173
# File 'lib/awestruct/cli/manifest.rb', line 170

def initialize(path, libs)
  @path = path
  @libs = libs
end

Instance Method Details

#perform(dir) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/awestruct/cli/manifest.rb', line 175

def perform(dir)
  file = File.join(dir, @path)
  File.open(file, 'r') do |old|
    File.unlink(file)
    File.open(file, 'w') do |new|
      @libs.each do |lib|
        new.write "require '#{lib}'\n"
      end
      new.write old.read
    end
  end
end

#unperform(dir) ⇒ Object



188
189
190
# File 'lib/awestruct/cli/manifest.rb', line 188

def unperform(dir)
  #nothing
end