Class: Osmer::Target::Pg

Inherits:
Object
  • Object
show all
Defined in:
lib/osmer/target/pg.rb

Defined Under Namespace

Classes: Connection

Constant Summary collapse

GEOTYPES =
{ 'point' => 'POINT', 'line' => 'LINESTRING', 'polygon' => 'POLYGON', 'multiline' => 'MULTILINESTRING', 'multipolygon' => 'MULTIPOLYGON' }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Pg

Returns a new instance of Pg.



9
10
11
# File 'lib/osmer/target/pg.rb', line 9

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/osmer/target/pg.rb', line 7

def options
  @options
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/osmer/target/pg.rb', line 13

def [](key)
  @options[key]
end

#geometry_type(type) ⇒ Object



33
34
35
# File 'lib/osmer/target/pg.rb', line 33

def geometry_type(type)
  GEOTYPES[type.to_s.gsub(/s\z/,'')] or raise StandardError.new("Unknown geometry type #{type.inspect}")
end

#in_transactionObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/osmer/target/pg.rb', line 17

def in_transaction
  conn = Connection.new connection_options

  begin
    conn.exec "BEGIN TRANSACTION"

    yield conn

    conn.exec "COMMIT"
  ensure
    conn.close
  end
end