Class: Copy::Storage::Relational

Inherits:
Object
  • Object
show all
Defined in:
lib/copy/storage/relational.rb

Defined Under Namespace

Classes: Document

Instance Method Summary collapse

Constructor Details

#initialize(connection_url) ⇒ Relational

Returns a new instance of Relational.



14
15
16
17
18
# File 'lib/copy/storage/relational.rb', line 14

def initialize(connection_url)
  DataMapper.setup(:default, connection_url)
  DataMapper.finalize
  DataMapper.auto_upgrade!
end

Instance Method Details

#get(name) ⇒ Object



20
21
22
23
# File 'lib/copy/storage/relational.rb', line 20

def get(name)
  doc = Document.first(:name => name)
  doc.content unless doc.nil?
end

#set(name, content) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/copy/storage/relational.rb', line 25

def set(name, content)
  doc = Document.first(:name => name)
  if doc
    doc.update(:content => content)
  else
    Document.create(:name => name, :content => content)
  end
end