Module: JvYAML
- Defined in:
- lib/jvyaml/syck.rb,
lib/jvyaml.rb,
lib/jvyaml.rb
Overview
From yaml/types.rb
Defined Under Namespace
Modules: JvYAMLi, Syck Classes: Emitter, Error, Object, Omap, Pairs, PrivateType, Proxy, Set, Store, Stream, YPath
Constant Summary collapse
- DEFAULTS =
Default settings
{ :Indent => 2, :UseHeader => false, :UseVersion => false, :Version => '1.0', :SortKeys => false, :AnchorFormat => 'id%03d', :ExplicitTypes => false, :WidthType => 'absolute', :BestWidth => 80, :UseBlock => false, :UseFold => false, :Encoding => :None }
- @@tagged_classes =
A dictionary of taguris which map to Ruby classes.
{}
Class Method Summary collapse
- .add_domain_type(*args) ⇒ Object
- .emitter ⇒ Object
- .parse(obj) ⇒ Object
- .parse_documents(*args) ⇒ Object
- .parse_file(filepath) ⇒ Object
-
.quick_emit(oid, opts = {}, &e) ⇒ Object
Allocate an Emitter if needed.
-
.tag_class(tag, cls) ⇒ Object
Associates a taguri tag with a Ruby class cls.
-
.tagged_classes ⇒ Object
Returns the complete dictionary of taguris, paired with classes.
-
.tagurize(val) ⇒ Object
Convert a type_id to a taguri.
Class Method Details
.add_domain_type(*args) ⇒ Object
39 40 41 |
# File 'lib/jvyaml.rb', line 39 def self.add_domain_type(*args) warn "JvYAML::add_domain_type isn't supported in JvYAML" end |
.parse(obj) ⇒ Object
29 30 31 |
# File 'lib/jvyaml.rb', line 29 def self.parse(obj) ::JvYAML::JvYAMLi::Node::from_internal(::JvYAML::_parse_internal(obj)) || false end |
.parse_documents(*args) ⇒ Object
43 44 45 |
# File 'lib/jvyaml.rb', line 43 def self.parse_documents(*args) warn "JvYAML::parse_documents isn't supported in JvYAML" end |
.parse_file(filepath) ⇒ Object
33 34 35 36 37 |
# File 'lib/jvyaml.rb', line 33 def JvYAML.parse_file( filepath ) File.open( filepath ) do |f| parse( f ) end end |
.quick_emit(oid, opts = {}, &e) ⇒ Object
Allocate an Emitter if needed
103 104 105 106 107 108 109 110 111 |
# File 'lib/jvyaml.rb', line 103 def JvYAML.quick_emit( oid, opts = {}, &e ) out = if opts.is_a? JvYAML::Emitter opts else emitter.reset( opts ) end out.emit( oid, &e ) end |
.tag_class(tag, cls) ⇒ Object
Associates a taguri tag with a Ruby class cls. The taguri is used to give types to classes when loading JvYAML. Taguris are of the form:
tag:authorityName,date:specific
The authorityName
is a domain name or email address. The date
is the date the type was issued in YYYY or YYYY-MM or YYYY-MM-DD format. The specific
is a name for the type being added.
For example, built-in JvYAML types have ‘yaml.org’ as the authorityName
and ‘2002’ as the date
. The specific
is simply the name of the type:
tag:yaml.org,2002:int
tag:yaml.org,2002:float
tag:yaml.org,2002:timestamp
The domain must be owned by you on the date
declared. If you don’t own any domains on the date you declare the type, you can simply use an e-mail address.
tag:[email protected],2004:notes/personal
316 317 318 319 320 321 |
# File 'lib/jvyaml.rb', line 316 def self.tag_class( tag, cls ) if @@tagged_classes.has_key? tag warn "class #{ @@tagged_classes[tag] } held ownership of the #{ tag } tag" end @@tagged_classes[tag] = cls end |
.tagged_classes ⇒ Object
Returns the complete dictionary of taguris, paired with classes. The key for the dictionary is the full taguri. The value for each key is the class constant associated to that taguri.
JvYAML.tagged_classes["tag:yaml.org,2002:int"] => Integer
329 330 331 |
# File 'lib/jvyaml.rb', line 329 def self.tagged_classes @@tagged_classes end |
.tagurize(val) ⇒ Object
Convert a type_id to a taguri
277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/jvyaml.rb', line 277 def JvYAML.tagurize( val ) if /^tag:.*?:.*$/ =~ val.to_s val elsif /^(.*?)\/(.*)$/ =~ val.to_s "tag:#$1.yaml.org,2002:#$2" elsif val.kind_of?(Integer) val else "tag:yaml.org,2002:#{val}" end end |