Class: Spectra::Command::Generate

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

Overview

Subcommands

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Generate

Returns a new instance of Generate.



42
43
44
45
46
# File 'lib/spectra/commands.rb', line 42

def initialize(argv)
  # update config from options 
  Config.dry_run = argv.flag?('dry-run', false)
  super
end

Class Method Details

.optionsObject



36
37
38
39
40
# File 'lib/spectra/commands.rb', line 36

def self.options
  [[
    '--dry-run', 'Prints the would-be output file rather than generating anything' 
  ]].concat(super)
end

Instance Method Details

#runObject



57
58
59
60
61
# File 'lib/spectra/commands.rb', line 57

def run
  # generate the views from the user's spectrum.rb
  spectrum = Spectra::Spectrum.new
  spectrum.generate(@definition)
end

#validate!Object



48
49
50
51
52
53
54
55
# File 'lib/spectra/commands.rb', line 48

def validate!
  super
  begin
    @definition = IO.read('spectrum.rb')
  rescue Exception
    raise Informative, 'Failed to find a spectrum.rb file in the current directory'
  end 
end