Sha256: d9368d6c0fe6a76c33f1cbdcda9bcb5047bca982c2a658316e598692618c2deb
Contents?: true
Size: 961 Bytes
Versions: 3
Compression:
Stored size: 961 Bytes
Contents
require 'frenetic/concerns/hal_linked' require 'frenetic/concerns/collection_rest_methods' class Frenetic class ResourceCollection < Delegator include HalLinked include CollectionRestMethods def initialize( resource, params = {} ) @resource_class = resource @resources = [] @params = params || {} extract_resources! end def resource_type @resource_type ||= @resource_class.to_s.demodulize.underscore end def collection_key @collection_key ||= resource_type.pluralize end def __getobj__ @resources end def __setobj__ @resources end def api @resources.first.api end private def extract_resources! @resources = embedded_collection.collect do |resource| @resource_class.new resource end end def embedded_collection @params.fetch('_embedded',{}).fetch(collection_key, []) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
frenetic-0.0.20.alpha.6 | lib/frenetic/resource_collection.rb |
frenetic-0.0.20.alpha.5 | lib/frenetic/resource_collection.rb |
frenetic-0.0.20.alpha.4 | lib/frenetic/resource_collection.rb |