Class: Osmer::Updater

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/osmer/updater.rb

Defined Under Namespace

Classes: Dsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configurable

#configure

Constructor Details

#initialize(interval = nil) ⇒ Updater

Returns a new instance of Updater.



8
9
10
# File 'lib/osmer/updater.rb', line 8

def initialize(interval = nil)
  @interval = interval
end

Instance Attribute Details

#diffObject

Returns the value of attribute diff.



6
7
8
# File 'lib/osmer/updater.rb', line 6

def diff
  @diff
end

#dumpObject

Returns the value of attribute dump.



6
7
8
# File 'lib/osmer/updater.rb', line 6

def dump
  @dump
end

#intervalObject

Returns the value of attribute interval.



6
7
8
# File 'lib/osmer/updater.rb', line 6

def interval
  @interval
end

Instance Method Details

#load_diffs(db, schema) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/osmer/updater.rb', line 12

def load_diffs(db, schema)
  db.in_transaction do |conn|
    init_meta_table conn, schema
    cur = get_current_version conn, schema

    puts "Requesting diff versions"
    versions = get_diff_versions

    while version = versions.detect{|d| d[0] == cur }
      puts "Downloading diff #{version.join('-')}"
      file = download_file diff, version

      puts "Applying diff #{file}"
      yield file

      set_current_version conn, schema, version[1]
      cur = version[1]
    end
  end
end

#load_dump(db, schema) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/osmer/updater.rb', line 33

def load_dump(db, schema)
  db.in_transaction do |conn|
    init_meta_table conn, schema

    puts "Requesting last dump version"
    version = get_dump_version

    puts "Downloading dump #{version.join('-')}"
    file = download_file dump, version

    puts "Loading dump #{file}"
    yield file

    set_current_version conn, schema, version[0]
  end
end

#reset(db, schema) ⇒ Object



50
51
52
53
54
55
# File 'lib/osmer/updater.rb', line 50

def reset(db, schema)
  db.in_transaction do |conn|
    init_meta_table conn, schema
    reset_current_version conn, schema
  end
end