Sha256: 70e1e35e374d1510ca8a3a8ac6afd404125d0d7965402a128b5426250a06ba6e
Contents?: true
Size: 909 Bytes
Versions: 4
Compression:
Stored size: 909 Bytes
Contents
require 'json' require 'yajl' class FakeResponse def self.render(resource, id = nil, collection = false) new(resource, id, collection).render end def initialize(resource, id = nil, collection = false) @resource, @id, @collection = resource, id, collection end def render collection ? '[' + output + ']' : output end private attr_reader :resource, :id, :collection def output id ? converted : raw end def converted JSON(parsed) end def parsed @parsed ||= Yajl::Parser.parse(raw).merge!('id' => id) end def raw @raw ||= File .read(File.dirname(__FILE__) + '/../remotes/' + filename) end def filename testing || reality end def testing resource + '_200.json' if testing? end def testing? id =~ /^200/ end def reality return [resource, '_', id, '.json'].join if id [resource, '.json'].join end end
Version data entries
4 entries across 4 versions & 1 rubygems