webink 1.2.5 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -269,6 +269,13 @@ module Ink
269
269
  # [param controller:] Controller name string
270
270
  # [returns:] class or nil
271
271
  def self.verify(controller)
272
+ if not Module.const_defined? controller.capitalize
273
+ if File.exists? "./controllers/#{controller}.rb"
274
+ load "./controllers/#{controller}.rb"
275
+ else
276
+ raise NameError.new("Controller not found.")
277
+ end
278
+ end
272
279
  ((Module.const_get controller.capitalize).is_a? Class) ? (Module.const_get controller.capitalize) : (raise NameError.new("Controller not found."))
273
280
  end
274
281
 
@@ -192,14 +192,11 @@ module Ink
192
192
  #
193
193
  # Attempts to fetch the last inserted primary key
194
194
  # [returns:] primary key or nil
195
- def last_inserted_pk
196
- string = ""
197
- if @type == "mysql"
198
- string = "LAST_INSERT_ID()"
199
- elsif @type == "sqlite3"
200
- string = "last_insert_rowid()"
201
- end
202
- response = self.query "SELECT #{string} as id"
195
+ def last_inserted_pk(class_name)
196
+ table_name = Ink::Model.str_to_tablename(class_name)
197
+ pk_name = Ink::Model.classname(class_name).primary_key[0]
198
+ return if not (table_name and pk_name)
199
+ response = self.query("SELECT MAX(#{pk_name}) as id FROM #{table_name};")
203
200
  return (response.length > 0) ? response[0]["id"] : nil
204
201
  end
205
202
 
@@ -174,7 +174,7 @@ module Ink
174
174
  Ink::Database.database.query "UPDATE #{Ink::Model.str_to_tablename(self.class.name)} SET #{string * ","} #{pkvalue}"
175
175
  elsif response.length == 0
176
176
  Ink::Database.database.query "INSERT INTO #{Ink::Model.str_to_tablename(self.class.name)} (#{keystring * ","}) VALUES (#{valuestring * ","});"
177
- pk = Ink::Database.database.last_inserted_pk
177
+ pk = Ink::Database.database.last_inserted_pk(self.class.name)
178
178
  instance_variable_set "@#{self.class.primary_key[0]}", pk.is_a?(Numeric) ? pk : "\'#{pk}\'" if pk
179
179
  end
180
180
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: webink
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.5
5
+ version: 1.2.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthias Geier
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-21 00:00:00 Z
13
+ date: 2012-08-23 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fcgi