Sha256: 23195318f916968b7cc30da2edfab9fa2a5d26d9dc006ad77da31b1dd3701cb7

Contents?: true

Size: 914 Bytes

Versions: 17

Compression:

Stored size: 914 Bytes

Contents

# These extensions allow properly serializing and autoloading of
# Classes, Modules and Structs

require 'yaml'

class Module
  yaml_as "tag:ruby.yaml.org,2002:module"

  def self.yaml_new(klass, tag, val)
    val.constantize
  end

  def to_yaml( opts = {} )
    YAML::quick_emit( nil, opts ) { |out|
      out.scalar(taguri, self.name, :plain)
    }
  end
  
  def yaml_tag_read_class(name)
    # Constantize the object so that ActiveSupport can attempt
    # its auto loading magic. Will raise LoadError if not successful.
    name.constantize
    name
  end
  
end

class Class
  yaml_as "tag:ruby.yaml.org,2002:class"
  remove_method :to_yaml # use Module's to_yaml
end

class Struct
  def self.yaml_tag_read_class(name)
    # Constantize the object so that ActiveSupport can attempt
    # its auto loading magic. Will raise LoadError if not successful.
    name.constantize
    "Struct::#{ name }"
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
topprospect-delayed_job-2.0.9 lib/delayed/yaml_ext.rb
topprospect-delayed_job-2.0.8 lib/delayed/yaml_ext.rb
topprospect-delayed_job-2.0.7 lib/delayed/yaml_ext.rb
topprospect-delayed_job-2.0.6 lib/delayed/yaml_ext.rb
topprospect-delayed_job-2.0.5 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.9 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.8 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.6 lib/delayed/yaml_ext.rb
delayed_job-2.1.3 lib/delayed/yaml_ext.rb
delayed_job-2.1.2 lib/delayed/yaml_ext.rb
delayed_job-2.1.1 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.5 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.4 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.3 lib/delayed/yaml_ext.rb
blaxter-delayed_job-2.1.2 lib/delayed/yaml_ext.rb
delayed_job-2.1.0.pre2 lib/delayed/yaml_ext.rb
delayed_job-2.1.0.pre lib/delayed/yaml_ext.rb