class Plant::Utils

Utilities for the library

Public Class Methods

load_all_yaml_files(dir = 'app/content') click to toggle source

Loads all the yaml files into memory

# File lib/plant/utils.rb, line 21
def self.load_all_yaml_files(dir = 'app/content')
  Plant::Utils.yaml_files(dir).inject({}) do |memo, fle|
    memo.merge(Plant::Utils.load_yaml_file(fle))
  end
end
load_yaml_file(path) click to toggle source

Converts a given `path` yaml file into a flat hash of key: values Parameters path:string (path to yml file) Return Hash

# File lib/plant/utils.rb, line 14
def self.load_yaml_file(path)
  contents = YAML.load(File.read(path))
  return contents.pathify('.') if contents.respond_to? :pathify
  {}
end
yaml_files(dir = 'app/content') click to toggle source

Gets all yml file in the given directory within the scope of a rails app Parameters dir (string) path reletive to Rails.root to search Returns Array of strings (filepaths)

# File lib/plant/utils.rb, line 7
def self.yaml_files(dir = 'app/content')
  Dir.glob("#{Rails.root}/#{dir}/**/*.yml")
end