Sha256: 9dbab00ccded4aa796ed5e2f7f36f947186354e52162fe5397860ec8ef7efa0f

Contents?: true

Size: 872 Bytes

Versions: 5

Compression:

Stored size: 872 Bytes

Contents

require 'data_mapper'

module Copy
  module Storage
    class Relational
      class Document
        include DataMapper::Resource
        
        storage_names[:default] = 'copy_documents'
    
        property :id,         Serial
        property :name,       String, :unique_index => true
        property :content,    Text
      end
      
      def initialize(connection_url)
        DataMapper.setup(:default, connection_url)
        DataMapper.finalize
        DataMapper.auto_upgrade!
      end
      
      def get(name)
        doc = Document.first(:name => name)
        doc.content unless doc.nil?
      end
      
      def set(name, content)
        doc = Document.first(:name => name)
        if doc
          doc.update(:content => content)
        else
          Document.create(:name => name, :content => content)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
copy-0.0.41 lib/copy/storage/relational.rb
copy-0.0.4 lib/copy/storage/relational.rb
copy-0.0.3 lib/copy/storage/relational.rb
copy-0.0.2 lib/copy/storage/relational.rb
copy-0.0.1 lib/copy/storage/relational.rb