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 164
164: def initialize(name, public_name, expects, returns)
165: @name = name
166: @public_name = public_name
167: @expects = expects
168: @returns = returns
169: @caster = ActionWebService::Casting::BaseCaster.new(self)
170: end
Public Instance methods
Backwards compatibility with previous API
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 208
208: def [](sig_type)
209: case sig_type
210: when :expects
211: @expects.map{|x| compat_signature_entry(x)}
212: when :returns
213: @returns.map{|x| compat_signature_entry(x)}
214: end
215: 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 179
179: def cast_expects(params)
180: @caster.cast_expects(params)
181: end
Cast a Ruby return value into the expected Ruby value
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 184
184: def cast_returns(return_value)
185: @caster.cast_returns(return_value)
186: 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 190
190: def expects_index_of(param_name)
191: return -1 if @expects.nil?
192: (0..(@expects.length-1)).each do |i|
193: return i if @expects[i].name.to_s == param_name.to_s
194: end
195: -1
196: 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 200
200: def expects_to_hash(params)
201: return {} if @expects.nil?
202: h = {}
203: @expects.zip(params){ |type, param| h[type.name] = param }
204: h
205: end
The list of parameter names for this method
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 173
173: def param_names
174: return [] unless @expects
175: @expects.map{ |type| type.name }
176: end
String representation of this method
[ show source ]
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 218
218: def to_s
219: fqn = ""
220: fqn << (@returns ? (friendly_param(@returns[0], false) + " ") : "void ")
221: fqn << "#{@public_name}("
222: fqn << @expects.map{ |p| friendly_param(p) }.join(", ") if @expects
223: fqn << ")"
224: fqn
225: end