Skip to content

Commit ae4729f

Browse files
author
kselvraj
committed
Added temp_folder support
1 parent 242d172 commit ae4729f

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

lib/ohloh_scm/activity.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ class Activity
55
include OhlohScm::System
66
extend Forwardable
77
def_delegators :@core, :scm, :status
8-
def_delegators :scm, :url
8+
def_delegators :scm, :url, :temp_dir
99

1010
def initialize(core)
1111
@core = core
1212
end
1313

1414
def log_filename
15-
File.join(Dir.tmpdir, url.gsub(/\W/, '') + '.log')
15+
tmp_dir = temp_dir || Dir.tmpdir
16+
File.join(tmp_dir, url.gsub(/\W/, '') + '.log')
1617
end
1718

1819
def tags; end

lib/ohloh_scm/core.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ def initialize(scm_type, url, branch_name, username, password)
1818
@status = OhlohScm.const_get(scm_class_name)::Status.new(self)
1919
@validation = OhlohScm.const_get(scm_class_name)::Validation.new(self)
2020
end
21+
22+
def temp_dir=(tmp_dir)
23+
@scm.temp_dir = tmp_dir
24+
end
2125
end
2226
end

lib/ohloh_scm/git_svn/activity.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module OhlohScm
44
module GitSvn
55
class Activity < OhlohScm::Activity
6-
def_delegators :scm, :url
6+
def_delegators :scm, :url, :temp_dir
77

88
def commit_count(opts = {})
99
cmd = "#{after_revision(opts)} | grep -E -e '^r[0-9]+.*lines$' | wc -l"
@@ -49,7 +49,8 @@ def open_log_file(opts = {})
4949
end
5050

5151
def log_filename
52-
File.join('/tmp', url.gsub(/\W/, '') + '.log')
52+
tmp_dir = temp_dir || '/tmp'
53+
File.join(tmp_dir, url.gsub(/\W/, '') + '.log')
5354
end
5455

5556
def after_revision(opts)

lib/ohloh_scm/scm.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Scm
66
extend Forwardable
77
def_delegators :@core, :status, :activity
88
attr_reader :url, :username, :password
9-
attr_accessor :branch_name
9+
attr_accessor :branch_name, :temp_dir
1010

1111
def initialize(core:, url:, branch_name: nil, username: nil, password: nil)
1212
@core = core

spec/ohloh_scm/activity_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Activity' do
6+
describe 'log_filename' do
7+
it 'should return system tmp dir path' do
8+
core = get_core(:git)
9+
scm = OhlohScm::Activity.new(core)
10+
scm.log_filename.must_equal "#{Dir.tmpdir}/foobar.log"
11+
end
12+
13+
it 'should return temp folder path' do
14+
core = get_core(:git)
15+
core.temp_dir = '/test'
16+
scm = OhlohScm::Activity.new(core)
17+
scm.log_filename.must_equal '/test/foobar.log'
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)