mario 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ vendor
23
+ Gemfile
24
+ Gemfile.lock
25
+ .bundle
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 John Bender
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = mario
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 John Bender. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mario"
8
+ gem.summary = %Q{ Mario is a collection of utilities for dealing with platform specific issues }
9
+ gem.description = gem.summary
10
+ gem.email = "john.m.bender@gmail.com"
11
+ gem.homepage = "http://github.com/johnbender/mario"
12
+ gem.authors = ["John Bender"]
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
+ gem.add_development_dependency "mocha"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+
23
+ #
24
+ # TODO add platform specific checks for easy verification on each platform
25
+ #
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+ task :test => :check_dependencies
48
+
49
+ task :default => :test
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "mario #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
@@ -0,0 +1,91 @@
1
+ module Mario
2
+ class Platform
3
+ @@forced = nil
4
+
5
+ class << self
6
+ def nix_group
7
+ { :cygwin => 'cygwin',
8
+ :linux => 'linux',
9
+ :osx => 'darwin',
10
+ :solaris => 'solaris',
11
+ :bsd => 'bsd'}
12
+ end
13
+
14
+ def windows_group
15
+ { :winnt => 'mswin',
16
+ :win7 => 'mingw' }
17
+ end
18
+
19
+ def targets
20
+ nix_group.merge(windows_group)
21
+ end
22
+
23
+ def linux?
24
+ check_os :linux
25
+ end
26
+
27
+ def osx?
28
+ check_os :osx
29
+ end
30
+
31
+ def solaris?
32
+ check_os :solaris
33
+ end
34
+
35
+ def bsd?
36
+ check_os :bsd
37
+ end
38
+
39
+ def cygwin?
40
+ check_os :cygwin
41
+ end
42
+
43
+ def win7?
44
+ check_os :win7
45
+ end
46
+
47
+ def winnt?
48
+ check_os :winnt
49
+ end
50
+
51
+ def nix?
52
+ check_group nix_group
53
+ end
54
+
55
+ def windows?
56
+ check_group windows_group
57
+ end
58
+
59
+ def check_group(group)
60
+ group.each do |key, value|
61
+ return true if check_os key
62
+ end
63
+ false
64
+ end
65
+
66
+ alias_method :darwin?, :osx?
67
+
68
+ def os
69
+ @@forced || Config::CONFIG['target_os']
70
+ end
71
+
72
+ def check_os(key)
73
+ os.downcase.include?(targets[key])
74
+ end
75
+
76
+ def forced=(val)
77
+ logger.warn("Mario::Platform.os will now report as #{val}")
78
+ @@forced=val
79
+ end
80
+
81
+ def forced
82
+ @@forced
83
+ end
84
+
85
+ def logger(out=STDOUT)
86
+ @@logger ||= Logger.new(STDOUT)
87
+ @@logger
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,24 @@
1
+ module Mario
2
+ class Toolbelt
3
+ class << self
4
+
5
+ # Stolen shamelessly from Mitchell Hashimoto's Virtualbox gem!
6
+ # TODO more research
7
+ def shell_escape_path(str)
8
+ if Platform.windows?
9
+ #Wrap windows paths with white space in quotes
10
+ str = "\"#{str}\"" if str =~ /\s/
11
+ return str
12
+ end
13
+
14
+ str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').
15
+ gsub(/\n/, "'\n'").
16
+ sub(/^$/, "''")
17
+ end
18
+
19
+ # Mario would just jumpt to escape a shell's path
20
+ alias_method :jump, :shell_escape_path
21
+
22
+ end
23
+ end
24
+ end
data/lib/mario.rb ADDED
@@ -0,0 +1,6 @@
1
+
2
+ require 'rbconfig'
3
+ require 'logger'
4
+ lib = File.dirname(__FILE__)
5
+ %w{ mario/platform mario/toolbelt }.each { |file| require File.expand_path(file, lib) }
6
+
data/test/helper.rb ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require File.expand_path('../.bundle/environment', __FILE__)
3
+ rescue LoadError
4
+ require "rubygems"
5
+ require "bundler"
6
+ Bundler.setup
7
+ end
8
+
9
+ begin
10
+ require 'ruby-debug'
11
+ rescue LoadError; end
12
+
13
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'mario')
14
+ require 'test/unit'
15
+ require 'mocha'
16
+ require 'shoulda'
17
+
18
+ class Test::Unit::TestCase
19
+ def setup
20
+ logger = mock('logger')
21
+ Mario::Platform.stubs(:logger).returns(logger)
22
+ logger.stubs(:warn)
23
+ end
24
+ end
25
+
26
+
@@ -0,0 +1,74 @@
1
+ require 'helper'
2
+
3
+ class TestPlatform < Test::Unit::TestCase
4
+ context "Mario's jumping platforms" do
5
+
6
+ context 'when testing for *nix' do
7
+ should 'return true for all known variants' do
8
+ Mario::Platform::nix_group.each do |key, value|
9
+ assert check_nix(key)
10
+ end
11
+ end
12
+
13
+ should 'return false for all other' do
14
+ # TODO use relative complement of nix_group in targets
15
+ Mario::Platform::windows_group.each do |key, value|
16
+ assert !check_nix(key)
17
+ end
18
+ end
19
+ end
20
+
21
+ context 'when testing for windows' do
22
+ should 'only return true for all known variants' do
23
+ Mario::Platform.windows_group.each do |key, value|
24
+ assert check_win(key)
25
+ end
26
+ end
27
+
28
+ should 'return false for others' do
29
+ # TODO use relative complement of windows_group in targets
30
+ Mario::Platform.nix_group.each do |key, value|
31
+ assert !check_win(key)
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'when checking any os with abnormal target strings' do
37
+ should 'handle extranious characters' do
38
+ assert check_nix('12%&linux%#$')
39
+ end
40
+
41
+ should 'handle capitals' do
42
+ assert check_nix('LINUX')
43
+ end
44
+ end
45
+
46
+ context 'when checking an os' do
47
+ should 'respond positively to each os listed in targets' do
48
+ Mario::Platform.targets.each do |key, value|
49
+ Mario::Platform.forced = value
50
+ assert Mario::Platform.send(key.to_s + '?')
51
+ end
52
+ end
53
+ end
54
+
55
+ context 'when forcing a target os' do
56
+ should 'log at a warning level' do
57
+ logger = mock('logger')
58
+ Mario::Platform.expects(:logger).returns(logger)
59
+ logger.expects(:warn).with { |string| string =~ /foo/ }
60
+ Mario::Platform.forced = 'foo'
61
+ end
62
+ end
63
+ end
64
+
65
+ def check_nix(force)
66
+ Mario::Platform.forced = Mario::Platform.targets[force]
67
+ Mario::Platform.nix?
68
+ end
69
+
70
+ def check_win(force)
71
+ Mario::Platform.forced = Mario::Platform::targets[force]
72
+ Mario::Platform.windows?
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ class TestPlatform < Test::Unit::TestCase
4
+ context "Mario's toolbelt" do
5
+ context "on all platforms" do
6
+ should "escape weird characters in paths meant for a shell command " do
7
+ %w( $ @ % ^ & * ).each do |char|
8
+ assert Mario::Toolbelt.shell_escape_path(char).include?('\\')
9
+ end
10
+ end
11
+ end
12
+
13
+ context "on windows" do
14
+ setup do
15
+ Mario::Platform.forced = Mario::Platform.targets[:win7]
16
+ end
17
+
18
+ should "wrap file paths with white space in double quotes" do
19
+ result = Mario::Toolbelt.shell_escape_path(' something serious ')
20
+ assert result =~ /^"/
21
+ assert result =~ /"$/
22
+ end
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mario
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - John Bender
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Mario is a collection of utilities for dealing with platform specific issues
36
+ email: john.m.bender@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - lib/mario.rb
51
+ - lib/mario/platform.rb
52
+ - lib/mario/toolbelt.rb
53
+ - test/helper.rb
54
+ - test/mario/test_plaform.rb
55
+ - test/mario/test_toolbelt.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/johnbender/mario
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Mario is a collection of utilities for dealing with platform specific issues
84
+ test_files:
85
+ - test/helper.rb
86
+ - test/mario/test_plaform.rb
87
+ - test/mario/test_toolbelt.rb