Module: Yew::Utils

Defined in:
lib/yew.rb

Class Method Summary collapse

Class Method Details

.fetch(key, env, root) ⇒ Yew::Tree, Object

Fetches the key’s value.

Returns a tree if the value is a hash. Otherwise it returns the raw value.

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/yew.rb', line 76

def self.fetch(key, env, root)
  value = raw_fetch(key, env, root)

  if value.is_a?(Hash)
    path = key
    path = "#{root}.#{path}" if root

    Tree.new(value, path)
  else
    value
  end
end

.raw_fetch(key, env, root) ⇒ Object

Fetches a value from the env.

Raises:

  • (RuntimeError)

    When key not found.



92
93
94
95
96
97
98
# File 'lib/yew.rb', line 92

def self.raw_fetch(key, env, root)
  env.fetch(key) do
    env.fetch(key.to_s) do
      raise "Attribute #{key} not found at /#{root}"
    end
  end
end