Class: Rack::RacksonFive

Inherits:
Struct
  • Object
show all
Defined in:
lib/rack/rackson-five.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RacksonFive

Returns a new instance of RacksonFive.



3
4
5
# File 'lib/rack/rackson-five.rb', line 3

def initialize(app)
  @app = app
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/rack/rackson-five.rb', line 2

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/rack/rackson-five.rb', line 7

def call(env)
  request = Rack::Request.new(env)
  if request.path_info =~ /^\/rackson-five\/(.+)$/
    rackson_five_request($1)
  else
    jacksonify(env)
  end
end

#jacksonify(env) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack/rackson-five.rb', line 26

def jacksonify(env)
  status, headers, response = @app.call(env)
  if headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
    body = ""
    response.each { |part| body << part }
    index = body.rindex("</body>")
    if index
        body.insert(index, '<img src="/rackson-five/rackson-five.png" style="position:absolute; bottom:0; right:0;" /><embed src="/rackson-five/rackson-five.mid" autostart="true" loop="-1" hidden="true" />')
      headers["Content-Length"] = body.length.to_s
      response = [body]
    end
  end
  [status, headers, response]
end

#memberObject



41
42
43
44
# File 'lib/rack/rackson-five.rb', line 41

def member
  all_members = [:group, :micheal, :tito, :jermaine, :randy, :marlon, :jackie]
  available_members = all_members - (all_members - options[:members])
end

#rackson_five_request(path) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/rack/rackson-five.rb', line 16

def rackson_five_request(path)
  if path == "rackson-five.png"
    data = ::File.open(::File.join(::File.dirname(__FILE__),"images","group.png"),"r").read
    [200, {"Content-Type" => "image/png"},data]
  elsif path == "rackson-five.mid"
    data = ::File.open(::File.join(::File.dirname(__FILE__),"midi","want_you_back.mid"),"r").read
    [200, {"Content-Type" => "audio/midi"},data]
  end
end