Class: Target::Base
- Includes:
- HasDirectories, HasOptionMethods
- Defined in:
- lib/gpm/target.rb
Direct Known Subclasses
Constant Summary collapse
- PHASES =
[:file_creation, :packaging]
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#work_dir ⇒ Object
readonly
Returns the value of attribute work_dir.
Class Method Summary collapse
- .add_step_for_phase(phase, block, description = nil) ⇒ Object
- .field_name_for_steps(phase) ⇒ Object
- .phase_steps_names ⇒ Object
- .steps_for_phase(phase) ⇒ Object
Instance Method Summary collapse
- #create_package(source) ⇒ Object
- #exec(*args) ⇒ Object
-
#initialize(work_dir, options = {}) ⇒ Base
constructor
A new instance of Base.
- #package_dir ⇒ Object
- #tar(output, files, options = {}) ⇒ Object
- #tar_directory(directory, options = {}) ⇒ Object
- #type ⇒ Object
Methods included from HasOptionMethods
Methods included from HasDirectories
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, = {}) @work_dir = work_dir @logger = create_logger @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
34 35 36 |
# File 'lib/gpm/target.rb', line 34 def @options end |
#work_dir ⇒ Object (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_names ⇒ Object
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_dir ⇒ Object
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, ={}) exec("tar -zcf #{output} #{files.map{ |f| "./#{f}" }.join(" ")} "+.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, = {}) FileUtils.mkdir_p(directory) ::Dir.chdir(directory) do tar(File.join('..',directory.gsub('.dir','')),[''], ) end end |
#type ⇒ Object
41 42 43 |
# File 'lib/gpm/target.rb', line 41 def type self.class.name.downcase.gsub("target::","") end |