Sha256: 1e5aa20b1b3c4c881666b6180e66ff165491553ba6dd4e89e46b83719d01976f

Contents?: true

Size: 700 Bytes

Versions: 8

Compression:

Stored size: 700 Bytes

Contents

require 'yaml'
require 'dm-core'

module DataMapper
  class Property
    class Yaml < Text
      def custom?
        true
      end

      def load(value)
        if value.nil?
          nil
        elsif value.is_a?(::String)
          ::YAML.load(value)
        else
          raise ArgumentError.new("+value+ of a property of YAML type must be nil or a String")
        end
      end

      def dump(value)
        if value.nil?
          nil
        elsif value.is_a?(::String) && value =~ /^---/
          value
        else
          ::YAML.dump(value)
        end
      end

      def typecast(value)
        value
      end
    end # class Yaml
  end # class Property
end # module DataMapper

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dm-types-1.1.0.rc2 lib/dm-types/yaml.rb
dm-types-1.1.0.rc1 lib/dm-types/yaml.rb
dm-types-1.0.2 lib/dm-types/yaml.rb
dm-types-1.0.1 lib/dm-types/yaml.rb
dm-types-1.0.0 lib/dm-types/yaml.rb
dm-types-1.0.0.rc3 lib/dm-types/yaml.rb
dm-types-1.0.0.rc2 lib/dm-types/yaml.rb
dm-types-1.0.0.rc1 lib/dm-types/yaml.rb