Class: Spectra::Command::Init

Inherits:
Spectra::Command show all
Defined in:
lib/spectra/commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Init

Returns a new instance of Init.



71
72
73
74
75
# File 'lib/spectra/commands.rb', line 71

def initialize(argv)
  super
  self.source = File.dirname(__FILE__) + '/template.rb'
  self.destination = "#{Dir.pwd}/spectrum.rb"
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



62
63
64
# File 'lib/spectra/commands.rb', line 62

def destination
  @destination
end

#sourceObject

Returns the value of attribute source.



62
63
64
# File 'lib/spectra/commands.rb', line 62

def source
  @source
end

Instance Method Details

#runObject



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/spectra/commands.rb', line 82

def run
  begin
    IO.copy_stream(self.source, self.destination)
  rescue Exception => exception
    message  = 'Failed to create spectrum.rb'
    message += "\n#{exception}"
    raise Informative, message
  else
    Spectra.logger.debug "[✓] Created #{self.destination}"
  end
end

#validate!Object

Raises:



77
78
79
80
# File 'lib/spectra/commands.rb', line 77

def validate!
  super 
  raise Informative, "#{self.destination} already exists" if File.file?(self.destination) 
end