Module: YAML

Defined in:
lib/core_ex/yaml.rb

Defined Under Namespace

Modules: BaseNode

Class Method Summary collapse

Class Method Details

.have_option?(opts, opt_name) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/core_ex/yaml.rb', line 39

def have_option? ( opts, opt_name )
  if opts.respond_to? :[]
    opts[opt_name] || have_option?(opts[:Emitter], opt_name)
  elsif opts.respond_to? :options
    have_option? opts.options, opt_name
  end
end

.load_from_io(io, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/core_ex/yaml.rb', line 19

def load_from_io io, &block
  buffer = []
  io.each_line do |line|
    if line == '...'
      unless buffer.empty?
        block[YAML.parse(buffer.join).symbol_safe_transform]
        buffer = []
      end
    elsif not buffer.empty? and line =~ /^---/
      block[YAML.parse(buffer.join).symbol_safe_transform]
      buffer = [line]
    else
      buffer << line
    end
  end
  if not buffer.empty?
    block[YAML.parse(buffer.join).symbol_safe_transform]
  end
end