Sha256: a5b10b751d9c6b5f0c4573d5cab7774492a8db10c29967bc1717c9beefb70176

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

module ShopifyAPI
  module Mock
    class Fixtures
      @cache = {}
      
      class << self
        
        def all
          Dir[File.join(ShopifyAPI::Mock::Fixtures.path, "**", "*.json")].map do |fixture|
            File.basename(fixture, ".json").to_sym
          end
        end
        
        def read(name, ext = :json)
          fixture_name = "#{name.to_s}.#{ext.to_s}"
          fixture = File.join(self.path, fixture_name)
          raise "invalid fixture name" unless File.exists? fixture
          @cache[fixture_name] = File.read(fixture) unless @cache.include? fixture_name
          @cache[fixture_name]
        end
        
        def use(name, content)
          name = "#{name}.json"
          if content == :default
            @cache.delete name if @cache.include? name
          else
            @cache[name] = content
          end
          ShopifyAPI::Mock.reset
        end
        
        def path
          @path ||= File.expand_path("../fixtures/", __FILE__)
        end
        
        def path=(value)
          @path = value
          ShopifyAPI::Mock.reset
        end
        
        def reset
          @cache = {}
          @path = nil
          ShopifyAPI::Mock::Responses.register_all
        end
        
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shopify-mock-0.0.3 lib/shopify-mock/fixtures.rb
shopify-mock-0.0.2 lib/shopify-mock/fixtures.rb