From b23da2d383effec160ddf22725a330885077f89b Mon Sep 17 00:00:00 2001 From: ahoward Date: Sat, 7 Dec 2013 15:05:56 -0700 Subject: handle silly hostnames --- Rakefile | 1 + lib/systemu.rb | 14 ++++++++++++-- pkg/systemu-2.6.0.gem | Bin 0 -> 13824 bytes systemu.gemspec | 3 ++- test/systemu_test.rb | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 pkg/systemu-2.6.0.gem diff --git a/Rakefile b/Rakefile index fdf4f20..d103852 100644 --- a/Rakefile +++ b/Rakefile @@ -118,6 +118,7 @@ task :gemspec do spec.platform = Gem::Platform::RUBY spec.summary = #{ lib.inspect } spec.description = #{ description.inspect } + spec.license = "same as ruby's" spec.files =\n#{ files.sort.pretty_inspect } spec.executables = #{ executables.inspect } diff --git a/lib/systemu.rb b/lib/systemu.rb index 64cfbcd..04c24d9 100644 --- a/lib/systemu.rb +++ b/lib/systemu.rb @@ -14,7 +14,7 @@ class SystemUniversal # # constants # - SystemUniversal::VERSION = '2.5.2' unless SystemUniversal.send(:const_defined?, :VERSION) + SystemUniversal::VERSION = '2.6.0' unless SystemUniversal.send(:const_defined?, :VERSION) def SystemUniversal.version() SystemUniversal::VERSION end def version() SystemUniversal::VERSION end # @@ -217,11 +217,21 @@ class SystemUniversal end end + def slug_for(*args) + options = args.last.is_a?(Hash) ? args.pop : {} + join = (options[:join] || options['join'] || '_').to_s + string = args.flatten.compact.join(join) + words = string.to_s.scan(%r|[/\w]+|) + words.map!{|word| word.gsub %r|[^/0-9a-zA-Z_-]|, ''} + words.delete_if{|word| word.nil? or word.strip.empty?} + words.join(join).downcase.gsub('/', (join * 2)) + end + def tmpdir d = Dir.tmpdir, max = 42, &b i = -1 and loop{ i += 1 - tmp = File.join d, "systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }" + tmp = File.join(d, slug_for("systemu_#{ @host }_#{ @ppid }_#{ @pid }_#{ rand }_#{ i += 1 }")) begin Dir.mkdir tmp diff --git a/pkg/systemu-2.6.0.gem b/pkg/systemu-2.6.0.gem new file mode 100644 index 0000000..e2d5587 Binary files /dev/null and b/pkg/systemu-2.6.0.gem differ diff --git a/systemu.gemspec b/systemu.gemspec index 6d0b469..23a6241 100644 --- a/systemu.gemspec +++ b/systemu.gemspec @@ -3,10 +3,11 @@ Gem::Specification::new do |spec| spec.name = "systemu" - spec.version = "2.5.2" + spec.version = "2.6.0" spec.platform = Gem::Platform::RUBY spec.summary = "systemu" spec.description = "description: systemu kicks the ass" + spec.license = "same as ruby's" spec.files = ["LICENSE", diff --git a/test/systemu_test.rb b/test/systemu_test.rb index 19fac1d..6d4bf2b 100644 --- a/test/systemu_test.rb +++ b/test/systemu_test.rb @@ -17,6 +17,20 @@ Testing SystemU do assert{ stdout == stdin } end + testing 'silly hostnames' do + host = SystemU.instance_variable_get('@host') + silly_hostname = "silly's hostname with spaces" + begin + SystemU.instance_variable_set('@host', silly_hostname) + assert{ SystemU.instance_variable_get('@host') == silly_hostname } + stdin = '42' + status, stdout, stderr = assert{ systemu :bin/:cat, :stdin => stdin } + assert{ status == 0 } + ensure + assert{ SystemU.instance_variable_set('@host', host) } + end + end + end -- cgit v1.2.1