Class: Transdifflation::YAMLReader
- Inherits:
-
Object
- Object
- Transdifflation::YAMLReader
- Defined in:
- lib/transdifflation/yaml_reader.rb
Overview
Reads YAML from the specified source
Class Method Summary collapse
-
.read_YAML_from_filesystem(path_to_yaml_relative_from_rails_root) ⇒ Object
Get YAML content from a file in filesystem.
-
.read_YAML_from_gem(gem_name, file_path_to_yaml_in_gem) ⇒ Object
Get YAML content from a gem.
-
.read_YAML_from_pathfile(path_to_yaml) ⇒ Object
Get YAML content from a file in filesystem.
Class Method Details
.read_YAML_from_filesystem(path_to_yaml_relative_from_rails_root) ⇒ Object
Get YAML content from a file in filesystem
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/transdifflation/yaml_reader.rb', line 28 def self.read_YAML_from_filesystem(path_to_yaml_relative_from_rails_root) #get the file yaml_file_path = File.realpath(path_to_yaml_relative_from_rails_root, Rails.root) yaml_file_name = File.basename( yaml_file_path ) raise ArgumentError.new("File '#{yaml_file_name}' does not exists in path '#{yaml_file_path}'") if (!File.file?(yaml_file_path)) #read the yml content file get_YAML_content_from_YAML_file(yaml_file_path) end |
.read_YAML_from_gem(gem_name, file_path_to_yaml_in_gem) ⇒ Object
Get YAML content from a gem
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/transdifflation/yaml_reader.rb', line 9 def self.read_YAML_from_gem(gem_name, file_path_to_yaml_in_gem) #get where the gem is localized gem_SRC =`bundle show #{gem_name}`.chomp raise ArgumentError.new("Gem '#{gem_name}' not installed") if ($?.to_i != 0) #get return code and check if is different from zero #get the file within the gem yaml_file_in_gem_SRC = File.join( gem_SRC, file_path_to_yaml_in_gem ) raise ArgumentError.new("File '#{file_path_to_yaml_in_gem}' does not exists in gem '#{gem_name}'") if (!File.file?(yaml_file_in_gem_SRC)) #read the yml content file get_YAML_content_from_YAML_file(yaml_file_in_gem_SRC) end |
.read_YAML_from_pathfile(path_to_yaml) ⇒ Object
Get YAML content from a file in filesystem
42 43 44 45 46 47 48 49 50 |
# File 'lib/transdifflation/yaml_reader.rb', line 42 def self.read_YAML_from_pathfile(path_to_yaml) #get the file yaml_file_name = File.basename( path_to_yaml ) raise ArgumentError.new("File '#{yaml_file_name}' does not exists in path '#{path_to_yaml}'") if (!File.file?(path_to_yaml)) #read the yml content file get_YAML_content_from_YAML_file(path_to_yaml) end |