Module: ActiveRecordEncoding::ExtendedClassMethods
- Defined in:
- lib/active_record_encoding.rb
Overview
ExtendedClassMethods defines class methods for inclusion in models sub-classed from ActiveRecord::Base to do the dirty work. It is only included in models that use ActiveRecordEncoding.
Instance Method Summary collapse
-
#active_record_external_encoding(attr_name = nil) ⇒ Object
:nodoc:.
-
#active_record_internal_encoding(attr_name = nil) ⇒ Object
:nodoc:.
-
#encoding_aware_define_read_method(symbol, attr_name, column) ⇒ Object
Redefine the attribute read method to do the conversion.
Instance Method Details
#active_record_external_encoding(attr_name = nil) ⇒ Object
:nodoc:
160 161 162 163 |
# File 'lib/active_record_encoding.rb', line 160 def active_record_external_encoding (attr_name = nil) #:nodoc: @active_record_encodings[attr_name][:ext] || @active_record_external_encoding end |
#active_record_internal_encoding(attr_name = nil) ⇒ Object
:nodoc:
165 166 167 168 169 170 171 172 |
# File 'lib/active_record_encoding.rb', line 165 def active_record_internal_encoding (attr_name = nil) #:nodoc: @active_record_encodings[attr_name][:int] || @active_record_internal_encoding || ActiveRecordEncoding.internal_encoding || Encoding.default_internal || Encoding.default_external || 'UTF-8' end |
#encoding_aware_define_read_method(symbol, attr_name, column) ⇒ Object
Redefine the attribute read method to do the conversion.
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/active_record_encoding.rb', line 176 def encoding_aware_define_read_method (symbol, attr_name, column) #:nodoc: pre_encoding_aware_define_read_method(symbol, attr_name, column) return if active_record_external_encoding(attr_name).nil? method_name = "encoding_aware_attr_#{symbol}".to_sym old_method_name = "pre_#{method_name}".to_sym code = " encoding_aware_attribute_cast!(\#{attr_name.inspect}, \#{old_method_name})\n __EOM__\n evaluate_attribute_method attr_name, \"def \#{method_name}; \#{code}; end\"\n alias_method \"pre_\#{method_name}\".to_sym, symbol\n alias_method symbol, method_name\nend\n" |