Class: ShopifyAPI::Mock::Fixture
- Inherits:
-
Object
- Object
- ShopifyAPI::Mock::Fixture
- Defined in:
- lib/shopify-mock/fixtures.rb
Overview
provides easy access to fixtures
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/fixtures.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
68 69 70 71 72 73 |
# File 'lib/shopify-mock/fixtures.rb', line 68 def all Dir[File.join(ShopifyAPI::Mock::Fixture.path, "*")].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
84 85 86 87 88 89 |
# File 'lib/shopify-mock/fixtures.rb', line 84 def find(name, ext = :json) fixture_name = "#{name.to_s}.#{ext.to_s}" file_name = File.join(self.path, 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
96 97 98 |
# File 'lib/shopify-mock/fixtures.rb', line 96 def path @path ||= File.("../fixtures/", __FILE__) end |
.path=(value) ⇒ String
sets the current fixtures path
106 107 108 109 110 |
# File 'lib/shopify-mock/fixtures.rb', line 106 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/fixtures.rb', line 24 def data @data || File.read(@file_name) end |
#data=(value) ⇒ Object
overrides the contents of the fixture
47 48 49 50 |
# File 'lib/shopify-mock/fixtures.rb', line 47 def data=(value) @data = value data end |
#ext ⇒ Symbol
gets the extension of the fixture
58 59 60 |
# File 'lib/shopify-mock/fixtures.rb', line 58 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/fixtures.rb', line 34 def name File.basename(@file_name, ".#{self.ext.to_s}").to_sym end |