Class: Autumn::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/autumn/script.rb

Overview

Manages data used by the script/generate and script/destroy scripts. This class is instantiated by the script, and manages the script’s data and encapsulates common functionality between the two scripts. The object must be initialized and parse_argv must be called before all attributes are ready for access.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScript

Creates a new instance.



29
30
31
# File 'lib/autumn/script.rb', line 29

def initialize
  @generator = Autumn::Generator.new
end

Instance Attribute Details

#generatorObject (readonly)

The Generator instance used to create files.



25
26
27
# File 'lib/autumn/script.rb', line 25

def generator
  @generator
end

#nameObject (readonly)

The name of the Autumn object to be created.



19
20
21
# File 'lib/autumn/script.rb', line 19

def name
  @name
end

#objectObject (readonly)

The type of object to be created (e.g., “leaf”).



21
22
23
# File 'lib/autumn/script.rb', line 21

def object
  @object
end

#vcsObject (readonly)

The version control system in use for this project, or nil if none is being used for this transaction.



23
24
25
# File 'lib/autumn/script.rb', line 23

def vcs
  @vcs
end

Instance Method Details

#call_generator(meth) ⇒ Object

Calls the method given by the symbol, with two arguments: the name attribute, and an options hash verbosity enabled and the VCS set to the value of vcs.



61
62
63
# File 'lib/autumn/script.rb', line 61

def call_generator(meth)
  generator.send(meth, name, :verbose => true, :vcs => vcs)
end

#parse_argv(argv) ⇒ Object

Parses ARGV or similar array. Normally you would pass ARGV into this method. Populates the object and name attributes and returns true. Outputs an error and returns false if the given arguments are invalid.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/autumn/script.rb', line 37

def parse_argv(argv)
  if ARGV.length != 2 then
    $stderr.puts "Please specify an object (e.g., 'leaf') and its name (e.g., 'Scorekeeper')."
    return false
  end

  @object = ARGV.shift
  @name = ARGV.shift
  
  return true
end

#use_vcsObject

Determines the version control system in use by this project and sets the vcs attribute to its name (:cvs, :svn, or :git).



53
54
55
# File 'lib/autumn/script.rb', line 53

def use_vcs
  @vcs = find_vcs
end