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.
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
#destination ⇒ Object
Returns the value of attribute destination.
67 68 69 |
# File 'lib/spectra/commands.rb', line 67 def destination @destination end |
#source ⇒ Object
Returns the value of attribute source.
67 68 69 |
# File 'lib/spectra/commands.rb', line 67 def source @source end |
Instance Method Details
#run ⇒ Object
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 = 'Failed to create spectrum.rb' += "\n#{exception}" raise Informative, else Spectra.logger.info "[✓] Created #{self.destination}" end end |
#validate! ⇒ Object
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 |