File: legacy_yaml_adapter.rb

package info (click to toggle)
rails 2%3A4.2.7.1-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 23,416 kB
  • sloc: ruby: 186,673; yacc: 45; sql: 43; sh: 14; makefile: 12
file content (30 lines) | stat: -rw-r--r-- 714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module ActiveRecord
  module LegacyYamlAdapter
    def self.convert(klass, coder)
      return coder unless coder.is_a?(Psych::Coder)

      case coder["active_record_yaml_version"]
      when 0 then coder
      else
        if coder["attributes"].is_a?(AttributeSet)
          coder
        else
          Rails41.convert(klass, coder)
        end
      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