Represents an API method and its associated metadata, and provides functionality to assist in commonly performed API method tasks.
Methods
Attributes
| [R] | expects | |
| [R] | name | |
| [R] | public_name | |
| [R] | returns |
Public Class methods
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 172
172: def initialize(name, public_name, expects, returns)
173: @name = name
174: @public_name = public_name
175: @expects = expects
176: @returns = returns
177: @caster = ActionWebService::Casting::BaseCaster.new(self)
178: end
Public Instance methods
Backwards compatibility with previous API
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 216
216: def [](sig_type)
217: case sig_type
218: when :expects
219: @expects.map{|x| compat_signature_entry(x)}
220: when :returns
221: @returns.map{|x| compat_signature_entry(x)}
222: end
223: end
Casts a set of Ruby values into the expected Ruby values
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 187
187: def cast_expects(params)
188: @caster.cast_expects(params)
189: end
Cast a Ruby return value into the expected Ruby value
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 192
192: def cast_returns(return_value)
193: @caster.cast_returns(return_value)
194: end
Returns the index of the first expected parameter with the given name
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 198
198: def expects_index_of(param_name)
199: return -1 if @expects.nil?
200: (0..(@expects.length-1)).each do |i|
201: return i if @expects[i].name.to_s == param_name.to_s
202: end
203: -1
204: end
Returns a hash keyed by parameter name for the given parameter list
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 208
208: def expects_to_hash(params)
209: return {} if @expects.nil?
210: h = {}
211: @expects.zip(params){ |type, param| h[type.name] = param }
212: h
213: end
The list of parameter names for this method
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 181
181: def param_names
182: return [] unless @expects
183: @expects.map{ |type| type.name }
184: end
String representation of this method
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 226
226: def to_s
227: fqn = ""
228: fqn << (@returns ? (@returns[0].human_name(false) + " ") : "void ")
229: fqn << "#{@public_name}("
230: fqn << @expects.map{ |p| p.human_name }.join(", ") if @expects
231: fqn << ")"
232: fqn
233: end