Class: VueCK::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/plugin.rb

Constant Summary collapse

REQUEST_MAP =
{
    "/vue/vue.js" => {
        file: "vue.js",
        content_type: "application/javascript"
    },
    "/vue/vue.css" => {
        file: "vue.css",
        content_type: "text/css"
    }
}

Instance Method Summary collapse

Constructor Details

#initialize(app = {}) ⇒ Plugin

Returns a new instance of Plugin.



14
15
16
# File 'lib/plugin.rb', line 14

def initialize(app={})
    @app = app
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/plugin.rb', line 18

def call(env)
    return @app.call(env) unless env["REQUEST_METHOD"] == "GET"
    path = env["PATH_INFO"]
    return @app.call(env) unless REQUEST_MAP[path]
    vueck = VueCK.new REQUEST_MAP[path][:file]
    content = vueck.serve_file
    response(content, path)
end

#response(content, path) ⇒ Object



27
28
29
30
31
32
# File 'lib/plugin.rb', line 27

def response(content, path)
    ["200", {
        "Content-Type"   => REQUEST_MAP[path][:content_type],
        "Content-Length" => content.size.to_s },
        [content]]
end