Class: ExtendedYAML

Inherits:
Object
  • Object
show all
Defined in:
lib/extended_yaml.rb,
lib/extended_yaml/version.rb,
lib/extended_yaml/deep_merge.rb

Defined Under Namespace

Modules: DeepMerge

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, key: 'extends') ⇒ ExtendedYAML

Returns a new instance of ExtendedYAML.



16
17
18
# File 'lib/extended_yaml.rb', line 16

def initialize(file, key: 'extends')
  @file, @key = file, key
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/extended_yaml.rb', line 7

def file
  @file
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/extended_yaml.rb', line 7

def key
  @key
end

Class Method Details

.load(file, key: 'extends') ⇒ Hash, Array

Returns the parsed YAML.

Parameters:

  • file (String)

    path to YAML file

  • key (String) (defaults to: 'extends')

    YAML key to use for loading files

Returns:

  • (Hash, Array)

    the parsed YAML



12
13
14
# File 'lib/extended_yaml.rb', line 12

def self.load(file, key: 'extends')
  new(file, key: key).result
end

Instance Method Details

#evaluateString

Returns the YAML string, with evaluated and ERB.

Returns:

  • (String)

    the YAML string, with evaluated and ERB



27
28
29
# File 'lib/extended_yaml.rb', line 27

def evaluate
  ERB.new(File.read file).result
end

#resultHash, Array

Returns the parsed YAML.

Returns:

  • (Hash, Array)

    the parsed YAML



21
22
23
24
# File 'lib/extended_yaml.rb', line 21

def result
  data = ::YAML.load evaluate
  resolve_extends data
end