Sha256: de15d62bd8358d47e5a982a3f5175c57a6ef90b3ec8a2281a65db602fd9768ec
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
require 'json' module Hikki class Collection attr_reader :collection def initialize(collection) @collection = collection.to_s end def index(field) raise 'Implementation missing.' end def save(data) raise 'Implementation missing.' end def find(id) raise 'Implementation missing.' end def all(options) raise 'Implementation missing.' end def find_by(field, value, options) raise 'Implementation missing.' end def remove(id) raise 'Implementation missing.' end def remove_all raise 'Implementation missing.' end def normalize_data(data) deep_copy(data).tap { |d| d.merge!('id' => id_for(d)) } end def deep_copy(h) JSON.parse(h.to_json) end def id_for(data) data.fetch('id', 'undefined').to_s end def normalize_options(options) { limit: options[:limit] || options['limit'] || -1, offset: options[:offset] || options['offset'] || 0 } end def page_range(options) (options[:offset]..(options[:limit] == -1 ? -1 : options[:offset] + options[:limit] - 1)) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hikki-0.0.3 | lib/hikki/collection.rb |
hikki-0.0.2 | lib/hikki/collection.rb |
hikki-0.0.1 | lib/hikki/collection.rb |