Class: Gossip::Crony
- Inherits:
-
Object
- Object
- Gossip::Crony
- Defined in:
- lib/gossip/crony.rb
Overview
This is the base class for the different Crony objects that the Preteen gossips with. A Crony object is something like mail, Twitter, Jabber, or anything that can accept a message and do something useful with it.
To understand Crony, you should first understand GossipCommand and Preteen. It’s helpful to understand the user-choices gem: http://user-choices.rubyforge.org
Direct Known Subclasses
CampfireCrony, JabberCrony, SmtpCrony, StdoutCrony, TracCrony, TwitterCrony
Instance Attribute Summary collapse
-
#is_bff_by_default ⇒ Object
writeonly
:nodoc:.
-
#user_choices ⇒ Object
writeonly
:nodoc:.
Instance Method Summary collapse
-
#add_bff_choice(builder) ⇒ Object
:nodoc:.
-
#add_configuration_choices(builder) ⇒ Object
This method describes how the user can control the Crony’s behavior in a config file or on the command-line.
-
#checked(symbol) ⇒ Object
:nodoc:.
-
#command_line_description ⇒ Object
There is a single configuration choice used to include the Crony in the gossip or exclude her.
-
#df(symbol) ⇒ Object
:nodoc:.
-
#hear(scandal, details) ⇒ Object
This does the work of accepting a message and doing something useful with it.
-
#initialize(defaults = {}) ⇒ Crony
constructor
Each Crony will require some information like an account name, a password, etc.
-
#is_bff? ⇒ Boolean
Is this Crony, at this moment, a Best Friend Forever who will be told gossip by the Preteen? (is_bff_by_default? is used to find the starting value of this boolean.).
-
#is_bff_by_default? ⇒ Boolean
By default, will this Crony be told gossip?.
-
#name ⇒ Object
This method returns a string identifying the Crony.
-
#postprocess_user_choices ⇒ Object
This method is called from UserChoices::Command::postprocess_user_choices.
-
#symbol ⇒ Object
This symbol identifies the crony within Ruby code.
Constructor Details
#initialize(defaults = {}) ⇒ Crony
Each Crony will require some information like an account name, a password, etc. Those can be specified by the user. If not, these values are used. By convention, the keys in the hash begin with :default_. So not override initialize; the work is done elsewhere.
21 22 23 |
# File 'lib/gossip/crony.rb', line 21 def initialize(defaults = {}) @defaults = defaults end |
Instance Attribute Details
#is_bff_by_default=(value) ⇒ Object (writeonly)
:nodoc:
66 67 68 |
# File 'lib/gossip/crony.rb', line 66 def is_bff_by_default=(value) @is_bff_by_default = value end |
#user_choices=(value) ⇒ Object (writeonly)
:nodoc:
66 67 68 |
# File 'lib/gossip/crony.rb', line 66 def user_choices=(value) @user_choices = value end |
Instance Method Details
#add_bff_choice(builder) ⇒ Object
:nodoc:
78 79 80 81 82 83 84 |
# File 'lib/gossip/crony.rb', line 78 def add_bff_choice(builder) # :nodoc: builder.add_choice(self.symbol, :type => :boolean, :default => is_bff_by_default?) { | command_line | command_line.uses_switch(*command_line_description) } end |
#add_configuration_choices(builder) ⇒ Object
This method describes how the user can control the Crony’s behavior in a config file or on the command-line. This method is called from UserChoices::Command#add_choices; see its documentation (in the user-choices gem). Or look at subclasses for examples.
Don’t bother overriding this if there are no configuration choices.
58 59 |
# File 'lib/gossip/crony.rb', line 58 def add_configuration_choices(builder) end |
#checked(symbol) ⇒ Object
:nodoc:
86 87 88 89 90 91 92 93 94 |
# File 'lib/gossip/crony.rb', line 86 def checked(symbol) # :nodoc: prog1(@defaults[symbol]) do | value | if value.nil? raise StandardError, "#{symbol.inspect} is nil for #{name} - likely a typo in a configuration file.\n" + @defaults.inspect end end end |
#command_line_description ⇒ Object
There is a single configuration choice used to include the Crony in the gossip or exclude her. This method returns an array of strings describing that option. It should be in the format used by OptionParser (optparse). Must be overridden.
48 49 50 |
# File 'lib/gossip/crony.rb', line 48 def command_line_description subclass_responsibility end |
#df(symbol) ⇒ Object
:nodoc:
96 97 98 |
# File 'lib/gossip/crony.rb', line 96 def df(symbol) # :nodoc: "Defaults to #{checked(symbol).inspect}." end |
#hear(scandal, details) ⇒ Object
This does the work of accepting a message and doing something useful with it. Must be overridden. The scandal is a short description. Some types of Crony (such as twitter) pay attention only to it, and ignore the details.
29 30 31 |
# File 'lib/gossip/crony.rb', line 29 def hear(scandal, details) subclass_responsibility end |
#is_bff? ⇒ Boolean
Is this Crony, at this moment, a Best Friend Forever who will be told gossip by the Preteen? (is_bff_by_default? is used to find the starting value of this boolean.)
74 75 76 |
# File 'lib/gossip/crony.rb', line 74 def is_bff? @user_choices[symbol] end |
#is_bff_by_default? ⇒ Boolean
By default, will this Crony be told gossip?
69 |
# File 'lib/gossip/crony.rb', line 69 def is_bff_by_default?; @is_bff_by_default; end |
#name ⇒ Object
This method returns a string identifying the Crony. It is used in error messages. Must be overridden.
35 36 37 |
# File 'lib/gossip/crony.rb', line 35 def name subclass_responsibility end |
#postprocess_user_choices ⇒ Object
This method is called from UserChoices::Command::postprocess_user_choices. See the documentation for the user-choices gem.
63 64 |
# File 'lib/gossip/crony.rb', line 63 def postprocess_user_choices end |
#symbol ⇒ Object
This symbol identifies the crony within Ruby code. Must be overridden.
40 41 42 |
# File 'lib/gossip/crony.rb', line 40 def symbol subclass_responsibility end |