Class: Wedge::Middleware::Responder
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#env ⇒ Object
Returns the value of attribute env.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#opal ⇒ Object
readonly
Returns the value of attribute opal.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#skip_call ⇒ Object
readonly
Returns the value of attribute skip_call.
-
#wedge_path ⇒ Object
Returns the value of attribute wedge_path.
Instance Method Summary collapse
-
#initialize(app, opal, scope, skip_call, env) ⇒ Responder
constructor
A new instance of Responder.
- #respond ⇒ Object
- #wedge(*args, &block) ⇒ Object
Constructor Details
#initialize(app, opal, scope, skip_call, env) ⇒ Responder
Returns a new instance of Responder.
59 60 61 |
# File 'lib/wedge/middleware.rb', line 59 def initialize(app, opal, scope, skip_call, env) @app = app; @opal = opal; @scope = (scope || self); @skip_call = skip_call; @env = env end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
57 58 59 |
# File 'lib/wedge/middleware.rb', line 57 def app @app end |
#env ⇒ Object
Returns the value of attribute env.
57 58 59 |
# File 'lib/wedge/middleware.rb', line 57 def env @env end |
#extension ⇒ Object
Returns the value of attribute extension.
57 58 59 |
# File 'lib/wedge/middleware.rb', line 57 def extension @extension end |
#opal ⇒ Object (readonly)
Returns the value of attribute opal.
56 57 58 |
# File 'lib/wedge/middleware.rb', line 56 def opal @opal end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
56 57 58 |
# File 'lib/wedge/middleware.rb', line 56 def scope @scope end |
#skip_call ⇒ Object (readonly)
Returns the value of attribute skip_call.
56 57 58 |
# File 'lib/wedge/middleware.rb', line 56 def skip_call @skip_call end |
#wedge_path ⇒ Object
Returns the value of attribute wedge_path.
57 58 59 |
# File 'lib/wedge/middleware.rb', line 57 def wedge_path @wedge_path end |
Instance Method Details
#respond ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/wedge/middleware.rb', line 63 def respond if path =~ Wedge.assets_url_regex @wedge_path, @extension = $1, $2 if extension == 'call' return response.finish if skip_call body, headers, status = [], {}, 200 body_data = request.body.read data = request.params begin # try json data.merge!(body_data ? JSON.parse(body_data) : {}) rescue begin # try form data data.merge!(body_data ? Rack::Utils.parse_query(body_data) : {}) rescue # no data end end data = data.indifferent name = data.delete(:__wedge_name__) method_called = data.delete(:__wedge_method__) method_args = data.delete(:__wedge_args__) if wedge_path == 'wedge/list_assets' res = { urls: Wedge.get_asset_urls(data[:path_name]), code: Wedge::Opal::Processor.load_asset_code(Wedge.config.opal[:server].sprockets, data[:path_name]) } elsif method_args == '__wedge_data__' && data method_args = [data] res = Wedge.scope!(scope, method_called)[name].send(method_called, *method_args) || '' else # This used to send things like init, we need a better way to # send client config data to the server # res = scope.wedge(name, data).send(method_called, *method_args) || '' res = Wedge.scope!(scope, method_called)[name].send(method_called, *method_args) || '' end # discuss: I don't think we should update the csrf token # every ajax call # headers["WEDGE-CSRF-TOKEN"] = self.csrf_token if self.methods.include? :csrf_token if res.is_a? Hash headers["Content-Type"] = 'application/json; charset=UTF-8' body << res.to_json else body << res.to_s end [status, headers, body] else if Wedge.config.debug if path[@opal[:maps_prefix]] @opal[:maps_app].call env else e = env.deep_dup e['PATH_INFO'] = env['PATH_INFO'].sub "#{Wedge.config.assets_url}/", '' @opal[:sprockets].call e end else @opal[:server].call env end end else response.finish end end |