Class: MultiRedis::Operation

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

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Operation

Returns a new instance of Operation.



121
122
123
124
125
126
127
128
129
130
# File 'lib/multi_redis.rb', line 121

def initialize *args, &block

  options = args.last.kind_of?(Hash) ? args.pop : {}

  @target = args.shift || options[:target] || self
  @redis = options[:redis]
  @steps = []

  DSL.new(self).instance_eval &block
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



119
120
121
# File 'lib/multi_redis.rb', line 119

def steps
  @steps
end

Instance Method Details

#add_step(multi_type = nil, &block) ⇒ Object



140
141
142
# File 'lib/multi_redis.rb', line 140

def add_step multi_type = nil, &block
  @steps << Step.new(@target, multi_type, block)
end

#execute(*args) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/multi_redis.rb', line 132

def execute *args
  if MultiRedis.executing?
    MultiRedis.register_operation self, *args
  else
    Executor.new([ self ], args: [ args ], redis: @redis).execute.first
  end
end