Class: Spectra::Command::Init
- Inherits:
-
Spectra::Command
- Object
- CLAide::Command
- Spectra::Command
- Spectra::Command::Init
- Defined in:
- lib/spectra/commands.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Init
constructor
A new instance of Init.
- #run ⇒ Object
- #validate! ⇒ Object
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
#destination ⇒ Object
Returns the value of attribute destination.
62 63 64 |
# File 'lib/spectra/commands.rb', line 62 def destination @destination end |
#source ⇒ Object
Returns the value of attribute source.
62 63 64 |
# File 'lib/spectra/commands.rb', line 62 def source @source end |
Instance Method Details
#run ⇒ Object
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 = 'Failed to create spectrum.rb' += "\n#{exception}" raise Informative, else Spectra.logger.debug "[✓] Created #{self.destination}" end end |
#validate! ⇒ Object
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 |