Class: Tesler::Copier

Inherits:
Object show all
Includes:
Operators::Base, Operators::Logger, Operators::Run
Defined in:
lib/tesler/copier.rb

Overview

This the class which receives the DSL commands.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Operators::Run

#copy_dir, #copy_file, #set_directory

Methods included from Operators::Logger

#copy_dir, #copy_file, destination_name, #set_directory

Methods included from Operators::Base

#destination_name

Constructor Details

#initialize(directory_name) ⇒ Copier

Returns a new instance of Copier.



8
9
10
11
# File 'lib/tesler/copier.rb', line 8

def  initialize(directory_name)
  @directory_name = directory_name
  self.as(Tesler::Config.operator).set_directory(@directory_name)
end

Class Method Details

.directory(directory_name, &block) ⇒ Object

Method called by the DSL method ‘directory’



37
38
39
40
# File 'lib/tesler/copier.rb', line 37

def self.directory(directory_name, &block)
  copier = Copier.new(directory_name)
  copier.instance_eval(&block)
end

Instance Method Details

#copy(file_name, options = {}) ⇒ Object

Method called by the DSL method ‘copy’



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tesler/copier.rb', line 14

def copy(file_name, options={})
  filename = file_name.tesler
  if not Tesler::Config.source_directory.blank?
    filename = "#{Tesler::Config.source_directory}/#{filename}"
  end
  
  # if the file's name contains a star, then it is considered as a regular expression
  if filename.include? "*"
    regexp_copy(filename, options)

  # the file's name is not a regular expression, so we copy it directly
  else
    direct_copy(filename, options)
  end
end

#directory(directory_name, &block) ⇒ Object

This method create a sub-directory



31
32
33
34
# File 'lib/tesler/copier.rb', line 31

def directory(directory_name, &block)
  copier = Copier.new("#{@directory_name}/#{directory_name}")
  copier.instance_eval(&block)
end