cowtech-rails 1.7.5.0 → 1.7.6.0
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/lib/cowtech/extensions.rb +33 -31
- data/lib/cowtech/version.rb +1 -1
- metadata +2 -2
data/lib/cowtech/extensions.rb
CHANGED
@@ -237,43 +237,45 @@ module Math
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
240
|
+
if defined?(ActiveRecord) then
|
241
|
+
class ActiveRecord::Base
|
242
|
+
def self.table_prefix
|
243
|
+
p = ActiveRecord::Base.configurations[Rails.env]["table_prefix"]
|
244
|
+
!p.blank? ? p + "_" : ""
|
245
|
+
end
|
245
246
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
247
|
+
def self.table_suffix
|
248
|
+
p = ActiveRecord::Base.configurations[Rails.env]["table_suffix"]
|
249
|
+
!p.blank? ? p + "_" : ""
|
250
|
+
end
|
250
251
|
|
251
|
-
|
252
|
-
|
253
|
-
|
252
|
+
def self.set_table_name(value = nil, &block)
|
253
|
+
define_attr_method :table_name, "#{ActiveRecord::Base.table_prefix}#{value}#{ActiveRecord::Base.table_suffix}", &block
|
254
|
+
end
|
254
255
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
256
|
+
def self.find_or_create(oid, attributes = nil)
|
257
|
+
begin
|
258
|
+
self.find(oid)
|
259
|
+
rescue ActiveRecord::RecordNotFound
|
260
|
+
self.new(attributes)
|
261
|
+
end
|
260
262
|
end
|
261
|
-
end
|
262
263
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
264
|
+
def self.safe_find(oid)
|
265
|
+
begin
|
266
|
+
rv = self.find(oid)
|
267
|
+
rescue ActiveRecord::RecordNotFound
|
268
|
+
nil
|
269
|
+
end
|
268
270
|
end
|
269
|
-
end
|
270
271
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
272
|
+
def self.random
|
273
|
+
c = self.count
|
274
|
+
c != 0 ? self.find(:first, :offset => rand(c)) : nil
|
275
|
+
end
|
275
276
|
|
276
|
-
|
277
|
-
|
277
|
+
def self.per_page
|
278
|
+
25
|
279
|
+
end
|
278
280
|
end
|
279
|
-
end
|
281
|
+
end
|
data/lib/cowtech/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cowtech-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.6.0
|
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: 2011-06-
|
12
|
+
date: 2011-06-30 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: A general purpose Rails utility plugin.
|
15
15
|
email: shogun_panda@me.com
|