Module: Syck
- Defined in:
- lib/syck/tag.rb,
lib/syck/syck.rb,
lib/syck/error.rb,
lib/syck/types.rb,
lib/syck/ypath.rb,
lib/syck/loader.rb,
lib/syck/stream.rb,
lib/syck/basenode.rb,
lib/syck/encoding.rb,
lib/syck/yamlnode.rb,
lib/syck/constants.rb,
lib/rubysl/syck/syck.rb,
lib/syck/baseemitter.rb
Overview
Constants used throughout the library
Defined Under Namespace
Modules: BaseEmitter, BaseNode Classes: DomainType, Error, Loader, Mapping, Node, Object, Omap, Pairs, ParseError, PrivateType, Sequence, Set, SpecialHash, Stream, TypeError, YPath, YamlNode
Constant Summary collapse
- ERROR_NO_HEADER_NODE =
Error messages
"With UseHeader=false, the node Array or Hash must have elements"
- ERROR_NEED_HEADER =
"With UseHeader=false, the node must be an Array or Hash"
- ERROR_BAD_EXPLICIT =
"Unsupported explicit transfer: '%s'"
- ERROR_MANY_EXPLICIT =
"More than one explicit transfer"
- ERROR_MANY_IMPLICIT =
"More than one implicit request"
- ERROR_NO_ANCHOR =
"No anchor for alias '%s'"
- ERROR_BAD_ANCHOR =
"Invalid anchor: %s"
- ERROR_MANY_ANCHOR =
"More than one anchor"
- ERROR_ANCHOR_ALIAS =
"Can't define both an anchor and an alias"
- ERROR_BAD_ALIAS =
"Invalid alias: %s"
- ERROR_MANY_ALIAS =
"More than one alias"
- ERROR_ZERO_INDENT =
"Can't use zero as an indentation width"
- ERROR_UNSUPPORTED_VERSION =
"This release of YAML.rb does not support YAML version %s"
- ERROR_UNSUPPORTED_ENCODING =
"Attempt to use unsupported encoding: %s"
- VERSION =
Constants
'0.60'
- SUPPORTED_YAML_VERSIONS =
['1.0']
- WORD_CHAR =
Parser tokens
'A-Za-z0-9'
- PRINTABLE_CHAR =
'-_A-Za-z0-9!?/()$\'". '
- NOT_PLAIN_CHAR =
'\x7f\x0-\x1f\x80-\x9f'
- ESCAPE_CHAR =
'[\\x00-\\x09\\x0b-\\x1f]'
- INDICATOR_CHAR =
'*&!|\\\\^@%{}[]='
- SPACE_INDICATORS =
'-#:,?'
- RESTRICTED_INDICATORS =
'#:,}]'
- DNS_COMP_RE =
"\\w(?:[-\\w]*\\w)?"
- DNS_NAME_RE =
"(?:(?:#{DNS_COMP_RE}\\.)+#{DNS_COMP_RE}|#{DNS_COMP_RE})"
- ESCAPES =
%w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a \x08 \t \n \v \f \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1a \e \x1c \x1d \x1e \x1f }
- UNESCAPES =
{ 'a' => "\x07", 'b' => "\x08", 't' => "\x09", 'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c", 'r' => "\x0d", 'e' => "\x1b", '\\' => '\\', }
- 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
-
.escape(value, skip = "") ⇒ Object
Escape the string, condensing common escapes.
-
.merge_i(ary, hsh) ⇒ Object
– For Rubinius, replaces the rb_iterate call to syck_merge_i.
-
.mktime(str) ⇒ Object
– For Rubinius, replaces rb_syck_mktime.
-
.set_ivars(hsh, obj) ⇒ Object
– For Rubinius, replaces the rb_iterate call to syck_set_ivars.
-
.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.
-
.unescape(value) ⇒ Object
Unescape the condenses escapes.
Class Method Details
.escape(value, skip = "") ⇒ Object
Escape the string, condensing common escapes
10 11 12 13 14 15 16 17 |
# File 'lib/syck/encoding.rb', line 10 def self.escape( value, skip = "" ) warn "#{caller[0]}: YAML.escape is deprecated" if $VERBOSE value.gsub( /\\/, "\\\\\\" ). gsub( /"/, "\\\"" ). gsub( /([\x00-\x1f])/ ) do skip[$&] || ESCAPES[ $&.unpack("C")[0] ] end end |
.merge_i(ary, hsh) ⇒ Object
– For Rubinius, replaces the rb_iterate call to syck_merge_i. ++
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubysl/syck/syck.rb', line 29 def self.merge_i(ary, hsh) ary.each do |entry| begin entry = Rubinius::Type.coerce_to entry, Hash, :to_hash hsh.update entry rescue # ignore coercion errors end end nil end |
.mktime(str) ⇒ Object
– For Rubinius, replaces rb_syck_mktime. ++
45 46 47 48 49 50 51 52 |
# File 'lib/rubysl/syck/syck.rb', line 45 def self.mktime(str) require "date" begin DateTime.parse(str).to_time rescue ArgumentError # nothing end end |
.set_ivars(hsh, obj) ⇒ Object
– For Rubinius, replaces the rb_iterate call to syck_set_ivars. ++
20 21 22 23 24 |
# File 'lib/rubysl/syck/syck.rb', line 20 def self.set_ivars(hsh, obj) hsh.each do |key, value| obj.instance_variable_set :"@#{key}", value end 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 YAML. 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 YAML 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
35 36 37 38 39 40 |
# File 'lib/syck/tag.rb', line 35 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
48 49 50 |
# File 'lib/syck/tag.rb', line 48 def self.tagged_classes @@tagged_classes end |
.unescape(value) ⇒ Object
Unescape the condenses escapes
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/syck/encoding.rb', line 22 def self.unescape( value ) warn "#{caller[0]}: YAML.unescape is deprecated" if $VERBOSE value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) { if $3 ["#$3".hex ].pack('U*') elsif $2 [$2].pack( "H2" ) else UNESCAPES[$1] end } end |