Class: Action

Inherits:
Object
  • Object
show all
Includes:
Logging
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#init_logger, #log_level=, #log_target=

Methods included from File_Checking

#file_check, file_check

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(options = {}, &b)
  init_logger(STDOUT, Logger::INFO)

  @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.



34
35
36
# File 'lib/action.rb', line 34

def global
  @global
end

#hiddenObject

Returns the value of attribute hidden.



34
35
36
# File 'lib/action.rb', line 34

def hidden
  @hidden
end

#keyObject

Returns the value of attribute key.



34
35
36
# File 'lib/action.rb', line 34

def key
  @key
end

#nameObject

Returns the value of attribute name.



34
35
36
# File 'lib/action.rb', line 34

def name
  @name
end

#procObject

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_sObject



36
37
38
# File 'lib/action.rb', line 36

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