Class: Plant::Utils
- Inherits:
-
Object
- Object
- Plant::Utils
- Defined in:
- lib/plant/utils.rb
Overview
Utilities for the library
Class Method Summary collapse
-
.load_all_yaml_files(dir = 'app/content') ⇒ Object
Loads all the yaml files into memory.
-
.load_yaml_file(path) ⇒ Object
Converts a given ‘path` yaml file into a flat hash of key: values Parameters path:string (path to yml file) Return Hash.
-
.yaml_files(dir = 'app/content') ⇒ Object
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).
Class Method Details
.load_all_yaml_files(dir = 'app/content') ⇒ Object
Loads all the yaml files into memory
21 22 23 24 25 |
# 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) ⇒ Object
Converts a given ‘path` yaml file into a flat hash of key: values Parameters path:string (path to yml file) Return Hash
14 15 16 17 18 |
# 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') ⇒ Object
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)
7 8 9 |
# File 'lib/plant/utils.rb', line 7 def self.yaml_files(dir = 'app/content') Dir.glob("#{Rails.root}/#{dir}/**/*.yml") end |