slim_scrooge 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -20,6 +20,8 @@ In future releases I expect further gains.
20
20
 
21
21
  h2. Installation
22
22
 
23
+ Requirements: Rails 2.2 or above, Ruby 1.8.6 or above. (Ruby 1.9 to be tested)
24
+
23
25
  <pre>
24
26
  # if you haven't already, add gemcutter to your gem sources
25
27
  sudo gem install gemcutter
@@ -70,7 +72,7 @@ h2. Caveats
70
72
 
71
73
  It is possible to delete an object and then to try to use its attributes to access another object that perhaps must be also deleted (like the option :dependent=>:destroy in Rails associations).
72
74
 
73
- SlimScrooge particularly checks for columns used by :dependent=>:destroy, but if you are doing something similar manually in your code then you may run into problems. Your attempt to access the key of the dependent object could cause a reload if the column is not already noted by SlimScrooge, and the reload will fail if you have already destroyed the parent object.
75
+ This situation is likely to be found rarely because SlimScrooge particularly checks for columns used by :dependent=>:destroy, but if you are doing something similar manually in your code then you may run into problems. Your attempt to access the key of the dependent object could cause a reload if the column is not already noted by SlimScrooge, and the reload will fail if you have already destroyed the parent object.
74
76
 
75
77
  h2. Tests
76
78
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
+ :patch: 2
2
3
  :major: 1
3
4
  :minor: 0
4
- :patch: 1
5
5
  :build:
@@ -43,6 +43,7 @@ module SlimScrooge
43
43
  @model_class = model_class
44
44
  @quoted_table_name = model_class.quoted_table_name
45
45
  @primary_key = model_class.primary_key
46
+ @quoted_primary_key = model_class.connection.quote_column_name(@primary_key)
46
47
  @columns_hash = model_class.columns_hash
47
48
  @select_regexp = self.class.select_regexp(model_class.table_name)
48
49
  @seen_columns = SimpleSet.new(essential_columns)
@@ -51,7 +52,7 @@ module SlimScrooge
51
52
  # List of columns that should always be fetched no matter what
52
53
  #
53
54
  def essential_columns
54
- @model_class.reflect_on_all_associations.inject([@model_class.primary_key]) do |arr, assoc|
55
+ @model_class.reflect_on_all_associations.inject([@primary_key]) do |arr, assoc|
55
56
  if assoc.options[:dependent] && assoc.macro == :belongs_to
56
57
  arr << assoc.association_foreign_key
57
58
  end
@@ -77,7 +78,7 @@ module SlimScrooge
77
78
  def reload_sql(primary_keys, fetched_columns)
78
79
  sql_keys = primary_keys.collect{|pk| "'#{pk}'"}.join(ScroogeComma)
79
80
  cols = scrooge_select_sql(missing_columns(fetched_columns))
80
- "SELECT #{cols} FROM #{@quoted_table_name} WHERE #{@quoted_table_name}.#{@primary_key} IN (#{sql_keys})"
81
+ "SELECT #{cols} FROM #{@quoted_table_name} WHERE #{@quoted_primary_key} IN (#{sql_keys})"
81
82
  end
82
83
 
83
84
  # Change a set of columns into a correctly quoted comma separated list
@@ -24,7 +24,7 @@ module SlimScrooge
24
24
  # together with the callsite_hash generated by callsite_hash.c
25
25
  #
26
26
  def callsite_key(callsite_hash, sql)
27
- callsite_hash + sql.gsub(/WHERE.*/i, "").hash
27
+ callsite_hash + sql.gsub(/\sWHERE.*/i, "").hash
28
28
  end
29
29
 
30
30
  # Create a new callsite
@@ -68,6 +68,12 @@ module SlimScrooge
68
68
  @monitored_columns.merge(self)
69
69
  end
70
70
 
71
+ def freeze
72
+ @result_set.reload! if @result_set
73
+ @monitored_columns.freeze
74
+ super
75
+ end
76
+
71
77
  # Marshal
72
78
  # Dump a real hash - can't dump a monitored hash due to default proc
73
79
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_scrooge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-07 00:00:00 +02:00
12
+ date: 2009-11-23 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15