Class: Sohm::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/sohm/command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, *args) ⇒ Command

Returns a new instance of Command.



13
14
15
16
17
# File 'lib/sohm/command.rb', line 13

def initialize(operation, *args)
  @operation = operation
  @args = args
  @keys = []
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/sohm/command.rb', line 10

def args
  @args
end

#keysObject (readonly)

Returns the value of attribute keys.



11
12
13
# File 'lib/sohm/command.rb', line 11

def keys
  @keys
end

#operationObject (readonly)

Returns the value of attribute operation.



9
10
11
# File 'lib/sohm/command.rb', line 9

def operation
  @operation
end

Class Method Details

.[](operation, head, *tail) ⇒ Object



3
4
5
6
7
# File 'lib/sohm/command.rb', line 3

def self.[](operation, head, *tail)
  return head if tail.empty?

  new(operation, head, *tail)
end

Instance Method Details

#call(nido, redis) ⇒ Object



19
20
21
22
23
# File 'lib/sohm/command.rb', line 19

def call(nido, redis)
  newkey(nido, redis) do |key|
    redis.call(@operation, key, *params(nido, redis))
  end
end

#cleanObject



25
26
27
28
29
30
31
# File 'lib/sohm/command.rb', line 25

def clean
  keys.each do |key, redis|
    redis.call("DEL", key)
  end

  subcommands.each { |cmd| cmd.clean }
end