Class: Action
Overview
An Action is executed on a user’s request. It has a name, an associated closure and hotkey.
Defined Under Namespace
Classes: ActionError
Constant Summary
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary collapse
-
#global ⇒ Object
Returns the value of attribute global.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#proc ⇒ Object
Returns the value of attribute proc.
Attributes included from BasicLogging
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(options = {}, &b) ⇒ Action
constructor
A new instance of Action.
- #to_s ⇒ Object
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, set_level, set_target, #set_target
Constructor Details
#initialize(options = {}, &b) ⇒ Action
Returns a new instance of Action.
34 35 36 37 38 39 40 41 |
# File 'lib/action.rb', line 34 def initialize( = {}, &b) @name = [:name] @key = [:key] @proc = b if b @global = [:global] @hidden = [:hidden] end |
Instance Attribute Details
#global ⇒ Object
Returns the value of attribute global.
27 28 29 |
# File 'lib/action.rb', line 27 def global @global end |
#hidden ⇒ Object
Returns the value of attribute hidden.
27 28 29 |
# File 'lib/action.rb', line 27 def hidden @hidden end |
#key ⇒ Object
Returns the value of attribute key.
27 28 29 |
# File 'lib/action.rb', line 27 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
27 28 29 |
# File 'lib/action.rb', line 27 def name @name end |
#proc ⇒ Object
Returns the value of attribute proc.
27 28 29 |
# File 'lib/action.rb', line 27 def proc @proc end |
Instance Method Details
#call(*args) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/action.rb', line 43 def call(*args) unless @proc raise ActionError.new((@name ? '' : 'Unnamed ') << 'action' << (@name ? (' ' << @name) : '') << ' called before a command was defined') end @proc.call(*args) end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/action.rb', line 29 def to_s "[#<" << classname << ':' << hash << '@name="' << name << '", @key="' << key << '">' end |