nakor 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +7 -0
- data/lib/nakor/generators/corona-game-template/scripts/lib/active_record.lua +22 -10
- data/lib/nakor/generators/corona-game-template/scripts/lib/orm.lua +5 -1
- data/lib/nakor/generators/corona-game-template/scripts/lib/table_ext.lua +32 -0
- data/lib/nakor/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -19,6 +19,13 @@ This will create the awesome_app directory in the current directory. To run it i
|
|
19
19
|
|
20
20
|
/Applications/CoronaSDK/simulator awesome_app
|
21
21
|
|
22
|
+
# Development
|
23
|
+
|
24
|
+
To release a new version:
|
25
|
+
|
26
|
+
gem bump
|
27
|
+
gem release
|
28
|
+
|
22
29
|
# Credits
|
23
30
|
|
24
31
|
This code is MIT licensed, see http://developer.coronalabs.com/code/license
|
@@ -79,12 +79,15 @@ end
|
|
79
79
|
------------------------------------------------------------------------------
|
80
80
|
-- Returns all rows in the table that match the given filter
|
81
81
|
------------------------------------------------------------------------------
|
82
|
-
function ActiveRecord.static:findAll(
|
82
|
+
function ActiveRecord.static:findAll( klass, params )
|
83
83
|
local result = nil
|
84
|
-
if
|
85
|
-
|
84
|
+
if params == nil then
|
85
|
+
params = {}
|
86
|
+
end
|
87
|
+
if params.where == nil then
|
88
|
+
result = orm.selectAll( klass.tableName, params )
|
86
89
|
else
|
87
|
-
result = orm.selectWhere(
|
90
|
+
result = orm.selectWhere( klass.tableName, params )
|
88
91
|
end
|
89
92
|
return result
|
90
93
|
end
|
@@ -92,11 +95,11 @@ end
|
|
92
95
|
------------------------------------------------------------------------------
|
93
96
|
-- Updates all rows in the table that match the given filter
|
94
97
|
------------------------------------------------------------------------------
|
95
|
-
function ActiveRecord.static:updateAll( updateSql, filter )
|
98
|
+
function ActiveRecord.static:updateAll( klass, updateSql, filter )
|
96
99
|
if filter == nil then
|
97
|
-
orm.updateAll(
|
100
|
+
orm.updateAll( klass.tableName, updateSql )
|
98
101
|
else
|
99
|
-
orm.updateWhere(
|
102
|
+
orm.updateWhere( klass.tableName, updateSql, filter )
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
@@ -114,8 +117,10 @@ end
|
|
114
117
|
------------------------------------------------------------------------------
|
115
118
|
function ActiveRecord:reload()
|
116
119
|
local updatedRecord = orm.selectOne( self.class.tableName, 'id', self.id )
|
117
|
-
|
118
|
-
|
120
|
+
if updatedRecord ~= nil then
|
121
|
+
for k,v in pairs(updatedRecord) do
|
122
|
+
self[k] = v
|
123
|
+
end
|
119
124
|
end
|
120
125
|
end
|
121
126
|
|
@@ -144,7 +149,14 @@ end
|
|
144
149
|
-- Updates an array of columns
|
145
150
|
------------------------------------------------------------------------------
|
146
151
|
function ActiveRecord:updateAttributes( updateTable )
|
147
|
-
|
152
|
+
local filter = "id = " .. self.id
|
153
|
+
local columns = {}
|
154
|
+
local columnValues = {}
|
155
|
+
for k,v in pairs(updateTable) do
|
156
|
+
table.insert( columns, k )
|
157
|
+
table.insert( columnValues, v )
|
158
|
+
end
|
159
|
+
orm.updateAttributes( self.class.tableName, filter, columns, columnValues )
|
148
160
|
end
|
149
161
|
|
150
162
|
------------------------------------------------------------------------------
|
@@ -156,7 +156,11 @@ M.updateRow = updateRow
|
|
156
156
|
-- otherwise do an insert
|
157
157
|
------------------------------------------------------------------------------
|
158
158
|
local createOrUpdate = function( tableName, recordData )
|
159
|
-
local existingRecord =
|
159
|
+
local existingRecord = nil
|
160
|
+
if recordData.id ~= nil then
|
161
|
+
existingRecord = M.selectOne( tableName, 'id', recordData.id )
|
162
|
+
end
|
163
|
+
|
160
164
|
if existingRecord == nil then
|
161
165
|
M.insertRow( tableName, recordData )
|
162
166
|
else
|
@@ -1,5 +1,37 @@
|
|
1
1
|
local M = {}
|
2
2
|
|
3
|
+
------------------------------------------------------------------------------
|
4
|
+
-- Return the number of instances of a value in a list
|
5
|
+
-- Adapted from: http://snippets.luacode.org/?p=snippets/Count_Item_Occurances_in_Table_24
|
6
|
+
------------------------------------------------------------------------------
|
7
|
+
local itemCount = function(list, value)
|
8
|
+
local count = 0
|
9
|
+
for i,v in pairs(list) do
|
10
|
+
if v == value then count = count + 1 end
|
11
|
+
end
|
12
|
+
return count
|
13
|
+
end
|
14
|
+
M.itemCount = itemCount
|
15
|
+
|
16
|
+
------------------------------------------------------------------------------
|
17
|
+
-- Return true if the given list has duplicate entries for the given value
|
18
|
+
-- This is a modified version of itemCount,
|
19
|
+
-- optimized for checking for duplicates
|
20
|
+
------------------------------------------------------------------------------
|
21
|
+
local hasDuplicateValues = function(list, value)
|
22
|
+
local result = false
|
23
|
+
local count = 0
|
24
|
+
for i,v in pairs(list) do
|
25
|
+
if v == value then count = count + 1 end
|
26
|
+
if count > 1 then
|
27
|
+
result = true
|
28
|
+
break
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return result
|
32
|
+
end
|
33
|
+
M.hasDuplicateValues = hasDuplicateValues
|
34
|
+
|
3
35
|
------------------------------------------------------------------------------
|
4
36
|
-- Merge two tables
|
5
37
|
-- From: http://stackoverflow.com/questions/1283388/lua-merge-tables
|
data/lib/nakor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nakor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project: nakor
|
160
|
-
rubygems_version: 1.8.
|
160
|
+
rubygems_version: 1.8.23
|
161
161
|
signing_key:
|
162
162
|
specification_version: 3
|
163
163
|
summary: Nakor is a gem that encapsulates the corona-game-template project.
|