Class: Hoverboard::RackApp

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

Constant Summary collapse

PT =
PivotalTracker

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackApp

Returns a new instance of RackApp.



11
12
13
14
# File 'lib/hoverboard/rack_app.rb', line 11

def initialize(app)
  @app             = app
  PT::Client.token = config.pivotal_tracker_token
end

Instance Method Details

#accept(pivotal_story_id) ⇒ Object



55
56
57
58
59
# File 'lib/hoverboard/rack_app.rb', line 55

def accept(pivotal_story_id)
  story = project.stories.find(pivotal_story_id.to_i)
  story.update(:current_state => 'accepted')
  render "Accepted"
end

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hoverboard/rack_app.rb', line 16

def call(env)
  req = Rack::Request.new(env)

  if env?('development') && dev_rsp = dev_mode(req)
    return dev_rsp
  end

  case req.path
  when %r{^/hoverboard$}
    index
  when %r{^/hoverboard/(.*)/accept}
    accept $1
  when %r{^/hoverboard/(.*)/reject}
    reject $1, req.params["reason"]
  else
    @app.call(env)
  end
end

#configObject



89
90
91
# File 'lib/hoverboard/rack_app.rb', line 89

def config
  Hoverboard.configuration
end

#dev_mode(req) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/hoverboard/rack_app.rb', line 39

def dev_mode(req)
  case req.path
  when %r{^/hoverboard/hoverboard.css$}
    [200, {"Content-Type" => "text/css"}, [ (root + 'lib/hoverboard/stylesheets/hoverboard.css').read ]]

  when %r{^/hoverboard/hoverboard.js$}
    [200, {"Content-Type" => "text/javascript"}, [ (root + 'lib/hoverboard/javascript/hoverboard.js').read ]]

  end
end

#env?(env) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/hoverboard/rack_app.rb', line 35

def env?(env)
  (ENV['RACK_ENV'] || (defined?(Rails) && Rails.env)) == env
end

#haml(file_name, options = {}) ⇒ Object



72
73
74
75
# File 'lib/hoverboard/rack_app.rb', line 72

def haml(file_name, options={})
  template = (template_root + "#{file_name}.haml").read
  render Haml::Engine.new(template).render(self)
end

#indexObject



50
51
52
53
# File 'lib/hoverboard/rack_app.rb', line 50

def index
  @stories = project.stories.all(:current_state => "delivered")
  haml "index"
end

#projectObject



68
69
70
# File 'lib/hoverboard/rack_app.rb', line 68

def project
  @project ||= PT::Project.find(config.pivotal_tracker_project)
end

#reject(pivotal_story_id, reason = nil) ⇒ Object



61
62
63
64
65
66
# File 'lib/hoverboard/rack_app.rb', line 61

def reject(pivotal_story_id, reason=nil)
  story = project.stories.find(pivotal_story_id.to_i)
  story.update(:current_state => 'rejected')
  story.notes.create(:text => "[rejected] #{reason}")
  render "Rejected"
end

#render(html) ⇒ Object



77
78
79
# File 'lib/hoverboard/rack_app.rb', line 77

def render(html)
  [200, {"Content-Type" => "text/html"}, [html]]
end

#rootObject



81
82
83
# File 'lib/hoverboard/rack_app.rb', line 81

def root
  @root ||= Pathname("../../../").expand_path(__FILE__)
end

#template_rootObject



85
86
87
# File 'lib/hoverboard/rack_app.rb', line 85

def template_root
  @template_root ||= root+'lib/hoverboard/templates'
end