Sha256: eaee92aa447ff7e3b5b864d37e21b1776f72d832eea776ce4bf38b16cd0776c5
Contents?: true
Size: 1.76 KB
Versions: 6
Compression:
Stored size: 1.76 KB
Contents
module Her module Model module Paths # Defines a custom collection path for the resource # # @example # class User # include Her::Model # collection_path "/users" # end def collection_path(path=nil) # {{{ return @her_collection_path unless path @her_resource_path = "#{path}/:id" @her_collection_path = path end # }}} # Defines a custom resource path for the resource # # @example # class User # include Her::Model # resource_path "/users/:id" # end def resource_path(path=nil) # {{{ return @her_resource_path unless path @her_resource_path = path end # }}} # Return a custom path based on the collection path and variable parameters # # @example # class User # include Her::Model # collection_path "/utilisateurs" # end # # User.all # Fetched via GET /utilisateurs def build_request_path(parameters={}) # {{{ (path = parameters.include?(:id) ? @her_resource_path : @her_collection_path).gsub(/:([\w_]+)/) do # Look for :key or :_key, otherwise raise an exception parameters[$1.to_sym] || parameters["_#{$1}".to_sym] || raise(Her::Errors::PathError.new("Missing :_#{$1} parameter to build the request path (#{path}).")) end end # }}} # Return a path based on the collection path and a resource data # # @example # class User # include Her::Model # collection_path "/utilisateurs" # end # # User.find(1) # Fetched via GET /utilisateurs/1 def request_path # {{{ self.class.build_request_path(@data) end # }}} end end end
Version data entries
6 entries across 6 versions & 1 rubygems