Module: RapidYAML
- Defined in:
- lib/rapidyaml/version.rb,
lib/rapidyaml.rb
Overview
Version constant definition for rapidyaml gem
This file defines the VERSION constant for the RapidYAML module, which is used for gem versioning, dependency resolution, and runtime version checks. The version follows semantic versioning (SemVer) format and is referenced by the gemspec, bundler, and other parts of the gem infrastructure.
The version is kept in a separate file to allow easy programmatic access and updates during the release process without modifying the main module files.
Constant Summary collapse
- ParseError =
Error and SyntaxError are defined in the C extension (Init_rapidyaml). ParseError is kept as an alias for backward compatibility.
SyntaxError- DATE_RE =
Regex patterns for scalar coercion during load. Only applied when the corresponding class is in permitted_classes.
/\A(\d{4})-(\d{2})-(\d{2})\z/- DATETIME_RE =
/\A\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?: ?(?:Z|[+-]\d{2}:?\d{2}))?\z/- VERSION =
'0.1.3'
Class Method Summary collapse
-
.dump(obj) ⇒ String
Serializes a Ruby object to a YAML string.
-
.dump_file(obj, path) ⇒ void
Serializes a Ruby object to a YAML file.
-
.dump_stream(*objects) ⇒ String
Serializes multiple Ruby objects into a multi-document YAML stream.
-
.libyaml_version ⇒ String
Returns the version string of the bundled rapidyaml C++ library.
-
.load(yaml, symbolize_names: false, permitted_classes: []) ⇒ Object
Parses a YAML string and returns the corresponding Ruby object.
-
.load_file(path, symbolize_names: false, permitted_classes: []) ⇒ Object
Parses YAML from a file and returns the corresponding Ruby object.
-
.load_stream(yaml, symbolize_names: false, permitted_classes: []) {|Object| ... } ⇒ Array?
Parses all YAML documents in a string and yields each as a Ruby object.
-
.safe_dump(obj) ⇒ String
Equivalent to dump; rapidyaml does not serialize arbitrary Ruby objects, so there is no unsafe surface to restrict.
-
.safe_load(yaml, symbolize_names: false, permitted_classes: []) ⇒ Object
Alias matching Psych.safe_load; rapidyaml does not execute arbitrary code, so this is equivalent to load for all practical purposes.
- .safe_load_stream(yaml, symbolize_names: false, permitted_classes: [], &block) ⇒ Object
-
.unsafe_load(yaml, symbolize_names: false, permitted_classes: []) ⇒ Object
Alias matching Psych.unsafe_load; rapidyaml never executes arbitrary Ruby object tags, so this is equivalent to load.
-
.unsafe_load_file(path, symbolize_names: false, permitted_classes: []) ⇒ Object
Alias matching Psych.unsafe_load_file; rapidyaml never executes arbitrary Ruby object tags, so this is equivalent to load_file.
Class Method Details
.dump(obj) ⇒ String
Serializes a Ruby object to a YAML string.
74 75 76 |
# File 'lib/rapidyaml.rb', line 74 def dump(obj) Ext.emit(obj) end |
.dump_file(obj, path) ⇒ void
This method returns an undefined value.
Serializes a Ruby object to a YAML file.
174 175 176 |
# File 'lib/rapidyaml.rb', line 174 def dump_file(obj, path) File.write(path, dump(obj)) end |
.dump_stream(*objects) ⇒ String
Serializes multiple Ruby objects into a multi-document YAML stream.
83 84 85 86 87 88 |
# File 'lib/rapidyaml.rb', line 83 def dump_stream(*objects) objects.map do |obj| s = dump(obj) obj.is_a?(Hash) || obj.is_a?(Array) ? "---\n#{s}" : "--- #{s}" end.join end |
.libyaml_version ⇒ String
Returns the version string of the bundled rapidyaml C++ library. Psych exposes libyaml_version; this is the equivalent for rapidyaml.
103 104 105 |
# File 'lib/rapidyaml.rb', line 103 def libyaml_version Ext.ryml_version end |
.load(yaml, symbolize_names: false, permitted_classes: []) ⇒ Object
Parses a YAML string and returns the corresponding Ruby object.
51 52 53 54 55 |
# File 'lib/rapidyaml.rb', line 51 def load(yaml, symbolize_names: false, permitted_classes: []) result = Ext.parse(yaml) result = coerce_scalars(result, permitted_classes) unless permitted_classes.empty? symbolize_names ? deep_symbolize_keys(result) : result end |
.load_file(path, symbolize_names: false, permitted_classes: []) ⇒ Object
Parses YAML from a file and returns the corresponding Ruby object.
163 164 165 166 |
# File 'lib/rapidyaml.rb', line 163 def load_file(path, symbolize_names: false, permitted_classes: []) load(File.read(path), symbolize_names: symbolize_names, permitted_classes: permitted_classes) end |
.load_stream(yaml, symbolize_names: false, permitted_classes: []) {|Object| ... } ⇒ Array?
Parses all YAML documents in a string and yields each as a Ruby object. If no block given, returns an array of all documents.
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/rapidyaml.rb', line 115 def load_stream(yaml, symbolize_names: false, permitted_classes: [], &block) docs = Ext.parse_stream(yaml) docs = docs.map { |d| coerce_scalars(d, permitted_classes) } unless permitted_classes.empty? docs = docs.map { |d| deep_symbolize_keys(d) } if symbolize_names if block docs.each(&block) nil else docs end end |
.safe_dump(obj) ⇒ String
Equivalent to dump; rapidyaml does not serialize arbitrary Ruby objects, so there is no unsafe surface to restrict.
95 96 97 |
# File 'lib/rapidyaml.rb', line 95 def safe_dump(obj) dump(obj) end |
.safe_load(yaml, symbolize_names: false, permitted_classes: []) ⇒ Object
Alias matching Psych.safe_load; rapidyaml does not execute arbitrary code, so this is equivalent to load for all practical purposes.
65 66 67 |
# File 'lib/rapidyaml.rb', line 65 def safe_load(yaml, symbolize_names: false, permitted_classes: []) load(yaml, symbolize_names: symbolize_names, permitted_classes: permitted_classes) end |
.safe_load_stream(yaml, symbolize_names: false, permitted_classes: [], &block) ⇒ Object
128 129 130 131 |
# File 'lib/rapidyaml.rb', line 128 def safe_load_stream(yaml, symbolize_names: false, permitted_classes: [], &block) load_stream(yaml, symbolize_names: symbolize_names, permitted_classes: permitted_classes, &block) end |
.unsafe_load(yaml, symbolize_names: false, permitted_classes: []) ⇒ Object
Alias matching Psych.unsafe_load; rapidyaml never executes arbitrary Ruby object tags, so this is equivalent to load.
140 141 142 |
# File 'lib/rapidyaml.rb', line 140 def unsafe_load(yaml, symbolize_names: false, permitted_classes: []) load(yaml, symbolize_names: symbolize_names, permitted_classes: permitted_classes) end |
.unsafe_load_file(path, symbolize_names: false, permitted_classes: []) ⇒ Object
Alias matching Psych.unsafe_load_file; rapidyaml never executes arbitrary Ruby object tags, so this is equivalent to load_file.
151 152 153 |
# File 'lib/rapidyaml.rb', line 151 def unsafe_load_file(path, symbolize_names: false, permitted_classes: []) load_file(path, symbolize_names: symbolize_names, permitted_classes: permitted_classes) end |