swiss_db 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a0d5dfe97a03004a6badf4904bd5aaa8862a1db
4
- data.tar.gz: 9316b9e0707c88275778f903e45e20fa9b553fff
3
+ metadata.gz: 04dcca30855e79f7effe25280491f5ff88a60f05
4
+ data.tar.gz: 9d5aa72a3fb8b0b96acf70993143399a08d8313d
5
5
  SHA512:
6
- metadata.gz: c7a647c5a48c059f5ee9bbf40c1741c65a5c2ee0da617cbb70f786e6481da0e850f5c226c5cbaef54ba20a8ca993e87df32f6b2ea8005d6cb94a4a4c073cb28a
7
- data.tar.gz: d4523e7006c165cd516c9dde90d547b88e0f8e2bce5a896b1c2d680dbe35a1c233fd15259ad144b2174cd52d151ae41c25558034ae8d116e7c7c172818b4c699
6
+ metadata.gz: 51423f441488fdfc031ce13f4523cc4d7f1b6f1e4607ea657b3d045f5fe170f54447227942f65c680957ae597cffd137e93d603a9bcca0a4d4b437617779d54d
7
+ data.tar.gz: 905a859a27dbfa725f6ceeb948c84744cf02e0a81e822b91754d33228290669da30525dced774963439bbb80a54c433fc679cae922866d30108c92a94c5db4b6
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![endorse](https://api.coderwall.com/jsilverMDX/endorsecount.png)](https://coderwall.com/jsilverMDX)
2
+
1
3
  # SwissDb
2
4
 
3
5
  RubyMotion Android ActiveRecord-like ORM for SQLite
@@ -23,7 +23,7 @@ module MotionSupport
23
23
  @__instance__ ||= new
24
24
  end
25
25
 
26
- # attr_reader :plurals, :singulars, :uncountables, :humans, :acronyms, :acronym_regex
26
+ attr_accessor :plurals, :singulars, :uncountables, :humans, :acronyms, :acronym_regex
27
27
 
28
28
  def initialize
29
29
  @plurals, @singulars, @uncountables, @humans, @acronyms, @acronym_regex = [], [], [], [], {}, /(?=a)b/
@@ -214,7 +214,7 @@ module MotionSupport
214
214
  # MotionSupport::Inflector.inflections do |inflect|
215
215
  # inflect.uncountable 'rails'
216
216
  # end
217
- def inflections
217
+ def inflections(&block)
218
218
  if block_given?
219
219
  yield Inflections.instance
220
220
  else
@@ -3,7 +3,22 @@
3
3
  # Convenience methods over the standard cursor
4
4
  # Used by Swiss DataStore
5
5
 
6
- class Cursor
6
+ class CursorModel
7
+
8
+ def initialize(h)
9
+ h.each do |k,v|
10
+ instance_variable_set("@#{k}", v)
11
+ end
12
+ end
13
+
14
+ def method_missing(methId, *args)
15
+ str = methId.id2name
16
+ instance_variable_get("@#{str}")
17
+ end
18
+
19
+ end
20
+
21
+ class Cursor # < Array
7
22
 
8
23
  FIELD_TYPE_BLOB = 4
9
24
  FIELD_TYPE_FLOAT = 2
@@ -31,6 +46,20 @@ class Cursor
31
46
  cursor.moveToPosition(pos) ? self : nil
32
47
  end
33
48
 
49
+ def to_a
50
+ arr = []
51
+ (0...count).each do |i|
52
+ # puts i
53
+ hash_obj = {}
54
+ cursor.moveToPosition(i)
55
+ $current_schema[model.class_name].each do |k, v|
56
+ hash_obj[k.to_sym] = self.send(k.to_sym)
57
+ end
58
+ arr << CursorModel.new(hash_obj)
59
+ end
60
+ arr
61
+ end
62
+
34
63
  def count
35
64
  cursor.getCount
36
65
  end
data/lib/swiss_db/db.rb CHANGED
@@ -35,7 +35,8 @@ class Object
35
35
  @table_name = table_name
36
36
  @current_schema[@table_name] = {}
37
37
  block.call
38
- DataStore.current_schema = @current_schema # there was no other way. I couldn't get context to create the model here.
38
+ $current_schema = @current_schema
39
+ DataStore.current_schema = @current_schema
39
40
  end
40
41
 
41
42
  def add_column(name, type)
@@ -6,10 +6,10 @@ class SwissModel
6
6
  # meh? .. won't work for now in java... created classes become java packages
7
7
  # name will become the namespace of the package...
8
8
  # def self.inherited(subclass)
9
- # puts "New subclass: #{subclass.class.name.to_s}"
9
+ # puts "New subclass: #{subclass.class.name.split('.').last}"
10
10
  # end
11
11
 
12
- # attr_accessor :table_name
12
+ # attr_accessor :table_name, :class_name
13
13
 
14
14
  def self.store
15
15
  context = DataStore.context
@@ -17,7 +17,12 @@ class SwissModel
17
17
  @store
18
18
  end
19
19
 
20
+ def self.class_name
21
+ @class_name
22
+ end
23
+
20
24
  def self.set_class_name(class_name) # hack, class.name not functioning in RM Android...
25
+ @class_name = class_name
21
26
  set_table_name(class_name.tableize)
22
27
  end
23
28
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiss_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Silverman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2015-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler