CachedSupermodel 0.1.2.5 → 0.1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/cs_active_record.rb +49 -4
  3. metadata +10 -7
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/cached_supermodel.rb'
6
6
 
7
- Hoe.new('CachedSupermodel', '0.1.2.5') do |p|
7
+ Hoe.new('CachedSupermodel', '0.1.2.7') do |p|
8
8
  p.summary = 'A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.'
9
9
  p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
10
10
  p.author = 'adocca Entertainment AB'
@@ -68,15 +68,60 @@ class ActiveRecord::Base
68
68
  class_eval "
69
69
  def self.#{finder}_get_ids(*args)
70
70
  match = '#{finder}'.match(/^find_(all_)?by_(.*)$/)
71
+ # flag for find / find_all
72
+ find_all = '#{finder}'.match(/^find_all_by/) ? true : false
71
73
  attributes = match[2].to_s.split(/_and_/)
72
74
  normal_arguments = args[0...attributes.size]
75
+ key_type = columns_hash[self.primary_key].type
76
+
73
77
  rest = args[attributes.size..-1]
74
78
  cache_value(['CachedSupermodel:' + self.name + ':#{finder}:' + normal_arguments.inspect, rest.inspect]) do
75
- rval = method_missing(:#{finder}, *args)
76
- if Array === rval
77
- rval.collect(&:id)
79
+ params = []
80
+ query = 'SELECT ' + self.primary_key.to_s + ' from ' + self.table_name
81
+ where = []
82
+ attributes.each_with_index do |a, i|
83
+ where << a + ' = ?'
84
+ params << args[i]
85
+ end
86
+
87
+ query << (' WHERE ' + where.join(' AND '))
88
+
89
+ if rest.include?(:order)
90
+ query << ' ORDER BY ?'
91
+ params << rest[:order]
92
+ end
93
+
94
+ if find_all
95
+ if rest.include?(:limit)
96
+ query << ' LIMIT ?'
97
+ params << rest[:limit]
98
+ end
99
+ else
100
+ query << ' LIMIT 1'
101
+ end
102
+
103
+ if rest.include?(:offset)
104
+ query << ' OFFSET ?'
105
+ params << rest[:offset]
106
+ end
107
+
108
+ rval = self.connection.select_all(self.sanitizeSQL([query, *params])).collect{ |row|
109
+ if key_type == :integer
110
+ row[self.primary_key.to_s].to_i
111
+ else
112
+ row[self.primary_key.to_s]
113
+ end
114
+ }.compact
115
+
116
+
117
+ if find_all
118
+ rval
78
119
  else
79
- rval.nil? ? nil : rval.id
120
+ if rval.blank?
121
+ nil
122
+ else
123
+ rval.first
124
+ end
80
125
  end
81
126
  end
82
127
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: CachedSupermodel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.2.5
7
- date: 2007-07-30 00:00:00 +02:00
6
+ version: 0.1.2.7
7
+ date: 2007-08-23 00:00:00 +02:00
8
8
  summary: A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.
9
9
  require_paths:
10
10
  - lib
@@ -40,10 +40,13 @@ files:
40
40
  - test/test_cached_supermodel.rb
41
41
  test_files:
42
42
  - test/test_cached_supermodel.rb
43
- rdoc_options: []
44
-
45
- extra_rdoc_files: []
46
-
43
+ rdoc_options:
44
+ - --main
45
+ - README.txt
46
+ extra_rdoc_files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.txt
47
50
  executables:
48
51
  - cached_supermodel
49
52
  extensions: []
@@ -67,5 +70,5 @@ dependencies:
67
70
  requirements:
68
71
  - - ">="
69
72
  - !ruby/object:Gem::Version
70
- version: 1.2.0
73
+ version: 1.2.2
71
74
  version: