Class: Laze::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/laze/target.rb

Constant Summary collapse

TargetException =

Generic exception to be raised for store-specific exceptions.

Class.new(Exception)
FileSystemException =

Exception for when interacting with the filesystem goes bad.

Class.new(TargetException)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_dir) ⇒ Target

:nodoc:



32
33
34
35
36
# File 'lib/laze/target.rb', line 32

def initialize(output_dir) #:nodoc:
  @output_dir = output_dir
  reset
  Laze::Plugins.each(:target) { |plugin| extend plugin }
end

Instance Attribute Details

#output_dirObject (readonly)

The base directory to create all the files in. This is relative the location where laze is run from.



14
15
16
# File 'lib/laze/target.rb', line 14

def output_dir
  @output_dir
end

Class Method Details

.find(kind) ⇒ Object

Find a target deployment engine by name and return its class.

When loading Laze::Targets::Filesystem you would call:

Target.find(:filesystem)

Raises:



22
23
24
25
26
# File 'lib/laze/target.rb', line 22

def self.find(kind)
  targets = @targets.select { |s| s.name.to_s.split('::').last.downcase.to_sym == kind }
  raise TargetException, 'No such target.' unless targets.any?
  targets.first
end

.inherited(child) ⇒ Object

:nodoc:



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

def self.inherited(child) #:nodoc:
  @targets << child
end

Instance Method Details

#create(item) ⇒ Object

Given an item this will create the output file in the right output location.



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

def create(item)
  raise 'This is a generic target. Please use a subclass.'
end

#resetObject

Empty the current output directory



50
51
52
53
54
# File 'lib/laze/target.rb', line 50

def reset
  FileUtils.rm_rf(output_dir) if File.directory?(output_dir)
  FileUtils.mkdir(output_dir) unless File.directory?(output_dir)
  Laze.debug "Emptied output directory #{output_dir}"
end

#saveObject

Finalize the generation and process any after hooks.



39
40
41
# File 'lib/laze/target.rb', line 39

def save
  raise 'This is a generic target. Please use a subclass.'
end