Module: Sinatra::REST::Helpers
- Defined in:
- lib/sinatra/rest.rb
Overview
model unspecific helpers, will be included once
Instance Method Summary collapse
- #call_model_method(model_class, name, options = {}) ⇒ Object
- #escape_model_id(model) ⇒ Object
-
#filter_model_params(params) ⇒ Object
for example _method will be removed.
Instance Method Details
#call_model_method(model_class, name, options = {}) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/sinatra/rest.rb', line 168 def call_model_method(model_class, name, ={}) if .nil? || model_class.method(name).arity == 0 Kernel.warn "warning: calling #{model_class.to_s}##{name} with args, although it doesn't take args" if model_class.send(name) else model_class.send(name, ) end end |
#escape_model_id(model) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/sinatra/rest.rb', line 154 def escape_model_id(model) if model.nil? raise 'can not generate url for nil' elsif model.kind_of?(String) Rack::Utils.escape(model) elsif model.kind_of?(Fixnum) model elsif model.id.kind_of? String Rack::Utils.escape(model.id) else model.id end end |
#filter_model_params(params) ⇒ Object
for example _method will be removed
150 151 152 |
# File 'lib/sinatra/rest.rb', line 150 def filter_model_params(params) params.reject {|k, v| k =~ /^(_|session_token)/ } end |