Module: IMW::Formats::Yaml
- Includes:
- Enumerable
- Defined in:
- lib/imw/formats/yaml.rb
Overview
Provides methods for reading and writing YAML data.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Iterate over the elements in the YAML.
-
#emit(data, options = {}) ⇒ Object
Emit the
data
into this resource. -
#load(&block) ⇒ Hash, ...
Return the content of this resource.
Instance Method Details
#each(&block) ⇒ Object
Iterate over the elements in the YAML.
26 27 28 |
# File 'lib/imw/formats/yaml.rb', line 26 def each &block load(&block) end |
#emit(data, options = {}) ⇒ Object
Emit the data
into this resource. It must be opened for writing.
34 35 36 37 38 |
# File 'lib/imw/formats/yaml.rb', line 34 def emit data, ={} require 'yaml' write(data.to_yaml) self end |
#load(&block) ⇒ Hash, ...
Return the content of this resource.
Will pass a block to the outermost YAML data structure’s each method.
15 16 17 18 19 20 21 22 23 |
# File 'lib/imw/formats/yaml.rb', line 15 def load &block require 'yaml' yaml = YAML.load(io) if block_given? yaml.each(&block) else yaml end end |