module Fauxbag

Constants

VERSION

Public Instance Methods

load_chefzero_databag(databag) click to toggle source

Parse all data bag JSON files into a single hash

@param [String] Data Bag Directory @return [Hash] All data bags in a single Hash

# File lib/fauxbag/load_databag_json.rb, line 20
def load_chefzero_databag(databag)
  databag_hash = Hash.new
  databag_dir  = Dir.glob("#{data_bag_load_path}/#{databag}/" + '*.json')

  databag_dir.each do |item|
    File.open(item, "r") do |f|
      data_bag_item = MultiJson.load(f)
      id = data_bag_item.delete("id")

      databag_hash[id] = data_bag_item
    end
  end

  databag_hash
end
load_databag_json(databag, item) click to toggle source

Parse example data bag item JSON file

@param [String] Data Bag Directory @param [String] Data Bag Item @return [Hash] Parsed JSON Data Bag Item

# File lib/fauxbag/load_databag_json.rb, line 10
def load_databag_json(databag, item)
  File.open(File.join(data_bag_load_path, databag, "#{item}.json"), "r") do |f|
    MultiJson.load(f)
  end
end

Private Instance Methods

current_example_dir() click to toggle source

Returns a string of the full path to the folder where the current spec file is located based on the example metadata for this test.

@return [String] Path to the spec file

# File lib/fauxbag/load_databag_json.rb, line 46
def current_example_dir
  File.dirname(File.expand_path(RSpec.current_example.metadata[:file_path]))
end
data_bag_load_path() click to toggle source
# File lib/fauxbag/load_databag_json.rb, line 38
def data_bag_load_path
  File.join(current_example_dir, "data_bags")
end