lib/stoor/git_config.rb in stoor-0.1.4 vs lib/stoor/git_config.rb in stoor-0.1.5

- old
+ new

@@ -1,24 +1,26 @@ module Stoor class GitConfig - def initialize(app); @app = app; end + attr_reader :repo_path + def initialize(app, repo_path = nil) + @app, @repo_path = app, repo_path + end + def call(env) @request = Rack::Request.new(env) unless @request.session['gollum.author'] - if ENV['WIKI_PATH_IN_USE'] - if name = git_option_value('user.name') - if email = git_option_value('user.email') - @request.session['gollum.author'] = { :name => name, :email => email } - end - end + if repo_path && (name = git_option_value('user.name')) && (email = git_option_value('user.email')) + @request.session['gollum.author'] = { :name => name, :email => email } end end @app.call(env) end + private + def git_option_value(option) - `cd #{ENV['WIKI_PATH_IN_USE']} && git config --get #{option}`.strip - rescue + @repo ||= Grit::Repo.new(repo_path) + @repo.config[option] end end end