Class: Gors::Model
- Inherits:
-
Object
- Object
- Gors::Model
- Defined in:
- lib/gors.rb
Instance Method Summary collapse
- #call(modelname) ⇒ Object
-
#initialize(req) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(req) ⇒ Model
Returns a new instance of Model.
212 213 214 |
# File 'lib/gors.rb', line 212 def initialize req @req = req end |
Instance Method Details
#call(modelname) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/gors.rb', line 216 def call modelname case @req.request_method when "GET" if(Object.const_get(modelname.capitalize).respond_to? "append") model = Object.const_get(modelname.capitalize).all.send(Object.const_get(modelname.capitalize).append) else model = Object.const_get(modelname.capitalize).all end model.to_json when "POST" if(Object.const_get(modelname.capitalize).respond_to? "append") model = Object.const_get(modelname.capitalize).create(JSON.parse(@req.body.string)) else model = Object.const_get(modelname.capitalize).create(JSON.parse(@req.body.string)) end model.to_json else end end |