From 9ebef18f9b65cf4dec8459e866fdce3d125ba02e Mon Sep 17 00:00:00 2001 From: Paul B Date: Fri, 5 Sep 2014 19:20:31 +0200 Subject: [PATCH] fix(models_controller): mix up of private/public methods --- lib/yodatra/models_controller.rb | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/yodatra/models_controller.rb b/lib/yodatra/models_controller.rb index f59204f..e7d620c 100644 --- a/lib/yodatra/models_controller.rb +++ b/lib/yodatra/models_controller.rb @@ -44,6 +44,18 @@ module Yodatra # enable_search_on :name class ModelsController < Sinatra::Base + # Generic route to target ONE resource + ONE_ROUTE = + %r{\A/([\w]+?)/([0-9]+)(?:/([\w]+?)/([0-9]+)){0,1}\Z} + + # Generic route to target ALL resources + ALL_ROUTE = + %r{\A/([\w]+?)(?:/([0-9]+)/([\w]+?)){0,1}\Z} + + # Search route + SEARCH_ROUTE = + %r{\A/([\w]+?)(?:/([0-9]+)/([\w]+?)){0,1}/search\Z} + before do content_type 'application/json' end @@ -103,8 +115,6 @@ class ModelsController < Sinatra::Base end class << self - private - def model_name self.name.split('::').last.gsub(/sController/, '') end @@ -113,8 +123,6 @@ def model model_name.constantize end - public - # This helper gives the ability to disable default root by specifying # a list of routes to disable. # @param *opts list of routes to disable (e.g. :create, :destroy) @@ -158,18 +166,6 @@ def enable_search_on(*attributes) private - # Generic route to target ONE resource - ONE_ROUTE = - %r{\A/([\w]+?)/([0-9]+)(?:/([\w]+?)/([0-9]+)){0,1}\Z} - - # Generic route to target ALL resources - ALL_ROUTE = - %r{\A/([\w]+?)(?:/([0-9]+)/([\w]+?)){0,1}\Z} - - # Search route - SEARCH_ROUTE = - %r{\A/([\w]+?)(?:/([0-9]+)/([\w]+?)){0,1}/search\Z} - # Defines a nested route or not and retrieves the correct resource (or resources) # @param disables is the name to check if it was disabled # @param &block to be yield with the retrieved resource