Module: Merb::Ext::Direct::RemotingProvider

Defined in:
lib/merb-ext-direct/mixins/remoting_provider.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

standard ruby method called when some class does: include Ext::Direct::RemotingProvider



15
16
17
18
19
# File 'lib/merb-ext-direct/mixins/remoting_provider.rb', line 15

def self.included(base)
    # must explicity specify controller-actions to make callable.  security-wise, this is a *good* thing.
    # just one action is added.
    base.show_action(:rpc)
end

Instance Method Details

#rpcObject

rpc remote procedure call handler for Ext.direct requests.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/merb-ext-direct/mixins/remoting_provider.rb', line 25

def rpc
    if !request.ajax? && !params["extAction"]
        return "Ext::Direct::RemotingProvider#rpc -- This method is an ajax-handler only"
    end

    is_form = false
    is_upload = false
    if params["extAction"] && params["extMethod"]
        # create fake response here.
        is_form = true
        is_upload = params.delete("extUpload") == 'true'

        request = {
            "xcontroller" => params.delete("extAction"),
            "xaction" => params.delete("extMethod"),
            "type" => "rpc",
            "id" => params.delete("id"),
            "tid" => params.delete("extTID"),
            "format" => params.delete("format"),
            "data" => params
        }
        params.delete('controller')
        params.delete('action')

        res = "<html><body><textarea>#{handle_request(request).gsub(/&quot;/, "\&quot;")}</textarea></body></html>"
        Merb.logger.info('OUTPUT: ' + res)
        res

    elsif (params[:inflated_object])
        # multiple requests found.  I'm not sure how this "inflated_object" mechanism works.  This is Merb magic?
        responses = []
        params[:inflated_object].each do |req|
            responses << handle_request(req)
        end
        # controllers always return a string, so each response has already been json-encoded.
        # since we're dealing with multiple requests here, we have to manually string-concat-wrap the retured
        # string-of-json.
        #
        return "[" + responses.join(',') + "]"
    else
        return handle_request(params)
    end
end