playpen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2010-10-07
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ .autotest
2
+ CHANGELOG.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ ext/playpen/extconf.rb
7
+ ext/playpen/playpen.c
8
+ lib/playpen.rb
9
+ test/test_playpen.rb
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = playpen
2
+
3
+ * http://github.com/tenderlove/playpen
4
+
5
+ == DESCRIPTION:
6
+
7
+ Playpen wraps OS X sandbox api with a loving embrace. Playpen provides the
8
+ same API that the Sandbox class in MacRuby provides.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * AWESOME
13
+ * MANY
14
+
15
+ == SYNOPSIS:
16
+
17
+ Playpen.no_internet.apply!
18
+
19
+ == REQUIREMENTS:
20
+
21
+ * OS X 10.5 or greater
22
+
23
+ == INSTALL:
24
+
25
+ * gem install playpen
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2010 Aaron Patterson, Evan Phoenix
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ gem 'rake-compiler', '>= 0.4.1'
6
+ require "rake/extensiontask"
7
+
8
+ Hoe.spec 'playpen' do
9
+ developer('Aaron Patterson', 'aaron@tenderlovemaking.com')
10
+ developer('Evan Phoenix', 'evan@fallingsnow.net')
11
+ self.readme_file = 'README.rdoc'
12
+ self.history_file = 'CHANGELOG.rdoc'
13
+ self.extra_rdoc_files = FileList['*.rdoc']
14
+ self.spec_extras = { :extensions => ["ext/playpen/extconf.rb"] }
15
+
16
+ Rake::ExtensionTask.new "playpen", spec do |ext|
17
+ ext.lib_dir = File.join(*['lib', 'playpen', ENV['FAT_DIR']].compact)
18
+ end
19
+ end
20
+
21
+ task :test => :compile
22
+
23
+ # vim: syntax=ruby
@@ -0,0 +1,13 @@
1
+ # :stopdoc:
2
+
3
+ require 'mkmf'
4
+
5
+ def asplode(lib)
6
+ abort "-----\n#{lib} is missing."
7
+ end
8
+
9
+ asplode "sandbox" unless find_header('sandbox.h')
10
+ asplode "sandbox" unless find_library('sandbox', 'sandbox_init')
11
+
12
+ create_makefile('playpen/playpen')
13
+ # :startdoc:
@@ -0,0 +1,24 @@
1
+ #include <ruby.h>
2
+ #include <sandbox.h>
3
+
4
+ static VALUE playpen_init(VALUE self, VALUE name, VALUE flags)
5
+ {
6
+ char * error;
7
+ if(sandbox_init(StringValuePtr(name), NUM2INT(flags), &error) < 0) {
8
+ rb_raise(rb_eRuntimeError, "%s", error);
9
+ }
10
+
11
+ return self;
12
+ }
13
+
14
+ void Init_playpen()
15
+ {
16
+ VALUE cPlaypen = rb_define_class("Playpen", rb_cObject);
17
+ rb_define_const(cPlaypen, "SANDBOX_NAMED", INT2NUM(SANDBOX_NAMED));
18
+ rb_define_const(cPlaypen, "NO_INTERNET", rb_str_new2(kSBXProfileNoInternet));
19
+ rb_define_const(cPlaypen, "NO_NETWORK", rb_str_new2(kSBXProfileNoNetwork));
20
+ rb_define_const(cPlaypen, "NO_WRITE", rb_str_new2(kSBXProfileNoWrite));
21
+ rb_define_const(cPlaypen, "TEMP_ONLY_WRITE", rb_str_new2(kSBXProfileNoWriteExceptTemporary));
22
+ rb_define_const(cPlaypen, "COMPUTATION_ONLY", rb_str_new2(kSBXProfilePureComputation));
23
+ rb_define_singleton_method(cPlaypen, "sandbox_init", playpen_init, 2);
24
+ }
data/lib/playpen.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'playpen/playpen'
2
+
3
+ class Playpen
4
+ VERSION = '1.0.0'
5
+
6
+ def initialize
7
+ @commands = []
8
+ end
9
+
10
+ def apply!
11
+ @commands.each do |command|
12
+ self.class.sandbox_init(command, Playpen::SANDBOX_NAMED)
13
+ end
14
+ end
15
+
16
+ constants.each do |const|
17
+ class_eval(<<-eoruby, __FILE__, __LINE__ + 1)
18
+ def #{const.to_s.downcase}
19
+ @commands << #{const}
20
+ self
21
+ end
22
+
23
+ def self.#{const.to_s.downcase}
24
+ new.#{const.to_s.downcase}
25
+ end
26
+ eoruby
27
+ end
28
+
29
+ class << self
30
+ alias :no_writes :no_write
31
+ alias :temporary_writes :temp_only_write
32
+ alias :pure_computation :computation_only
33
+ end
34
+
35
+ alias :no_writes :no_write
36
+ alias :temporary_writes :temp_only_write
37
+ alias :pure_computation :computation_only
38
+ end
@@ -0,0 +1,70 @@
1
+ require "test/unit"
2
+ require "playpen"
3
+
4
+ class TestPlaypen < Test::Unit::TestCase
5
+ def test_constant_exists
6
+ assert Playpen::SANDBOX_NAMED, 'yay!'
7
+ end
8
+
9
+ def test_no_internet
10
+ assert Playpen::NO_INTERNET, "woop-be-doop!"
11
+ end
12
+
13
+ def test_no_network
14
+ assert Playpen::NO_NETWORK, "woop-be-doop!"
15
+ end
16
+
17
+ def test_no_write
18
+ assert Playpen::NO_WRITE, "woop-be-doop!"
19
+ end
20
+
21
+ def test_temp_only_write
22
+ assert Playpen::TEMP_ONLY_WRITE, "woop-be-doop!"
23
+ end
24
+
25
+ def test_computation_only
26
+ assert Playpen::COMPUTATION_ONLY, "woop-be-doop!"
27
+ end
28
+
29
+ def test_sanity
30
+ Playpen.sandbox_init(Playpen::NO_INTERNET, Playpen::SANDBOX_NAMED)
31
+ end
32
+
33
+ def test_chaining
34
+ x = fake_pp
35
+ x.no_internet.no_network.no_writes.temporary_writes.pure_computation.apply!
36
+ assert_equal([
37
+ [Playpen::NO_INTERNET, Playpen::SANDBOX_NAMED],
38
+ [Playpen::NO_NETWORK, Playpen::SANDBOX_NAMED],
39
+ [Playpen::NO_WRITE, Playpen::SANDBOX_NAMED],
40
+ [Playpen::TEMP_ONLY_WRITE, Playpen::SANDBOX_NAMED],
41
+ [Playpen::COMPUTATION_ONLY, Playpen::SANDBOX_NAMED],
42
+ ], x.args)
43
+ end
44
+
45
+ def test_class_methods
46
+ {
47
+ 'no_internet' => Playpen::NO_INTERNET,
48
+ 'no_network' => Playpen::NO_NETWORK,
49
+ 'no_write' => Playpen::NO_WRITE,
50
+ 'temporary_writes' => Playpen::TEMP_ONLY_WRITE,
51
+ 'pure_computation' => Playpen::COMPUTATION_ONLY,
52
+ }.each do |method, const|
53
+ x = fake_pp
54
+ x.send(method).apply!
55
+ assert_equal([[const, Playpen::SANDBOX_NAMED]], x.args)
56
+ end
57
+ end
58
+
59
+ def fake_pp
60
+ Class.new(Playpen) do
61
+ class << self
62
+ attr_accessor :args
63
+ def sandbox_init file, flags
64
+ self.args << [file, flags]
65
+ end
66
+ end
67
+ self.args = []
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: playpen
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Patterson
14
+ - Evan Phoenix
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-10-07 00:00:00 -06:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rubyforge
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 2
33
+ - 0
34
+ - 4
35
+ version: 2.0.4
36
+ type: :development
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: hoe
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 19
47
+ segments:
48
+ - 2
49
+ - 6
50
+ - 2
51
+ version: 2.6.2
52
+ type: :development
53
+ version_requirements: *id002
54
+ description: |-
55
+ Playpen wraps OS X sandbox api with a loving embrace. Playpen provides the
56
+ same API that the Sandbox class in MacRuby provides.
57
+ email:
58
+ - aaron@tenderlovemaking.com
59
+ - evan@fallingsnow.net
60
+ executables: []
61
+
62
+ extensions:
63
+ - ext/playpen/extconf.rb
64
+ extra_rdoc_files:
65
+ - Manifest.txt
66
+ - CHANGELOG.rdoc
67
+ - README.rdoc
68
+ files:
69
+ - .autotest
70
+ - CHANGELOG.rdoc
71
+ - Manifest.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - ext/playpen/extconf.rb
75
+ - ext/playpen/playpen.c
76
+ - lib/playpen.rb
77
+ - test/test_playpen.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/tenderlove/playpen
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --main
85
+ - README.rdoc
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: playpen
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Playpen wraps OS X sandbox api with a loving embrace
113
+ test_files:
114
+ - test/test_playpen.rb