Class: Scaffolder::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/scaffolder/tool.rb

Direct Known Subclasses

Help, Sequence, Validate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ Tool

Returns a new instance of Tool.



10
11
12
13
14
# File 'lib/scaffolder/tool.rb', line 10

def initialize(settings)
  @scaffold_file = settings.rest.first
  @sequence_file = settings.rest.last
  @settings = settings
end

Instance Attribute Details

#scaffold_fileObject (readonly)

Returns the value of attribute scaffold_file.



6
7
8
# File 'lib/scaffolder/tool.rb', line 6

def scaffold_file
  @scaffold_file
end

#sequence_fileObject (readonly)

Returns the value of attribute sequence_file.



7
8
9
# File 'lib/scaffolder/tool.rb', line 7

def sequence_file
  @sequence_file
end

#settingsObject (readonly)

Returns the value of attribute settings.



8
9
10
# File 'lib/scaffolder/tool.rb', line 8

def settings
  @settings
end

Instance Method Details

#run(out = STDOUT, err = STDERR) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scaffolder/tool.rb', line 16

def run(out=STDOUT,err=STDERR)
  begin
    message = execute
  rescue Exception => e
    err.puts("Error. #{e.message}")
    exit(1)
  else
    out.puts(message) if message
    exit(0)
  end
end

#scaffoldObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scaffolder/tool.rb', line 28

def scaffold
  {:Scaffold => @scaffold_file, :Sequence => @sequence_file}.each do |name,file|
    unless File.exists?(file)
      raise ArgumentError.new("#{name} file not found: #{file}")
    end
    if File.size(file) == 0
      raise ArgumentError.new("#{name} file is empty: #{file}")
    end
  end

  Scaffolder.new(YAML.load(File.read(@scaffold_file)),@sequence_file)
end