class Yurl::Engine

Attributes

file_name[RW]
secret_ruby[RW]

Public Class Methods

check_load_params(yml_file) click to toggle source
# File lib/yurl/engine.rb, line 84
def self.check_load_params(yml_file)
  begin
    raise ArgumentError, 'Attempted To Process Nil File Object' if yml_file.nil?
    raise ArgumentError, 'Attempted To Process Non YAML File' unless (File.extname(yml_file) == '.yml') || (File.extname(yml_file) == '.yaml')
    raise IOError, 'Attempted To Process Non-Existent YAML File' unless File.exist?(yml_file)
    raise ArgumentError, 'Attempted To Process Empty YAML File' if Psych.parse_file(yml_file).to_ruby == false
  rescue StandardError => e
    return "Exception raised with message - #{e.message}"
  end
  true
end
dump_yaml(yaml_hash) click to toggle source

Dump The Yaml File - Yaml to Hash

# File lib/yurl/engine.rb, line 75
def self.dump_yaml(yaml_hash)
  yaml_hash
end
find(needle_string, haystack) click to toggle source

Method to Follow String to Yaml Node.

# File lib/yurl/engine.rb, line 28
def self.find(needle_string, haystack)
  query_list = Engine.process_query_string(needle_string)
  ret_val = Engine.find_nested(query_list, haystack)
  return "Parameter Not Found At Path - #{needle_string}" if ret_val.nil?
  ret_val
end
find_internal(param, hash) click to toggle source

Method To Check If Param Is A Key In The Array

# File lib/yurl/engine.rb, line 47
def self.find_internal(param, hash)
  return nil unless hash.class == Hash && !hash[param].nil?
  hash[param]
end
find_nested(needle_array, haystack) click to toggle source

Method To Follow Array Path To Find Yaml Target

# File lib/yurl/engine.rb, line 36
def self.find_nested(needle_array, haystack)
  ret_val = haystack
  loop do
    param = needle_array.pop
    break if ret_val.nil? || param.nil?
    ret_val = Engine.find_internal(param, ret_val)
  end
  ret_val
end
load_file(yml_file) click to toggle source

Self File Loader For Engine Class Need to put in logic about an empty yaml file / non - existent YAML File

# File lib/yurl/engine.rb, line 61
def self.load_file(yml_file)
  file_check = Engine.check_load_params(yml_file)
  return file_check unless file_check == true
  Psych.parse_file(yml_file).to_ruby
end
load_yaml(yml) click to toggle source

Loading Yaml From Directly Passed Yaml Text

# File lib/yurl/engine.rb, line 68
def self.load_yaml(yml)
  raise ArgumentError, 'Attempted To Process Null Object' if yml.nil?
  ret_val = Psych.parse(yml).to_ruby
  ret_val
end
new(yml_file) click to toggle source

Constructor for Engine Class

# File lib/yurl/engine.rb, line 12
def initialize(yml_file)
  @file_name = yml_file
  @secret_ruby = Engine.load_file(yml_file)
end
pretty_print_yaml(yaml_hash) click to toggle source

Pretty Print The YAML File - Yaml To String

# File lib/yurl/engine.rb, line 80
def self.pretty_print_yaml(yaml_hash)
  yaml_hash.pretty_inspect
end
process_query_string(needle) click to toggle source

Method to Parse Query List in Query Array

# File lib/yurl/engine.rb, line 53
def self.process_query_string(needle)
  query_list = needle.split('/')
  raise ArgumentError, 'Query String In Wrong Format' unless query_list.respond_to?('each')
  query_list.reverse
end

Public Instance Methods

find(query) click to toggle source

Method To Find Nodes With Specific Values

# File lib/yurl/engine.rb, line 18
def find(query)
  query_list = Engine.process_query_string(query)
  ret = find_nested(query_list)
  return "Parameter Not Found At Path - #{query}" if ret.nil?
  ret
end