Class: Gossip::GossipCommand

Inherits:
UserChoices::Command
  • Object
show all
Includes:
UserChoices
Defined in:
lib/gossip/command.rb

Overview

THe GossipCommand knows how to set up a Preteen’s Crony’s. A particular script should subclass it to add script-specific behavior. See the examples, particularly fanout.rb, for details. To understand more about GossipCommand, see UserChoices::Command in the user-choices gem. user-choices.rubyforge.org.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(preteen) ⇒ GossipCommand

Returns a new instance of GossipCommand.



22
23
24
25
# File 'lib/gossip/command.rb', line 22

def initialize(preteen)
  self.preteen = preteen
  super()
end

Instance Attribute Details

#preteenObject

Returns the value of attribute preteen.



21
22
23
# File 'lib/gossip/command.rb', line 21

def preteen
  @preteen
end

Instance Method Details

#add_arglist_choice(builder) ⇒ Object

By default, the command will stuff all arguments into a choice named :arglist.



50
51
52
53
54
# File 'lib/gossip/command.rb', line 50

def add_arglist_choice(builder)
  builder.add_choice(:arglist) { | command_line |
    command_line.uses_arglist
  }
end

#add_choices(builder) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/gossip/command.rb', line 37

def add_choices(builder)
  first_set_are_specific_to_script(builder)
  all_crony_switches_come_next(builder)
  crony_specific_switches_are_third(builder)
  helpful_switches_go_last(builder)
  
  # Can go anywhere - doesn't appear in help text.
  add_arglist_choice(builder)
end

#describe_all_but_optionsObject



72
73
74
75
76
77
# File 'lib/gossip/command.rb', line 72

def describe_all_but_options
  [usage,
  "Site-wide defaults are noted below.",
  "Override them in the '#{script_config_file}' or '#{gossip_config_file}' files in your home folder."
  ].flatten
end

#postprocess_user_choicesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gossip/command.rb', line 56

def postprocess_user_choices
  if @user_choices[:choices]
    puts "Looking for configuration information in:"
    puts "  " + File.join(S4tUtils.find_home, script_config_file)
    puts "  " + File.join(S4tUtils.find_home, gossip_config_file)
    puts "Choices gathered from all sources:"
    puts alphabetical_symbol_hash(@user_choices)
    exit
  end

  preteen.cronies.each do | crony |
    crony.user_choices = @user_choices
    crony.postprocess_user_choices
  end
end

#script_config_fileObject

Override to name the configuration file specific to this script.



35
# File 'lib/gossip/command.rb', line 35

def script_config_file; subclass_responsibility; end

#usageObject

Text describing the command-line arguments (not the options). Traditionally looks something like:

"Usage: ruby #{$0} [options] args..."

Can be a single line or array of lines. Must be overridden.



32
# File 'lib/gossip/command.rb', line 32

def usage; subclass_responsibility; end