Permalink
Browse files

Make it a gem

  • Loading branch information...
siuying committed May 22, 2012
1 parent 00b372c commit ab7922ad7d76ede578c84b4203f48fec22e69980
Showing with 66 additions and 46 deletions.
  1. +4 −0 Gemfile
  2. +1 −13 Rakefile
  3. +1 −0 lib/nano-store.rb
  4. +7 −32 lib/nano_store.rb
  5. +36 −0 lib/nano_store/nano_store.rb
  6. +1 −1 lib/nano_store/version.rb
  7. +16 −0 nano-store.gemspec
View
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in gemspec
+gemspec
View
@@ -1,13 +1 @@
-$:.unshift("/Library/RubyMotion/lib")
-require 'motion/project'
-require 'motion-cocoapods'
-
-Motion::Project::App.setup do |app|
- app.name = 'NanoStoreDemo'
-
- app.files = Dir.glob(File.join(app.project_dir, 'vendor/BubbleWrap/lib/**/*.rb')) + app.files
- app.files = Dir.glob(File.join(app.project_dir, 'vendor/NanoStoreInMotion/lib/**/*.rb')) + app.files
- app.pods do
- dependency 'NanoStore'
- end
-end
+require "bundler/gem_tasks"
View
@@ -0,0 +1 @@
+require "nano_store"
View
@@ -1,36 +1,11 @@
-module NanoStore
- class NanoStoreError < StandardError; end
+require "nano_store/version"
- def self.store(type=:memory, path=nil)
- error_ptr = Pointer.new(:id)
+unless defined?(Motion::Project::Config)
+ raise "This file must be required within a RubyMotion project Rakefile."
+end
- 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
+Motion::Project::App.setup do |app|
+ Dir.glob(File.join(File.dirname(__FILE__), 'nano_store/*.rb')).each do |file|
+ app.files.unshift(file)
end
-
- # set debug mode
- # if YES, debug mode is on; otherwise debug mode is disabled.
- def self.debug=(debug)
- NSFSetIsDebugOn(debug)
- end
-
end
@@ -0,0 +1,36 @@
+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
@@ -1,3 +1,3 @@
module NanoStore
- VERSION = "0.2.2"
+ VERSION = "0.2.3"
end
View
@@ -0,0 +1,16 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/nano_store/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Francis Chong"]
+ gem.email = ["francis@ignition.hk"]
+ gem.description = "Wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite, for RubyMotion."
+ gem.summary = "Wrapper for NanoStore, a lightweight schema-less key-value document database based on sqlite, for RubyMotion."
+ gem.homepage = "https://github.com/siuying/NanoStoreInMotion"
+
+ gem.files = `git ls-files`.split($\)
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "nano-store"
+ gem.require_paths = ["lib"]
+ gem.version = NanoStore::VERSION
+end

0 comments on commit ab7922a

Please sign in to comment.