Sha256: c3df31418e24bc175950863097cb4b71fee7c7c53c71ac82a43fa27c3c444147

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require_relative 'flock'
module MockingBird
  class Mocker
    cattr_accessor :path, :flocks

    class << self
      def setup_mocks(options = {})
        # iterate over mocks and create birds in teh flock
        @flocks = {}
        @path = options.fetch(:path, default_directory)
        load_mocks if @path
      end

      def load_mocks
        Dir.entries(@path).each do |dir|

          full_path = File.join(@path,dir)
          if File.directory?(full_path) && dir != ".." && dir != "."
            flock = Flock.new(full_path)
            @flocks[flock.service.downcase.to_sym] = flock
          end
        end
      end

      private

      def default_directory
        Rails.root.join('test','mocks')
      end

      def method_missing(method, *args, &block)
        if match = method.to_s.match(/^(.*)=$/)
          super
        elsif has_flock?(method)
          @flocks[method]
        else
          nil
        end
      end

      def has_flock?(name)
        @flocks.keys.include? name
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocking_bird-0.0.2 lib/mocking_bird/mocker.rb