Class: LiveResource::RemoteMethod
- Inherits:
-
Object
- Object
- LiveResource::RemoteMethod
- Defined in:
- lib/live_resource/methods/method.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #add_destination(proxy, method, params) ⇒ Object
- #encode_with(coder) ⇒ Object
- #final_destination? ⇒ Boolean
- #forward_to(forward) ⇒ Object
-
#initialize(params) ⇒ RemoteMethod
constructor
A new instance of RemoteMethod.
- #inspect ⇒ Object
- #method ⇒ Object
- #next_destination! ⇒ Object
- #params ⇒ Object
- #params=(new_params) ⇒ Object
Constructor Details
#initialize(params) ⇒ RemoteMethod
Returns a new instance of RemoteMethod.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/live_resource/methods/method.rb', line 10 def initialize(params) @path = params[:path] @token = params[:token] @flags = params[:flags] || {} if @path.nil? unless params[:method] raise ArgumentError.new("RemoteMethod must have a method") end @path = [] @path << { :method => params[:method], :params => (params[:params] || []) } end end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
7 8 9 |
# File 'lib/live_resource/methods/method.rb', line 7 def flags @flags end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/live_resource/methods/method.rb', line 7 def path @path end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/live_resource/methods/method.rb', line 8 def token @token end |
Instance Method Details
#add_destination(proxy, method, params) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/live_resource/methods/method.rb', line 39 def add_destination(proxy, method, params) @path << { :resource => proxy, :method => method, :params => params } self end |
#encode_with(coder) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/live_resource/methods/method.rb', line 78 def encode_with coder coder.tag = '!live_resource:method' coder['flags'] = @flags coder['path'] = @path coder['token'] = @token if @token end |
#final_destination? ⇒ Boolean
66 67 68 |
# File 'lib/live_resource/methods/method.rb', line 66 def final_destination? @path.length == 1 end |
#forward_to(forward) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/live_resource/methods/method.rb', line 48 def forward_to(forward) while forward @path << { :resource => forward.resource, :method => forward.method, :params => forward.params } forward = forward.next end self end |
#inspect ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/live_resource/methods/method.rb', line 70 def inspect if @path.length == 1 "#{self.class}: #{@path[0][:method]} (#{@path[0][:params].length} params)" else "#{self.class}: #{@path.length} path elements" end end |
#method ⇒ Object
27 28 29 |
# File 'lib/live_resource/methods/method.rb', line 27 def method @path[0][:method] end |
#next_destination! ⇒ Object
61 62 63 64 |
# File 'lib/live_resource/methods/method.rb', line 61 def next_destination! @path.shift @path[0][:resource] end |
#params ⇒ Object
31 32 33 |
# File 'lib/live_resource/methods/method.rb', line 31 def params @path[0][:params] end |
#params=(new_params) ⇒ Object
35 36 37 |
# File 'lib/live_resource/methods/method.rb', line 35 def params=(new_params) @path[0][:params] = new_params end |