Class: Module

Inherits:
Object show all
Defined in:
lib/syck/tag.rb

Instance Method Summary collapse

Instance Method Details

#syck_yaml_as(tag, sc = true) ⇒ Object Also known as: yaml_as

Adds a taguri tag to a class, used when dumping or loading the class in YAML. See YAML::tag_class for detailed information on typing and taguris.


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/syck/tag.rb', line 59

def syck_yaml_as( tag, sc = true )
    verbose, $VERBOSE = $VERBOSE, nil
    class_eval <<-"END", __FILE__, __LINE__+1
        attr_writer :taguri
        def taguri
            if respond_to? :to_yaml_type
                Syck.tagurize( to_yaml_type[1..-1] )
            else
                return @taguri if defined?(@taguri) and @taguri
                tag = #{ tag.dump }
                if self.class.yaml_tag_subclasses? and self.class != Syck.tagged_classes[tag]
                    tag = "\#{ tag }:\#{ self.class.yaml_tag_class_name }"
                end
                tag
            end
        end
        def self.yaml_tag_subclasses?; #{ sc ? 'true' : 'false' }; end
    END
    Syck.tag_class tag, self
ensure
    $VERBOSE = verbose
end

#yaml_tag_class_nameObject

Transforms the subclass name into a name suitable for display in a subclassed tag.


86
87
88
# File 'lib/syck/tag.rb', line 86

def yaml_tag_class_name
    self.name
end

#yaml_tag_read_class(name) ⇒ Object

Transforms the subclass name found in the tag into a Ruby constant name.


91
92
93
# File 'lib/syck/tag.rb', line 91

def yaml_tag_read_class( name )
    name
end