Class: ActionService::Protocol::AbstractProtocolMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/action_service/protocol/abstract.rb

Overview

:nodoc:

Direct Known Subclasses

ProtocolRequest, ProtocolResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AbstractProtocolMessage

Returns a new instance of AbstractProtocolMessage.



39
40
41
42
43
# File 'lib/action_service/protocol/abstract.rb', line 39

def initialize(options={})
  @signature = @return_signature = nil
  @options = options
  @type = @options[:type] || CheckedMessage
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/action_service/protocol/abstract.rb', line 37

def options
  @options
end

#return_signatureObject

Returns the value of attribute return_signature.



35
36
37
# File 'lib/action_service/protocol/abstract.rb', line 35

def return_signature
  @return_signature
end

#signatureObject

Returns the value of attribute signature.



34
35
36
# File 'lib/action_service/protocol/abstract.rb', line 34

def signature
  @signature
end

#typeObject

Returns the value of attribute type.



36
37
38
# File 'lib/action_service/protocol/abstract.rb', line 36

def type
  @type
end

Instance Method Details

#check_compatibility(expected_class, received_class) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/action_service/protocol/abstract.rb', line 72

def check_compatibility(expected_class, received_class)
  return if \
      (expected_class == TrueClass or expected_class == FalseClass) and \
      (received_class == TrueClass or received_class == FalseClass)
  unless received_class.ancestors.include?(expected_class) or \
         expected_class.ancestors.include?(received_class)
    raise(ProtocolError, "value of type #{received_class.name} is not " +
                         "compatible with expected type #{expected_class.name}")
  end
end

#check_parameter_types(values, signature) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/action_service/protocol/abstract.rb', line 62

def check_parameter_types(values, signature)
  return unless checked? && signature
  unless signature.length == values.length
    raise(ProtocolError, "Signature and parameter lengths mismatch")
  end
  (1..signature.length).each do |i|
    check_compatibility(signature[i-1], values[i-1].class)
  end
end

#checked?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/action_service/protocol/abstract.rb', line 58

def checked?
  @type == CheckedMessage
end