Class: Dyna::DynamoDBWrapper::Table

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logger::ClientHelper
Defined in:
lib/dyna/wrapper/table.rb

Instance Method Summary collapse

Methods included from Logger::ClientHelper

#log

Constructor Details

#initialize(ddb, table, options) ⇒ Table

Returns a new instance of Table.



12
13
14
15
16
# File 'lib/dyna/wrapper/table.rb', line 12

def initialize(ddb, table, options)
  @ddb = ddb
  @table = table
  @options = options
end

Instance Method Details

#definitionObject



51
52
53
# File 'lib/dyna/wrapper/table.rb', line 51

def definition
  Exporter.table_definition(@table).symbolize_keys
end

#deleteObject



42
43
44
45
46
47
48
49
# File 'lib/dyna/wrapper/table.rb', line 42

def delete
  log(:info, 'Delete Table', :red, "#{table_name}")
  
  unless @options.dry_run
    @ddb.delete_table(table_name: @table.table_name)
    @options.updated = true
  end
end

#eql?(dsl) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/dyna/wrapper/table.rb', line 18

def eql?(dsl)
  definition_eql?(dsl)
end

#update(dsl) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dyna/wrapper/table.rb', line 22

def update(dsl)
  unless billing_mode_eql?(dsl) && provisioned_throughput_eql?(dsl)
    update_table(dsl)
  end
  unless global_secondary_indexes_eql?(dsl)
    wait_until_table_is_active
    update_table_index(dsl, dsl_global_secondary_index_updates(dsl))
  end
  unless stream_specification_eql?(dsl)
    wait_until_table_is_active
    update_stream_specification(dsl_stream_specification(dsl))
  end
  unless time_to_live_eql?(dsl)
    update_time_to_live(dsl)
  end
  unless auto_scaling_eql?(dsl)
    update_auto_scaling(dsl)
  end
end

#wait_until_table_is_activeObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dyna/wrapper/table.rb', line 55

def wait_until_table_is_active
  log(:info, "waiting table #{@table.table_name} to be ACTIVE or deleted..", false)
  loop do
    begin
      desc = @ddb.describe_table(table_name: table_name).table
    rescue => e
      break
    end
    status = desc.table_status
    log(:info, "status... #{status}", false)
    break if desc.table_status == 'ACTIVE'
    sleep 3
  end
end