lib/fauna/cache.rb in fauna-1.3.2 vs lib/fauna/cache.rb in fauna-1.3.3
- old
+ new
@@ -4,11 +4,11 @@
class Cache
attr_reader :connection
def initialize(connection)
- raise ArgumentError, "Connection cannot be nil" unless connection
+ fail ArgumentError, 'Connection cannot be nil' unless connection
@cache = {}
@connection = connection
end
def get(ref, query = {}, pagination = {})
@@ -30,34 +30,32 @@
res['resource']
end
def put(ref, data)
res = @connection.put(ref, data)
- if res['resource']
- update_cache(ref, res)
- res['resource']
- end
+ return unless res['resource']
+ update_cache(ref, res)
+ res['resource']
end
def patch(ref, data)
res = @connection.patch(ref, data)
- if res['resource']
- update_cache(ref, res)
- res['resource']
- end
+ return unless res['resource']
+ update_cache(ref, res)
+ res['resource']
end
def delete(ref, data)
@connection.delete(ref, data)
@cache.delete(ref)
nil
end
- private
+ private
def update_cache(ref, res)
- # FIXME Implement set range caching
- if (res['resource']['class'] != "resources" && res['resource']['class'] != "events")
+ # FIXME: Implement set range caching
+ if res['resource']['class'] != 'resources' && res['resource']['class'] != 'events'
@cache[ref] = res['resource']['ref'] # store the non-canonical ref as a pointer to the real one.
@cache[res['resource']['ref']] = res['resource']
end
@cache.merge!(res['references'] || {})
end