Class: Target::Base

Inherits:
Object show all
Includes:
HasDirectories, HasOptionMethods
Defined in:
lib/gpm/target.rb

Direct Known Subclasses

Deb

Constant Summary collapse

PHASES =
[:file_creation, :packaging]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasOptionMethods

included

Methods included from HasDirectories

#in_directory

Constructor Details

#initialize(work_dir, options = {}) ⇒ Base

Returns a new instance of Base.



35
36
37
38
39
# File 'lib/gpm/target.rb', line 35

def initialize(work_dir, options = {})
  @work_dir = work_dir
  @logger = create_logger
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/gpm/target.rb', line 34

def options
  @options
end

#work_dirObject (readonly)

Returns the value of attribute work_dir.



34
35
36
# File 'lib/gpm/target.rb', line 34

def work_dir
  @work_dir
end

Class Method Details

.add_step_for_phase(phase, block, description = nil) ⇒ Object



28
29
30
# File 'lib/gpm/target.rb', line 28

def self.add_step_for_phase(phase, block, description = nil)
  steps_for_phase(phase) << [block, description]
end

.field_name_for_steps(phase) ⇒ Object



22
23
24
# File 'lib/gpm/target.rb', line 22

def self.field_name_for_steps(phase)
  "#{phase}_steps".to_sym
end

.phase_steps_namesObject



19
20
21
# File 'lib/gpm/target.rb', line 19

def self.phase_steps_names
  PHASES.collect {|p| field_name_for_steps p }
end

.steps_for_phase(phase) ⇒ Object



25
26
27
# File 'lib/gpm/target.rb', line 25

def self.steps_for_phase(phase)
  self.send(field_name_for_steps(phase))
end

Instance Method Details

#create_package(source) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gpm/target.rb', line 49

def create_package(source)
  @origin_dir = Dir.getwd
  FileUtils.mkdir_p package_dir
  in_directory package_dir do
    self.class.phase_steps_names.each do |phase_name|
      steps_for_phase = self.class.send(phase_name)
      steps_for_phase.each do |step, description|
        @logger.info description if description
        instance_exec source, &step
      end
    end
  end
end

#exec(*args) ⇒ Object



75
76
77
78
79
# File 'lib/gpm/target.rb', line 75

def exec(*args)
  @logger.debug args.join(" ")
  success = system(*args)
  @logger.error "#{args.join(" ")} did not complete successfully!" unless success
end

#package_dirObject



45
46
47
# File 'lib/gpm/target.rb', line 45

def package_dir
  File.join(work_dir,'package_files')
end

#tar(output, files, options = {}) ⇒ Object



71
72
73
# File 'lib/gpm/target.rb', line 71

def tar(output, files, options={})
  exec("tar -zcf #{output} #{files.map{ |f| "./#{f}" }.join(" ")} "+options.collect {|k,v| "--#{k}=#{v}"}.join(" "))
end

#tar_directory(directory, options = {}) ⇒ Object



64
65
66
67
68
69
# File 'lib/gpm/target.rb', line 64

def tar_directory(directory, options = {})
    FileUtils.mkdir_p(directory)
    ::Dir.chdir(directory) do
      tar(File.join('..',directory.gsub('.dir','')),[''], options)
    end
end

#typeObject



41
42
43
# File 'lib/gpm/target.rb', line 41

def type
  self.class.name.downcase.gsub("target::","")
end