Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# A Spin::Socket wraps a Unix socket | ||
|
||
require 'tempfile' # for Dir::tmpdir | ||
require 'digest/md5' | ||
|
||
module Spin | ||
class Socket | ||
# This returns a path in the top level of the tmpdir with | ||
# a name unique to spin and the pwd. | ||
def self.filepath | ||
slug = Digest::MD5.hexdigest ['spin', Dir.pwd].join('-') | ||
[Dir::tmpdir, slug].join('/') | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'minitest/autorun' | ||
require_relative '../../lib/spin/socket' | ||
|
||
describe Spin::Socket do | ||
describe '#filepath' do | ||
before do | ||
@filepath = Spin::Socket.filepath | ||
end | ||
|
||
it 'is in the tmpdir' do | ||
p @filepath | ||
@filepath.must_include Dir::tmpdir | ||
end | ||
|
||
it "includes a digested version of 'spin' and the pwd" do | ||
@filepath.must_include digest("spin-#{Dir.pwd}") | ||
end | ||
|
||
def digest(string) | ||
Digest::MD5.hexdigest(string) | ||
end | ||
end | ||
end | ||
|