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
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.
Instance Method Summary collapse
- #call(*args) ⇒ Object
-
#initialize(options = {}, &b) ⇒ Action
constructor
A new instance of Action.
- #to_s ⇒ Object
Methods included from Logging
#init_logger, #log_level=, #log_target=
Methods included from File_Checking
Constructor Details
#initialize(options = {}, &b) ⇒ Action
Returns a new instance of Action.
41 42 43 44 45 46 47 48 49 |
# File 'lib/action.rb', line 41 def initialize( = {}, &b) init_logger(STDOUT, Logger::INFO) @name = [:name] @key = [:key] @proc = b if b @global = [:global] @hidden = [:hidden] end |
Instance Attribute Details
#global ⇒ Object
Returns the value of attribute global.
34 35 36 |
# File 'lib/action.rb', line 34 def global @global end |
#hidden ⇒ Object
Returns the value of attribute hidden.
34 35 36 |
# File 'lib/action.rb', line 34 def hidden @hidden end |
#key ⇒ Object
Returns the value of attribute key.
34 35 36 |
# File 'lib/action.rb', line 34 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/action.rb', line 34 def name @name end |
#proc ⇒ Object
Returns the value of attribute proc.
34 35 36 |
# File 'lib/action.rb', line 34 def proc @proc end |
Instance Method Details
#call(*args) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/action.rb', line 51 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
36 37 38 |
# File 'lib/action.rb', line 36 def to_s "[#<" << classname << ':' << hash << '@name="' << name << '", @key="' << key << '">' end |