Sha256: f067a8b172995c126d94db1c6d275e882851c82eff8d7398a34792ef6c74ce55
Contents?: true
Size: 979 Bytes
Versions: 8
Compression:
Stored size: 979 Bytes
Contents
module Zoop class NestedModel < Model def create @custom_url = self.class.url(parent_id) super end def url(*params) raise RequestError.new('Invalid ID') unless id.present? self.class.url parent_id, CGI.escape(id.to_s), *params end class << self def parent_resource_name raise NotImplementedError end def find_by_id(parent_id:, id:) raise RequestError.new('Invalid ID') unless id.present? raise RequestError.new('Invalid parent ID') unless parent_id.present? Zoop::Request.get(url parent_id, id).call end alias :find :find_by_id def url(parent_id, *params) raise RequestError.new('Invalid parent ID') unless parent_id.present? ["/#{parent_resource_name}", parent_id, "#{ CGI.escape underscored_class_name }s", *params].join '/' end end protected def parent_id raise NotImplementedError end end end
Version data entries
8 entries across 8 versions & 1 rubygems