| Class | ActionWebService::API::Method |
| In: |
vendor/rails/actionwebservice/lib/action_web_service/api.rb
|
| Parent: | Object |
Represents an API method and its associated metadata, and provides functionality to assist in commonly performed API method tasks.
| expects | [R] | |
| name | [R] | |
| public_name | [R] | |
| returns | [R] |
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 168
168: def initialize(name, public_name, expects, returns)
169: @name = name
170: @public_name = public_name
171: @expects = expects
172: @returns = returns
173: @caster = ActionWebService::Casting::BaseCaster.new(self)
174: end
Backwards compatibility with previous API
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 212
212: def [](sig_type)
213: case sig_type
214: when :expects
215: @expects.map{|x| compat_signature_entry(x)}
216: when :returns
217: @returns.map{|x| compat_signature_entry(x)}
218: end
219: end
Casts a set of Ruby values into the expected Ruby values
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 183
183: def cast_expects(params)
184: @caster.cast_expects(params)
185: end
Cast a Ruby return value into the expected Ruby value
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 188
188: def cast_returns(return_value)
189: @caster.cast_returns(return_value)
190: end
Returns the index of the first expected parameter with the given name
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 194
194: def expects_index_of(param_name)
195: return -1 if @expects.nil?
196: (0..(@expects.length-1)).each do |i|
197: return i if @expects[i].name.to_s == param_name.to_s
198: end
199: -1
200: end
Returns a hash keyed by parameter name for the given parameter list
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 204
204: def expects_to_hash(params)
205: return {} if @expects.nil?
206: h = {}
207: @expects.zip(params){ |type, param| h[type.name] = param }
208: h
209: end
The list of parameter names for this method
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 177
177: def param_names
178: return [] unless @expects
179: @expects.map{ |type| type.name }
180: end
String representation of this method
# File vendor/rails/actionwebservice/lib/action_web_service/api.rb, line 222
222: def to_s
223: fqn = ""
224: fqn << (@returns ? (@returns[0].human_name(false) + " ") : "void ")
225: fqn << "#{@public_name}("
226: fqn << @expects.map{ |p| p.human_name }.join(", ") if @expects
227: fqn << ")"
228: fqn
229: end