cosine-active_record_encoding 0.9.4 → 0.9.5

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.
Files changed (2) hide show
  1. data/lib/active_record_encoding.rb +9 -10
  2. metadata +1 -1
@@ -75,7 +75,7 @@ module ActiveRecordEncoding::StandardClassMethods
75
75
 
76
76
  if attr_names = options[:for]
77
77
  [*attr_names].each do |attr_name|
78
- active_record_encodings[attr_name.to_s][:ext] = new_encoding
78
+ @active_record_encodings[attr_name.to_s][:ext] = new_encoding
79
79
  end
80
80
  else
81
81
  @active_record_external_encoding = new_encoding
@@ -106,7 +106,7 @@ module ActiveRecordEncoding::StandardClassMethods
106
106
 
107
107
  if attr_names = options[:for]
108
108
  [*attr_names].each do |attr_name|
109
- active_record_encodings[attr_name.to_s][:int] = new_encoding
109
+ @active_record_encodings[attr_name.to_s][:int] = new_encoding
110
110
  end
111
111
  else
112
112
  @active_record_internal_encoding = new_encoding
@@ -138,7 +138,7 @@ module ActiveRecordEncoding::StandardClassMethods
138
138
 
139
139
  if attr_names = options[:for]
140
140
  [*attr_names].each do |attr_name|
141
- active_record_encodings[attr_name.to_s] =
141
+ @active_record_encodings[attr_name.to_s] =
142
142
  { :ext => new_encoding, :int => new_encoding }
143
143
  end
144
144
  else
@@ -157,17 +157,13 @@ end # ActiveRecordEncoding::StandardClassMethods
157
157
  #
158
158
  module ActiveRecordEncoding::ExtendedClassMethods
159
159
 
160
- def active_record_encodings #:nodoc:
161
- @active_record_encodings ||= Hash.new { |h, k| h[k] = Hash.new }
162
- end
163
-
164
160
  def active_record_external_encoding (attr_name = nil) #:nodoc:
165
- active_record_encodings[attr_name][:ext] ||
161
+ @active_record_encodings[attr_name][:ext] ||
166
162
  @active_record_external_encoding
167
163
  end
168
164
 
169
165
  def active_record_internal_encoding (attr_name = nil) #:nodoc:
170
- active_record_encodings[attr_name][:int] ||
166
+ @active_record_encodings[attr_name][:int] ||
171
167
  @active_record_internal_encoding ||
172
168
  ActiveRecordEncoding.internal_encoding ||
173
169
  Encoding.default_internal ||
@@ -201,12 +197,15 @@ end # ActiveRecordEncoding::ExtendedClassMethods
201
197
  module ActiveRecordEncoding::IncludedInstanceMethods
202
198
 
203
199
  def self.included (model_class) #:nodoc:
200
+ return if model_class.instance_variable_get(:@active_record_encodings)
201
+
204
202
  class << model_class
205
203
  alias_method :pre_encoding_aware_define_read_method, :define_read_method
206
204
  alias_method :define_read_method, :encoding_aware_define_read_method
207
205
  end
208
206
 
209
207
  model_class.class_eval do
208
+ @active_record_encodings = Hash.new { |h, k| h[k] = Hash.new }
210
209
  alias_method :pre_encoding_aware_read_attribute, :read_attribute
211
210
  alias_method :read_attribute, :encoding_aware_read_attribute
212
211
  end
@@ -257,7 +256,7 @@ module ActiveRecordEncoding::IncludedInstanceMethods
257
256
  # We need to behave differently if called from
258
257
  # #attributes_with_quotes because that is how Rails knows what value
259
258
  # to write out. Doing it this way is an unfortunate kludge.
260
- rc = if caller.grep(/`attributes_with_quotes'$/).empty?
259
+ if caller.grep(/`attributes_with_quotes'$/).empty?
261
260
  pure_encoding_aware_read_attribute(attr_name)
262
261
  else
263
262
  encoding_aware_read_attribute_for_write(attr_name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cosine-active_record_encoding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael H. Buselli