app/assets/javascripts/joosy/core/resource/rest.js.coffee in joosy-1.1.0.alpha.3 vs app/assets/javascripts/joosy/core/resource/rest.js.coffee in joosy-1.1.0
- old
+ new
@@ -26,26 +26,49 @@
else
parent
, ''
#
- # Builds member path based on the given id.
+ # Builds base path
#
- # @param [String] id ID of entity to build member path for
# @param [Hash] options See {Joosy.Resource.REST.find} for possible options
#
# @example Basic usage
- # Resource.memberPath(1, from: 'foo') # /resources/1/foo
+ # Resource.basePath() # /resources
#
- @memberPath: (id, options={}) ->
- path = ("/" + @::__entityName.pluralize())
- path = @__source if @__source? && !options.parent?
- path += "/#{id}"
+ @basePath: (options={}) ->
+ if @__source
+ path = @__source
+ else
+ path = '/'
+ path += @__namespace__.map((s)-> s.underscore()).join('/') + '/' if @__namespace__.length > 0
+ path += @::__entityName.pluralize()
if options.parent?
path = @__parentsPath(if Object.isArray(options.parent) then options.parent else [options.parent]) + path
+ path
+
+ #
+ # Builds base path
+ #
+ # @see Joosy.Resource.REST.basePath
+ #
+ basePath: (options) ->
+ @constructor.basePath options
+
+ #
+ # Builds member path based on the given id.
+ #
+ # @param [String] id ID of entity to build member path for
+ # @param [Hash] options See {Joosy.Resource.REST.find} for possible options
+ #
+ # @example Basic usage
+ # Resource.memberPath(1, from: 'foo') # /resources/1/foo
+ #
+ @memberPath: (id, options={}) ->
+ path = @basePath(options) + "/#{id}"
path += "/#{options.from}" if options.from?
path
#
# Builds member path
@@ -53,11 +76,11 @@
# @param [Hash] options See {Joosy.Resource.REST.find} for possible options
#
# @example Basic usage
# resource.memberPath(from: 'foo') # /resources/1/foo
#
- memberPath: (options={}) ->
+ memberPath: (options) ->
@constructor.memberPath @id(), options
#
# Builds collection path
#
@@ -65,24 +88,19 @@
#
# @example Basic usage
# Resource.collectionPath() # /resources/
#
@collectionPath: (options={}) ->
- path = ("/" + @::__entityName.pluralize())
- path = @__source if @__source? && !options.parent?
-
- if options.parent?
- path = @__parentsPath(if Object.isArray(options.parent) then options.parent else [options.parent]) + path
-
+ path = @basePath(options)
path += "/#{options.from}" if options.from?
path
#
# Builds collection path
#
# @see Joosy.Resource.REST.collectionPath
#
- collectionPath: (options={}) ->
+ collectionPath: (options) ->
@constructor.collectionPath options
#
# Sends the GET query using collectionPath.
# Callback will get parsed JSON object as a parameter.