Class: RVGP::Utilities::Yaml::PsychInclude

Inherits:
Object
  • Object
show all
Defined in:
lib/rvgp/utilities/yaml.rb

Overview

This class is needed, in order to capture the dependencies needed to properly preserve uptodate status in rake builds

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PsychInclude

Declare a proc, given the provided proc_as_string code

Parameters:

  • path (String)

    A relative or absolute path, to include, in the place of this line



24
25
26
# File 'lib/rvgp/utilities/yaml.rb', line 24

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/rvgp/utilities/yaml.rb', line 20

def path
  @path
end

Instance Method Details

#contents(include_paths) ⇒ Hash

The contents of this include target.

Parameters:

  • include_paths (Array<String>)

    A relative or absolute path, to include, in case our path is relative and we need to load it from a relative location. These paths are scanned for the include, in the relative order of their place in the array.

Returns:

  • (Hash)

    The contents of the target of this include. Keys are symbolized, and permitted_classes include Date, and Symbol



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rvgp/utilities/yaml.rb', line 35

def contents(include_paths)
  content_path = path if Pathname.new(path).absolute?
  content_path ||= include_paths.map { |p| [p.chomp('/'), path].join('/') }.find do |p|
    File.readable? p
  end

  unless content_path
    raise StandardError, format('Unable to find %<path>s in any of the provided paths: %<paths>s',
                                path: path.inspect, paths: include_paths.inspect)
  end

  Psych.safe_load_file content_path, symbolize_names: true, permitted_classes: [Date, Symbol]
end