Class: Hoverboard::RackApp
- Inherits:
-
Object
- Object
- Hoverboard::RackApp
- Defined in:
- lib/hoverboard/rack_app.rb
Constant Summary collapse
- PT =
PivotalTracker
Instance Method Summary collapse
- #accept(pivotal_story_id) ⇒ Object
- #call(env) ⇒ Object
- #config ⇒ Object
- #dev_mode(req) ⇒ Object
- #env?(env) ⇒ Boolean
- #haml(file_name, options = {}) ⇒ Object
- #index ⇒ Object
-
#initialize(app) ⇒ RackApp
constructor
A new instance of RackApp.
- #project ⇒ Object
- #reject(pivotal_story_id, reason = nil) ⇒ Object
- #render(html) ⇒ Object
- #root ⇒ Object
- #template_root ⇒ Object
Constructor Details
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 |
#config ⇒ Object
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
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, ={}) template = (template_root + "#{file_name}.haml").read render Haml::Engine.new(template).render(self) end |
#index ⇒ Object
50 51 52 53 |
# File 'lib/hoverboard/rack_app.rb', line 50 def index @stories = project.stories.all(:current_state => "delivered") haml "index" end |
#project ⇒ Object
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 |
#root ⇒ Object
81 82 83 |
# File 'lib/hoverboard/rack_app.rb', line 81 def root @root ||= Pathname("../../../").(__FILE__) end |
#template_root ⇒ Object
85 86 87 |
# File 'lib/hoverboard/rack_app.rb', line 85 def template_root @template_root ||= root+'lib/hoverboard/templates' end |