Sha256: 3c3c26dd9c0e327ef254950c63f92ac160cb5d63b9c309484ae752514ca92df4

Contents?: true

Size: 1.46 KB

Versions: 22

Compression:

Stored size: 1.46 KB

Contents

motion_require '../config/base.rb'
module MotionPrime
  class Store
    def self.create(type = nil, path = nil)
      error_ptr = Pointer.new(:id)
      case type || MotionPrime::Config.model.store_type.to_sym
      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
        path ||= begin
          documents_path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
          documents_path + "/nano.db"
        end
        store = NSFNanoStore.createAndOpenStoreWithType(NSFPersistentStoreType, path: path, error: error_ptr)
      else
        raise StoreError.new("unexpected store type (#{type}), must be one of: :memory, :temporary or :persistent")
      end

      raise StoreError, error_ptr[0].description if error_ptr[0]
      store
    end

    def self.connect!(type = nil)
      self.shared_store = create(type)
    end

    def self.connect(type = nil)
      connect!(type) unless connected?
    end

    def self.connected?
      !!shared_store
    end

    def self.disconnect
      self.shared_store = nil
    end

    def self.shared_store
      @shared_store
    end

    def self.shared_store=(store)
      @shared_store = store
    end

    def self.debug=(debug)
      NSFSetIsDebugOn(debug)
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
motion-prime-0.5.2 motion-prime/models/store.rb
motion-prime-0.5.1 motion-prime/models/store.rb
motion-prime-0.5.0 motion-prime/models/store.rb
motion-prime-0.4.5 motion-prime/models/store.rb
motion-prime-0.4.4 motion-prime/models/store.rb
motion-prime-0.4.3 motion-prime/models/store.rb
motion-prime-0.4.2 motion-prime/models/store.rb
motion-prime-0.4.1 motion-prime/models/store.rb
motion-prime-0.4.0 motion-prime/models/store.rb
motion-prime-0.3.3 motion-prime/models/store.rb
motion-prime-0.3.2 motion-prime/models/store.rb
motion-prime-0.3.1 motion-prime/models/store.rb
motion-prime-0.3.0 motion-prime/models/store.rb
motion-prime-0.2.1 motion-prime/models/store.rb
motion-prime-0.2.0 motion-prime/models/store.rb
motion-prime-0.1.7 motion-prime/models/store.rb
motion-prime-0.1.6 motion-prime/models/store.rb
motion-prime-0.1.5 motion-prime/models/store.rb
motion-prime-0.1.4 motion-prime/models/store.rb
motion-prime-0.1.3 motion-prime/models/store.rb