Class: Ext::Resource::Controllers::Rest
Class Attribute Summary collapse
-
.model ⇒ Object
Returns the value of attribute model.
-
.path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#create ⇒ Object
CRUD operations ###.
- #delete(id) ⇒ Object
-
#destroy(id) ⇒ Object
DELETE.
- #edit ⇒ Object
-
#get(action = nil, id = nil) ⇒ Object
GET method dispatching TODO : Test this method.
-
#index ⇒ Object
Pages ###.
- #new ⇒ Object
-
#post(action = nil, id = nil) ⇒ Object
POST method dispatching TODO : Update this method.
- #put(id) ⇒ Object
-
#show(id) ⇒ Object
GET.
-
#update(id) ⇒ Object
PUT.
Class Attribute Details
.model ⇒ Object
Returns the value of attribute model.
22 23 24 |
# File 'lib/ext/resource.rb', line 22 def model @model end |
.path ⇒ Object
Returns the value of attribute path.
22 23 24 |
# File 'lib/ext/resource.rb', line 22 def path @path end |
Class Method Details
.inherited(c) ⇒ Object
32 33 34 |
# File 'lib/ext/resource.rb', line 32 def inherited(c) c.path = "/#{c.name.gsub(/^.*::/,'').downcase}" end |
.urls ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/ext/resource.rb', line 24 def urls return [] unless @path @__urls ||= [ "#{path}", "#{path}/(\\d+)", "#{path}/(\\w+)", "#{path}/(\\w+)/(\\d+)", "#{path}/(\d+)/(\\w+)" ] end |
Instance Method Details
#create ⇒ Object
CRUD operations ###
90 91 92 |
# File 'lib/ext/resource.rb', line 90 def create # POST render name + '_create' end |
#delete(id) ⇒ Object
86 |
# File 'lib/ext/resource.rb', line 86 def delete(id); destroy(id); end |
#destroy(id) ⇒ Object
DELETE
102 103 104 |
# File 'lib/ext/resource.rb', line 102 def destroy(id) # DELETE redirect R(self, :index) end |
#edit ⇒ Object
116 117 118 |
# File 'lib/ext/resource.rb', line 116 def edit render name + '_edit' end |
#get(action = nil, id = nil) ⇒ Object
GET method dispatching TODO : Test this method
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ext/resource.rb', line 40 def get(action=nil, id=nil) # corrections if (new_id = action.to_i) > 0 action = id ? id : 'show' id = new_id elsif not action action = 'index' end if respond_to?(action) and not ['create','update','delete'].include?(action) if id and method(action).arity > 0 return send(action, id) elsif method(action).arity < 1 return send(action) end end puts "Action not found" if $DBG forward NotFound, 'get', @env.SCRIPT_INFO end |
#index ⇒ Object
Pages ###
108 109 110 |
# File 'lib/ext/resource.rb', line 108 def index render name + '_index' end |
#new ⇒ Object
112 113 114 |
# File 'lib/ext/resource.rb', line 112 def new render name + '_new' end |
#post(action = nil, id = nil) ⇒ Object
POST method dispatching TODO : Update this method
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ext/resource.rb', line 62 def post(action=nil, id=nil) # corrections if (new_id = action.to_i) > 0 action = id ? id : 'update' id = new_id elsif not action action = 'create' end # prefix other actions action = '_' + action unless ['create','update','delete'].include?(action) if respond_to?(action) if id and method(action).arity > 0 return send(action, id) elsif method(action).arity < 1 return send(action) end end puts "Action not found" if $DBG forward NotFound, 'get', @env.SCRIPT_INFO end |
#put(id) ⇒ Object
85 |
# File 'lib/ext/resource.rb', line 85 def put(id); update(id); end |
#show(id) ⇒ Object
GET
94 95 96 |
# File 'lib/ext/resource.rb', line 94 def show(id) # GET render name + '_show' end |
#update(id) ⇒ Object
PUT
98 99 100 |
# File 'lib/ext/resource.rb', line 98 def update(id) # PUT redirect R(self, :show, id) end |