Sha256: ae5f073ed75fcaa1ed742c526821805e26d127625ee645a054707e38dddcda15

Contents?: true

Size: 883 Bytes

Versions: 9

Compression:

Stored size: 883 Bytes

Contents

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 if defined?(DataMapper::Resource)
      
      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

9 entries across 9 versions & 2 rubygems

Version Path
copy_no_dependency-0.2.0 lib/copy/storage/relational.rb
copy-0.2.0 lib/copy/storage/relational.rb
copy-0.1.7 lib/copy/storage/relational.rb
copy-0.1.6 lib/copy/storage/relational.rb
copy-0.1.5 lib/copy/storage/relational.rb
copy-0.1.4 lib/copy/storage/relational.rb
copy-0.1.3 lib/copy/storage/relational.rb
copy-0.1.2 lib/copy/storage/relational.rb
copy-0.1.1 lib/copy/storage/relational.rb