Sha256: 71292dd4438762a61f5e3f9f0670093b0b98e42aaa1eed5e08294c09cf4a6736

Contents?: true

Size: 894 Bytes

Versions: 2

Compression:

Stored size: 894 Bytes

Contents

require_relative "read_fixture"
require_relative "helpers"
require 'pathname'

module FixtureOverlord
  module FixtureAccessor
    extend self

    def fixture_overlord(setting = nil)
      return unless setting.to_sym == :rule
      yaml_files.each do |yaml|

        # creates the hash version of the model
        define_method(yaml_filename(yaml)) do |key|
          hash            = FixtureOverlord.read_fixture(yaml, key)
          hash.yaml_file  = Helpers.yaml_filename(yaml)
          hash
        end

      end
    end

    def root
      @root ||= ::Pathname.new(Dir.pwd)
    end

    private

    # glob all yml files from their respective fixtures location
    def yaml_files
      Dir.glob(root.join("{test,spec}/fixtures/**/*.{yaml,yml}").to_s)
    end

    # reading the yaml filename
    def yaml_filename(file)
      ::File.basename(file).split('.').first
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fixture_overlord-0.1.9 lib/fixture_overlord/fixture_accessor.rb
fixture_overlord-0.1.8 lib/fixture_overlord/fixture_accessor.rb