Class: ShopifyAPI::Mock::Fixture
- Inherits:
-
Object
- Object
- ShopifyAPI::Mock::Fixture
- Defined in:
- lib/shopify-mock/fixture.rb
Overview
provides easy access to fixtures
Constant Summary collapse
- @@path =
nil
- @@cache =
{}
Class Method Summary collapse
-
.all ⇒ Array, Fixture
finds all the fixtures.
-
.find(name, ext = :json) ⇒ ShopifyAPI::Mock::Fixture
finds a fixture by name.
-
.path ⇒ String
gets the current path to the fixtures.
-
.path=(value) ⇒ String
sets the current fixtures path.
Instance Method Summary collapse
-
#data ⇒ String
gets the content of the fixture.
-
#data=(value) ⇒ Object
overrides the contents of the fixture.
-
#ext ⇒ Symbol
gets the extension of the fixture.
-
#initialize(file_name) ⇒ Fixture
constructor
private
creates a new instance of ShopifyAPI::Mock::Fixture.
-
#name ⇒ Symbol
gets the name of the fixture.
Constructor Details
#initialize(file_name) ⇒ Fixture
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
creates a new instance of ShopifyAPI::Mock::Fixture
13 14 15 16 |
# File 'lib/shopify-mock/fixture.rb', line 13 def initialize(file_name) raise IOError, "File not found: #{file_name}" unless File.exists? file_name @file_name = file_name end |
Class Method Details
.all ⇒ Array, Fixture
finds all the fixtures
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/shopify-mock/fixture.rb', line 70 def all # get a list of all the fixture files files = [] Dir[File.join(ShopifyAPI::Mock::Fixture.path, "**", "*")].each do |f| files << f unless File.directory? f end # map files to fixtures files.map do |file_name| fixture_name = File.basename(file_name) @@cache[fixture_name] ||= Fixture.new(file_name) end end |
.find(name, ext = :json) ⇒ ShopifyAPI::Mock::Fixture
finds a fixture by name
93 94 95 96 97 98 |
# File 'lib/shopify-mock/fixture.rb', line 93 def find(name, ext = :json) fixture_name = "#{name.to_s}.#{ext.to_s}" file_name = File.join(self.path, ext.to_s, fixture_name) return nil unless File.exists? file_name @@cache[fixture_name] ||= Fixture.new(file_name) end |
.path ⇒ String
gets the current path to the fixtures
105 106 107 |
# File 'lib/shopify-mock/fixture.rb', line 105 def path @@path ||= File.("../fixtures/", __FILE__) end |
.path=(value) ⇒ String
sets the current fixtures path
115 116 117 118 119 |
# File 'lib/shopify-mock/fixture.rb', line 115 def path=(value) return @@path if @@path == value @@path = value @@cache = {} end |
Instance Method Details
#data ⇒ String
gets the content of the fixture
24 25 26 |
# File 'lib/shopify-mock/fixture.rb', line 24 def data @data || File.read(@file_name) end |
#data=(value) ⇒ Object
overrides the contents of the fixture
49 50 51 52 |
# File 'lib/shopify-mock/fixture.rb', line 49 def data=(value) @data = value data end |
#ext ⇒ Symbol
gets the extension of the fixture
60 61 62 |
# File 'lib/shopify-mock/fixture.rb', line 60 def ext File.extname(@file_name).gsub(".","").to_sym end |
#name ⇒ Symbol
gets the name of the fixture
34 35 36 |
# File 'lib/shopify-mock/fixture.rb', line 34 def name File.basename(@file_name, ".#{self.ext.to_s}").to_sym end |