Class ActionWebService::API::Method
In: 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.

Methods

Attributes

expects  [R] 
name  [R] 
public_name  [R] 
returns  [R] 

Public Class methods

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 220
      def initialize(name, public_name, expects, returns)
        @name = name
        @public_name = public_name
        @expects = expects
        @returns = returns
        @caster = ActionWebService::Casting::BaseCaster.new(self)
      end

Public Instance methods

Backwards compatibility with previous API

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 264
      def [](sig_type)
        case sig_type
        when :expects
          @expects.map{|x| compat_signature_entry(x)}
        when :returns
          @returns.map{|x| compat_signature_entry(x)}
        end
      end

Casts a set of Ruby values into the expected Ruby values

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 235
      def cast_expects(params)
        @caster.cast_expects(params)
      end

Cast a Ruby return value into the expected Ruby value

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 240
      def cast_returns(return_value)
        @caster.cast_returns(return_value)
      end

Returns the index of the first expected parameter with the given name

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 246
      def expects_index_of(param_name)
        return -1 if @expects.nil?
        (0..(@expects.length-1)).each do |i|
          return i if @expects[i].name.to_s == param_name.to_s
        end
        -1
      end

Returns a hash keyed by parameter name for the given parameter list

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 256
      def expects_to_hash(params)
        return {} if @expects.nil?
        h = {}
        @expects.zip(params){ |type, param| h[type.name] = param }
        h
      end

The list of parameter names for this method

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 229
      def param_names
        return [] unless @expects
        @expects.map{ |type| type.name }
      end

String representation of this method

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 274
      def to_s
        fqn = ""
        fqn << (@returns ? (@returns[0].human_name(false) + " ") : "void ")
        fqn << "#{@public_name}("
        fqn << @expects.map{ |p| p.human_name }.join(", ") if @expects
        fqn << ")"
        fqn
      end

Private Instance methods

[Source]

# File actionwebservice/lib/action_web_service/api.rb, line 284
        def compat_signature_entry(entry)
          if entry.array?
            [compat_signature_entry(entry.element_type)]
          else
            if entry.spec.is_a?(Hash)
              {entry.spec.keys.first => entry.type_class}
            else
              entry.type_class
            end
          end
        end

[Validate]