Sha256: eefdd984a506fd180f2efd77314b1355363331de7dacbb37a915bf224fc5e8a1

Contents?: true

Size: 1 KB

Versions: 27

Compression:

Stored size: 1 KB

Contents

module NanoStore  
  class NanoStoreError < StandardError; end

  def self.store(type=:memory, path=nil)
    error_ptr = Pointer.new(:id)

    case type
    when :memory
      store = NSFNanoStore.createAndOpenStoreWithType(NSFMemoryStoreType, path:nil, error: error_ptr)
    when :temporary, :temp
      store = NSFNanoStore.createAndOpenStoreWithType(NSFTemporaryStoreType, path:nil, error: error_ptr)
    when :persistent, :file
      store = NSFNanoStore.createAndOpenStoreWithType(NSFPersistentStoreType, path:path, error: error_ptr)
    else
      raise NanoStoreError.new("unexpected store type (#{type}), must be one of: :memory, :temporary or :persistent")
    end

    raise NanoStoreError, error_ptr[0].description if error_ptr[0]    
    store
  end
  
  def self.shared_store
    @shared_store
  end
  
  def self.shared_store=(store)
    @shared_store = store
  end

  # set debug mode
  # if YES, debug mode is on; otherwise debug mode is disabled.
  def self.debug=(debug)
    NSFSetIsDebugOn(debug)
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
nano-store-0.3.4 lib/nano_store/nano_store.rb
nano-store-0.3.3 lib/nano_store/nano_store.rb
nano-store-0.3.2 lib/nano_store/nano_store.rb
nano-store-0.3.1 lib/nano_store/nano_store.rb
nano-store-0.3.0 lib/nano_store/nano_store.rb
nano-store-0.2.4 lib/nano_store/nano_store.rb
nano-store-0.2.3 lib/nano_store/nano_store.rb