Class: Action

Inherits:
Object
  • Object
show all
Includes:
BasicLogging
Defined in:
lib/action.rb

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

Attributes included from BasicLogging

#log_level, #target

Instance Method Summary collapse

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(options = {}, &b)

  @name = options[:name]
  @key = options[:key]
  @proc = b if b
  @global = options[:global]
  @hidden = options[:hidden]
end

Instance Attribute Details

#globalObject

Returns the value of attribute global.



27
28
29
# File 'lib/action.rb', line 27

def global
  @global
end

#hiddenObject

Returns the value of attribute hidden.



27
28
29
# File 'lib/action.rb', line 27

def hidden
  @hidden
end

#keyObject

Returns the value of attribute key.



27
28
29
# File 'lib/action.rb', line 27

def key
  @key
end

#nameObject

Returns the value of attribute name.



27
28
29
# File 'lib/action.rb', line 27

def name
  @name
end

#procObject

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_sObject



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

def to_s
  "[#<" << classname << ':' << hash << '@name="' << name << '", @key="' << key << '">'
end