diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-12-11 12:40:22 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-12-11 12:40:22 +0000 |
commit | 9b98362cda013f85406ae8b26922264d382794dd (patch) | |
tree | 9842eeee02a1e2b571e0008b18c5a8b390256224 /activerecord/lib | |
parent | ea12819adf5d5fa1e8ae07789478e18db887cda1 (diff) | |
parent | 69387ce0169b95d3a170cfb1c66a7570b1746e37 (diff) | |
download | rails-9b98362cda013f85406ae8b26922264d382794dd.tar.gz rails-9b98362cda013f85406ae8b26922264d382794dd.tar.bz2 rails-9b98362cda013f85406ae8b26922264d382794dd.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/doc/guides/html/activerecord_validations_callbacks.html
railties/doc/guides/source/activerecord_validations_callbacks.txt
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record.rb | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 4 | ||||
-rwxr-xr-x | activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/dirty.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/serializers/xml_serializer.rb | 23 | ||||
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 2 |
7 files changed, 30 insertions, 19 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb index 348e5b94af..1aaf456c0f 100644 --- a/activerecord/lib/active_record.rb +++ b/activerecord/lib/active_record.rb @@ -37,6 +37,8 @@ module ActiveRecord [Base, DynamicFinderMatch, ConnectionAdapters::AbstractAdapter] end + autoload :VERSION, 'active_record/version' + autoload :ActiveRecordError, 'active_record/base' autoload :ConnectionNotEstablished, 'active_record/base' diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5ee74ac2d9..77e5129a6b 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1416,8 +1416,8 @@ module ActiveRecord #:nodoc: def benchmark(title, log_level = Logger::DEBUG, use_silence = true) if logger && logger.level <= log_level result = nil - seconds = Benchmark.realtime { result = use_silence ? silence { yield } : yield } - logger.add(log_level, "#{title} (#{'%.1f' % (seconds * 1000)}ms)") + ms = Benchmark.ms { result = use_silence ? silence { yield } : yield } + logger.add(log_level, '%s (%.1fms)' % [title, ms]) result else yield diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index cab77fc031..bfafcfb3ab 100755 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -160,9 +160,9 @@ module ActiveRecord @open_transactions -= 1 end - def log_info(sql, name, seconds) + def log_info(sql, name, ms) if @logger && @logger.debug? - name = "#{name.nil? ? "SQL" : name} (#{sprintf("%.1f", seconds * 1000)}ms)" + name = '%s (%.1fms)' % [name || 'SQL', ms] @logger.debug(format_log_entry(name, sql.squeeze(' '))) end end @@ -171,9 +171,9 @@ module ActiveRecord def log(sql, name) if block_given? result = nil - seconds = Benchmark.realtime { result = yield } - @runtime += seconds - log_info(sql, name, seconds) + ms = Benchmark.ms { result = yield } + @runtime += ms + log_info(sql, name, ms) result else log_info(sql, name, 0) diff --git a/activerecord/lib/active_record/dirty.rb b/activerecord/lib/active_record/dirty.rb index ae573799ae..a1760875ba 100644 --- a/activerecord/lib/active_record/dirty.rb +++ b/activerecord/lib/active_record/dirty.rb @@ -151,12 +151,12 @@ module ActiveRecord def field_changed?(attr, old, value) if column = column_for_attribute(attr) - if column.type == :integer && column.null && (old.nil? || old == 0) + if column.type == :integer && column.null && (old.nil? || old == 0) && value.blank? # For nullable integer columns, NULL gets stored in database for blank (i.e. '') values. # Hence we don't record it as a change if the value changes from nil to ''. # If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll # be typecast back to 0 (''.to_i => 0) - value = nil if value.blank? + value = nil else value = column.type_cast(value) end diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index d171b742f5..4749823b94 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -23,11 +23,12 @@ module ActiveRecord #:nodoc: # </topic> # # This behavior can be controlled with <tt>:only</tt>, <tt>:except</tt>, - # <tt>:skip_instruct</tt>, <tt>:skip_types</tt> and <tt>:dasherize</tt>. + # <tt>:skip_instruct</tt>, <tt>:skip_types</tt>, <tt>:dasherize</tt> and <tt>:camelize</tt> . # The <tt>:only</tt> and <tt>:except</tt> options are the same as for the # +attributes+ method. The default is to dasherize all column names, but you - # can disable this setting <tt>:dasherize</tt> to +false+. To not have the - # column type included in the XML output set <tt>:skip_types</tt> to +true+. + # can disable this setting <tt>:dasherize</tt> to +false+. Setting <tt>:camelize</tt> + # to +true+ will camelize all column names - this also overrides <tt>:dasherize</tt>. + # To not have the column type included in the XML output set <tt>:skip_types</tt> to +true+. # # For instance: # @@ -178,13 +179,22 @@ module ActiveRecord #:nodoc: def root root = (options[:root] || @record.class.to_s.underscore).to_s - dasherize? ? root.dasherize : root + reformat_name(root) end def dasherize? !options.has_key?(:dasherize) || options[:dasherize] end + def camelize? + options.has_key?(:camelize) && options[:camelize] + end + + def reformat_name(name) + name = name.camelize if camelize? + dasherize? ? name.dasherize : name + end + def serializable_attributes serializable_attribute_names.collect { |name| Attribute.new(name, @record) } end @@ -212,7 +222,7 @@ module ActiveRecord #:nodoc: def add_tag(attribute) builder.tag!( - dasherize? ? attribute.name.dasherize : attribute.name, + reformat_name(attribute.name), attribute.value.to_s, attribute.decorations(!options[:skip_types]) ) @@ -220,8 +230,7 @@ module ActiveRecord #:nodoc: def add_associations(association, records, opts) if records.is_a?(Enumerable) - tag = association.to_s - tag = tag.dasherize if dasherize? + tag = reformat_name(association.to_s) if records.empty? builder.tag!(tag, :type => :array) else diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 27b5aca18f..0a27ea980e 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -147,7 +147,7 @@ module ActiveRecord end def save_with_transactions! #:nodoc: - rollback_active_record_state! { transaction { save_without_transactions! } } + rollback_active_record_state! { self.class.transaction { save_without_transactions! } } end # Reset id and @new_record if the transaction rolls back. @@ -175,7 +175,7 @@ module ActiveRecord # instance. def with_transaction_returning_status(method, *args) status = nil - transaction do + self.class.transaction do status = send(method, *args) raise ActiveRecord::Rollback unless status end diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index b59393d678..617b3f440f 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -205,7 +205,7 @@ module ActiveRecord else #key = :"activerecord.att.#{@base.class.name.underscore.to_sym}.#{attr}" attr_name = @base.class.human_attribute_name(attr) - full_messages << attr_name + ' ' + message + full_messages << attr_name + I18n.t('activerecord.errors.format.separator', :default => ' ') + message end end end |