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.



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

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.



67
68
69
# File 'lib/spectra/commands.rb', line 67

def destination
  @destination
end

#sourceObject

Returns the value of attribute source.



67
68
69
# File 'lib/spectra/commands.rb', line 67

def source
  @source
end

Instance Method Details

#runObject



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/spectra/commands.rb', line 87

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.info "[✓] Created #{self.destination}"
  end
end

#validate!Object

Raises:



82
83
84
85
# File 'lib/spectra/commands.rb', line 82

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