Sha256: cbd655bb2ed2d27315d15707acfe7b25e41b2419988c915d13e8d180b03cb27c

Contents?: true

Size: 1.16 KB

Versions: 35

Compression:

Stored size: 1.16 KB

Contents

module ActiveRecord
  module LegacyYamlAdapter
    def self.convert(klass, coder)
      return coder unless coder.is_a?(Psych::Coder)

      case coder["active_record_yaml_version"]
      when 1 then coder
      else
        if coder["attributes"].is_a?(AttributeSet)
          Rails420.convert(klass, coder)
        else
          Rails41.convert(klass, coder)
        end
      end
    end

    module Rails420
      def self.convert(klass, coder)
        attribute_set = coder["attributes"]

        klass.attribute_names.each do |attr_name|
          attribute = attribute_set[attr_name]
          if attribute.type.is_a?(Delegator)
            type_from_klass = klass.type_for_attribute(attr_name)
            attribute_set[attr_name] = attribute.with_type(type_from_klass)
          end
        end

        coder
      end
    end

    module Rails41
      def self.convert(klass, coder)
        attributes = klass.attributes_builder
          .build_from_database(coder["attributes"])
        new_record = coder["attributes"][klass.primary_key].blank?

        {
          "attributes" => attributes,
          "new_record" => new_record,
        }
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.7.1 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.7 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.6 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.6.rc1 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.5 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.5.rc2 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.5.rc1 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.4 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.4.rc1 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.3 lib/active_record/legacy_yaml_adapter.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.2 lib/active_record/legacy_yaml_adapter.rb
activerecord-5.0.2.rc1 lib/active_record/legacy_yaml_adapter.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/legacy_yaml_adapter.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/legacy_yaml_adapter.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/legacy_yaml_adapter.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/legacy_yaml_adapter.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/legacy_yaml_adapter.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/legacy_yaml_adapter.rb