Class: SDBTools::Operation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sdbtools/operation.rb

Overview

An Operation represents a SimpleDB operation and handles the details of re-requesting “next tokens” until the operation is complete.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sdb, method, *args) ⇒ Operation

Returns a new instance of Operation.



11
12
13
14
15
16
17
# File 'lib/sdbtools/operation.rb', line 11

def initialize(sdb, method, *args)
  @options = args.last.is_a?(Hash) ? args.pop : {}
  @sdb     = sdb
  @method  = method
  @args    = args
  @starting_token = @options[:starting_token]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



8
9
10
# File 'lib/sdbtools/operation.rb', line 8

def args
  @args
end

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/sdbtools/operation.rb', line 7

def method
  @method
end

#starting_tokenObject (readonly)

Returns the value of attribute starting_token.



9
10
11
# File 'lib/sdbtools/operation.rb', line 9

def starting_token
  @starting_token
end

Instance Method Details

#eachObject

Yields once for each result set, until there is no next token.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sdbtools/operation.rb', line 20

def each
  Transaction.open(":#{method} operation") do |t|
    next_token = starting_token
    begin
      args = @args.dup
      args << next_token
      results = @sdb.send(@method, *args)
      yield(results, self)
      next_token = results[:next_token]
    end while next_token
  end
end