Class: Rack::Xrevision

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/xrevision.rb,
lib/rack/xrevision/version.rb

Constant Summary collapse

REVISION_FILE_NAME =
'REVISION'
VERSION =
'0.1'

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Xrevision

Returns a new instance of Xrevision.



4
5
6
7
8
# File 'lib/rack/xrevision.rb', line 4

def initialize(app, options={})
  @app = app
  @app_path = options[:app_path] || Dir.pwd
  @revision_file_name = options[:file_name] || REVISION_FILE_NAME
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
# File 'lib/rack/xrevision.rb', line 10

def call(env)
  status, headers, response = @app.call(env)
  headers['X-Rev'] = rev_id if rev_id
  [status, headers, response]
end

#rev_idObject



16
17
18
19
20
# File 'lib/rack/xrevision.rb', line 16

def rev_id
  @rev_id ||= begin
    load_from_file || load_from_git
  end
end

#revision_file_pathObject



22
23
24
# File 'lib/rack/xrevision.rb', line 22

def revision_file_path
  "#{@app_path}/#{@revision_file_name}"
end