lib/finix/resources/resource.rb in finix-0.6 vs lib/finix/resources/resource.rb in finix-0.7
- old
+ new
@@ -20,14 +20,12 @@
links.each do |key, link|
property = key.sub(/.*?\./, '')
if property == 'self'
@hyperlinks[:self] = link[:href]
- # @attributes['href'] = link[:href]
else
@hyperlinks[property] = Finix::Utils.callable(Finix::Pagination.new(link[:href], {}))
- # @hyperlinks[property] = Finix.from_hypermedia_registry(property).new 'href' => link[:href]
end
end
end
def fetch(*arguments)
@@ -112,41 +110,29 @@
instance.hydrate(links)
instance
end
def fetch(*arguments)
- if arguments.nil? or arguments.empty? or arguments[0].nil? or arguments[0].to_s.empty? # no symbol.empty? in 1.8.7
- raise Finix::NotFound
+ if arguments.nil? or arguments.empty? or arguments[0].nil? or arguments[0].to_s.empty?
+ href = Finix.hypermedia_registry.key(self)
+ return Finix::Pagination.new href
end
options = arguments.slice!(0) or {}
- if options.is_a? String
+ if options.is_a? String and options =~ URI::regexp
href = options
else
href = Finix.hypermedia_registry.key(self) or Finix.hypermedia_registry.key(self.class)
- id = options.delete(:id)
+ id = options if options.is_a? String
+ id = options.delete(:id) if options.is_a? Hash
href = "#{href}/#{id}" unless id.nil?
end
response = Finix.get href
construct_from_response response.body
-
end
alias find fetch
-
- # def paginate(options = {})
- # Finix::Pagination.new href, options
- # end
-
- # alias scoped paginate
- # alias where paginate
-
- # def all(options = {})
- # pager = paginate(options)
- # pager.to_a
- # end
-
end
end
end