Class: HighCarb::RackApp

Inherits:
Object
  • Object
show all
Includes:
AssetsController, SlidesController, ViewsController
Defined in:
lib/highcarb/rack_app.rb

Constant Summary

Constants included from ViewsController

ViewsController::DefaultViewsPath

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ViewsController

#render_view

Methods included from AssetsController

#assets

Methods included from SlidesController

#load_asset, #load_snippet, #slides

Constructor Details

#initialize(command) ⇒ RackApp

Returns a new instance of RackApp.



25
26
27
28
29
30
31
32
# File 'lib/highcarb/rack_app.rb', line 25

def initialize(command)
  @command = command
  @root = Pathname.new(command.args.first)
  @assets_root = @root.join("./assets")

  config_path = @root.join("config.yml")
  @config = config_path.exist? ? YAML.load(config_path.read) : {}
end

Instance Attribute Details

#assets_rootObject (readonly)

Returns the value of attribute assets_root.



22
23
24
# File 'lib/highcarb/rack_app.rb', line 22

def assets_root
  @assets_root
end

#commandObject (readonly)

Returns the value of attribute command.



20
21
22
# File 'lib/highcarb/rack_app.rb', line 20

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/highcarb/rack_app.rb', line 23

def config
  @config
end

#rootObject (readonly)

Returns the value of attribute root.



21
22
23
# File 'lib/highcarb/rack_app.rb', line 21

def root
  @root
end

Instance Method Details

#call(env) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/highcarb/rack_app.rb', line 42

def call(env)
  catch(:response) do
    case env["PATH_INFO"]
    when "/slides"
      slides

    when /\A\/assets\/(.*)\Z/
      assets $1

    when "/remote"
      render_view "remote"

    when "/"
      render_view "index"

    else
      not_found! env["PATH_INFO"]
    end
  end
end

#not_found!(path) ⇒ Object



38
39
40
# File 'lib/highcarb/rack_app.rb', line 38

def not_found!(path)
  plain_response! 404, "Object #{path} not found"
end

#plain_response!(status, content) ⇒ Object



34
35
36
# File 'lib/highcarb/rack_app.rb', line 34

def plain_response!(status, content)
  throw :response, [status, {'Content-Type' => 'text/plain'}, content]
end