Class: Sh::Actions

Inherits:
Object show all
Defined in:
lib/sh_actions.rb

Constant Summary collapse

@@actions =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *tags, &block) ⇒ Actions

Returns a new instance of Actions.



6
7
8
9
10
11
12
# File 'lib/sh_actions.rb', line 6

def initialize name, *tags, &block
  @@actions << self
  @name = name
  @tags = tags
  @block = block
  @user_data = {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/sh_actions.rb', line 4

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



4
5
6
# File 'lib/sh_actions.rb', line 4

def tags
  @tags
end

#user_dataObject (readonly)

Returns the value of attribute user_data.



4
5
6
# File 'lib/sh_actions.rb', line 4

def user_data
  @user_data
end

Class Method Details

.get(*tags) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sh_actions.rb', line 26

def self.get *tags
  matches = []
  @@actions.each do |action|
    subset = true
    tags.each do |tag|
      subset = false unless action.tags.include? tag
    end
    matches << action if subset
  end
  return matches
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/sh_actions.rb', line 18

def [](key)
  return @user_data[key]
end

#[]=(key, value) ⇒ Object



14
15
16
# File 'lib/sh_actions.rb', line 14

def []=(key, value)
  @user_data[key] = value
end

#execute(*args) ⇒ Object



22
23
24
# File 'lib/sh_actions.rb', line 22

def execute *args
  @block.call *args
end