lib/finix/resources/resource.rb in finix-0.16 vs lib/finix/resources/resource.rb in finix-1.0.0

- old
+ new

@@ -1,16 +1,12 @@ -require 'addressable/template' - require_relative '../utils' require_relative '../hal_resource' require_relative '../pagination' require_relative '../indifferent_hash' module Finix - module Resource - include HalResource def initialize(*args) opts = args.slice!(0) || {} href = opts.delete(:href) @@ -115,11 +111,12 @@ instance end def fetch(*arguments) if arguments.nil? or arguments.empty? or arguments[0].nil? or arguments[0].to_s.empty? - href = Finix.hypermedia_registry.key(self) + href = Finix.get_href self + # href = Finix.hypermedia_registry.key(self) return Finix::Utils.eval_class(self, Pagination).new :href => href end options = arguments.slice!(0) or {} if options.is_a? String and options =~ URI::regexp @@ -138,17 +135,26 @@ response = Finix.get href construct_from_response response.body end def pagination(*args) - href = Finix.hypermedia_registry.key(self) + href = Finix.get_href self + # href = Finix.hypermedia_registry.key(self) opts = args.slice!(0) || {} opts[:href] = href Finix::Utils.eval_class(self, Pagination).new opts end alias find fetch - alias retrieve fetch - end + def retrieve(*args) + pager_or_resource = fetch *args + + if pager_or_resource.is_a? Pagination + pager_or_resource.load! unless pager_or_resource.loaded + end + + pager_or_resource + end + end end end