Class: Chirp::Application

Inherits:
Object
  • Object
show all
Includes:
FSSugar
Defined in:
lib/chirp/application.rb

Instance Method Summary collapse

Methods included from FSSugar

#all, #bigger, #contains, #dir?, #except, #file?, #length, #named, #none, #smaller

Constructor Details

#initializeApplication

Returns a new instance of Application.



242
243
244
245
# File 'lib/chirp/application.rb', line 242

def initialize
  @processors = []
  @context = Context.new
end

Instance Method Details

#comment(*args) ⇒ Object



264
265
266
# File 'lib/chirp/application.rb', line 264

def comment(*args)
  @context.comment(*args)
end

#copy(options = {}) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/chirp/application.rb', line 284

def copy(options={})
  options = options.clone
  options[:create_backups] = false unless options.key?(:create_backups)
  options[:redirect_output]= false
  @context.debug('Processing copy command:', options)
  each_path options do
    raise "Output path not specified for copy" unless output_path
    cp   full_path, output_path unless options[:recursive]
    cp_r full_path, output_path if options[:recursive]
  end
end

#dir(path) ⇒ Object



251
252
253
# File 'lib/chirp/application.rb', line 251

def dir(path)
  @processors << StaringWithProcessor.new(@context, path)
end

#each(options = {}, &block) ⇒ Object



268
269
270
271
# File 'lib/chirp/application.rb', line 268

def each(options={}, &block)
  @context.debug('Processing each command:', block)
  @processors << EachProcessor.new(@context, options, &block)
end

#each_dir(options = {}, &block) ⇒ Object



317
318
319
320
321
322
# File 'lib/chirp/application.rb', line 317

def each_dir(options={}, &block)
  @context.debug('Processing each_dir command:', options, block)
  new_options = options.clone
  new_options[:type] = :dir
  each_path(new_options, &block)
end

#each_file(options = {}, &block) ⇒ Object



303
304
305
306
307
308
# File 'lib/chirp/application.rb', line 303

def each_file(options={}, &block)
  @context.debug('Processing each_file command:', options, block)
  new_options = options.clone
  new_options[:type] = :file
  each_path(new_options, &block)
end

#each_line(options = {}, &block) ⇒ Object



310
311
312
313
314
315
# File 'lib/chirp/application.rb', line 310

def each_line(options={}, &block)
  @context.debug('Processing each_line command:', options, block)
  each(options) do
    line(options,&block)
  end
end

#each_path(options = {}, &block) ⇒ Object



296
297
298
299
300
301
# File 'lib/chirp/application.rb', line 296

def each_path(options={}, &block)
  @context.debug('Processing each_path command:', options, block)
  each(options) do
    before(&block)
  end
end

#execute(in_stream = $stdin, out_stream = $stdout) ⇒ Object



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/chirp/application.rb', line 324

def execute(in_stream=$stdin, out_stream=$stdout)
  @context.debug('Application execute')

  temp_file = nil
  @context.debug('Sources: ', *@context.paths)
  Chirp::run_with_input_stream(in_stream) do
    Chirp::run_with_output_stream(out_stream) do
      @processors.each do |processor|
        @context.debug('Calling ', processor)
        processor.execute
      end
    end
  end
  temp_file.unlink if temp_file
end

#mv(options = {}) ⇒ Object



273
274
275
276
277
278
279
280
281
282
# File 'lib/chirp/application.rb', line 273

def mv(options={})
  @context.debug('Processing mv command:', options)
  options = options.clone
  options[:create_backups] = false unless options.key?(:create_backups)
  options[:redirect_output]= false
  each_path options do
    raise "Output path not specified for rename" unless output_path
    mv full_path, output_path
  end
end

#now(&block) ⇒ Object



259
260
261
262
# File 'lib/chirp/application.rb', line 259

def now(&block)
  @context.debug('Processing now command:', block)
  @processors << NowProcessor.new(@context, &block)
end

#program(chirp_string, file = '-') ⇒ Object



247
248
249
# File 'lib/chirp/application.rb', line 247

def program(chirp_string, file='-')
  instance_eval(chirp_string, file)
end

#verbose(setting = true) ⇒ Object



255
256
257
# File 'lib/chirp/application.rb', line 255

def verbose(setting=true)
  @context.verbose = setting
end