pakada 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/LICENSE +19 -0
- data/README.rdoc +1 -0
- data/Rakefile +4 -0
- data/lib/pakada/application.rb +23 -0
- data/lib/pakada/boot.rb +7 -0
- data/lib/pakada/module.rb +81 -0
- data/lib/pakada/support/aliasing.rb +8 -0
- data/lib/pakada/support/inflection.rb +35 -0
- data/lib/pakada/support/instance_exec.rb +27 -0
- data/lib/pakada/support.rb +9 -0
- data/lib/pakada/tasks.rb +22 -0
- data/lib/pakada/test.rb +14 -0
- data/lib/pakada/test_case.rb +69 -0
- data/lib/pakada/version.rb +3 -0
- data/lib/pakada.rb +113 -0
- data/tasks/test.rb +73 -0
- data/test/files.rb +60 -0
- data/test/helper.rb +1 -0
- data/test/module_test.rb +81 -0
- data/test/pakada_test.rb +80 -0
- metadata +173 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Lars Gierth
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= Drupal-like awesomeness on Ruby
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Pakada
|
2
|
+
class Application
|
3
|
+
class << self
|
4
|
+
attr_reader :request, :response
|
5
|
+
|
6
|
+
def call(request_env)
|
7
|
+
Pakada.hook(:reset)
|
8
|
+
|
9
|
+
request = Rack::Request.new(request_env)
|
10
|
+
response = Rack::Response.new
|
11
|
+
|
12
|
+
@request, @response = request, response
|
13
|
+
Pakada.hook(:request)
|
14
|
+
|
15
|
+
response.write("Hi, I'm Pakada!") if response.length == 0
|
16
|
+
|
17
|
+
Pakada.hook(:response)
|
18
|
+
@request, @response = nil, nil
|
19
|
+
return response.finish
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/pakada/boot.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
class Pakada
|
2
|
+
module Module
|
3
|
+
@descendants = Dictionary.new
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_reader :descendants
|
7
|
+
|
8
|
+
def prepare
|
9
|
+
specs = []
|
10
|
+
Gem.loaded_specs.each do |name, spec|
|
11
|
+
next unless name =~ Regexp.new("^#{gem_prefix}")
|
12
|
+
i = $LOAD_PATH.find_index(spec.load_paths.first)
|
13
|
+
specs[i] = spec
|
14
|
+
end
|
15
|
+
specs.delete(nil)
|
16
|
+
|
17
|
+
specs.reverse.each do |spec|
|
18
|
+
name = spec.name[gem_prefix.length..-1].to_sym
|
19
|
+
@descendants[name] = {
|
20
|
+
:gemspec => spec,
|
21
|
+
:klass => nil,
|
22
|
+
:path => spec.full_gem_path,
|
23
|
+
} unless @descendants[name]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def load
|
28
|
+
prepare
|
29
|
+
|
30
|
+
@descendants.each do |name, mod|
|
31
|
+
next if mod[:klass]
|
32
|
+
require(mod[:gemspec].full_gem_path + "/module")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def gem_prefix
|
37
|
+
@gem_prefix ||= "pakada" + Pakada::VERSION.split(".")[0] + "-"
|
38
|
+
end
|
39
|
+
|
40
|
+
def included(klass)
|
41
|
+
klass.class_eval { @hooks = {} }
|
42
|
+
klass.extend(ClassMethods)
|
43
|
+
|
44
|
+
name = klass.to_s.underscore.split("_")[0..-2].join("_")
|
45
|
+
@descendants[name.to_sym][:klass] = klass
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def hook(name, *args)
|
50
|
+
hooks = self.class.class_eval { @hooks }
|
51
|
+
hooks[name].each {|h| instance_exec(*args, &h) } if hooks[name]
|
52
|
+
end
|
53
|
+
|
54
|
+
def version
|
55
|
+
return self.class.version
|
56
|
+
end
|
57
|
+
|
58
|
+
def path
|
59
|
+
return self.class.path
|
60
|
+
end
|
61
|
+
|
62
|
+
module ClassMethods
|
63
|
+
def hook(name, &block)
|
64
|
+
@hooks[name] ||= []
|
65
|
+
@hooks[name] << block
|
66
|
+
end
|
67
|
+
|
68
|
+
def name
|
69
|
+
return @name ||= Pakada::Module.descendants.find {|m| m[1][:klass] == self }[0]
|
70
|
+
end
|
71
|
+
|
72
|
+
def version
|
73
|
+
return Pakada::Module.descendants[name][:gemspec].version.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
def path
|
77
|
+
return Pakada::Module.descendants[name][:path]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def classify()
|
4
|
+
Extlib::Inflection.classify(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def camelize()
|
8
|
+
Extlib::Inflection.camelize(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def underscore()
|
12
|
+
Extlib::Inflection.underscore(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def humanize()
|
16
|
+
Extlib::Inflection.humanize(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def demodulize()
|
20
|
+
Extlib::Inflection.demodulize(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def tableize()
|
24
|
+
Extlib::Inflection.tableize(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def foreign_key()
|
28
|
+
Extlib::Inflection.foreign_key(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def constantize()
|
32
|
+
Extlib::Inflection.constantize(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Object
|
2
|
+
|
3
|
+
module InstanceExecHelper
|
4
|
+
end
|
5
|
+
|
6
|
+
include InstanceExecHelper
|
7
|
+
|
8
|
+
# this leaks memory
|
9
|
+
# see http://eigenclass.org/hiki/bounded+space+instance_exec
|
10
|
+
def instance_exec(*args, &block)
|
11
|
+
begin
|
12
|
+
old_critical, Thread.critical = Thread.critical, true
|
13
|
+
n = 0
|
14
|
+
n += 1 while respond_to?(mname = "__instance_exec#{n}")
|
15
|
+
InstanceExecHelper.module_eval { define_method(mname, &block) }
|
16
|
+
ensure
|
17
|
+
Thread.critical = old_critical
|
18
|
+
end
|
19
|
+
begin
|
20
|
+
ret = send(mname, *args)
|
21
|
+
ensure
|
22
|
+
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
23
|
+
end
|
24
|
+
return ret
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/pakada/tasks.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "pakada"
|
2
|
+
|
3
|
+
dirs = []
|
4
|
+
|
5
|
+
# core's tasks
|
6
|
+
dirs << Gem.loaded_specs["pakada"].full_gem_path
|
7
|
+
|
8
|
+
# modules' tasks
|
9
|
+
ENV["RACK_ENV"] ||= "development"
|
10
|
+
Bundler.setup(:modules, :default, ENV["RACK_ENV"].to_sym)
|
11
|
+
Pakada::Module.load
|
12
|
+
Pakada::Module.descendants.each do |name, mod|
|
13
|
+
dirs << mod[:gemspec].full_gem_path
|
14
|
+
end
|
15
|
+
|
16
|
+
# project's tasks
|
17
|
+
dirs << Dir.pwd
|
18
|
+
|
19
|
+
# load the tasks
|
20
|
+
dirs.uniq.each do |dir|
|
21
|
+
Dir["#{dir}/tasks/*"].each {|f| require(f) }
|
22
|
+
end
|
data/lib/pakada/test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
ENV["RACK_ENV"] = "testing"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup(:pakada, :modules, :default, ENV["RACK_ENV"].to_sym)
|
4
|
+
|
5
|
+
require "pakada"
|
6
|
+
|
7
|
+
require "test/unit"
|
8
|
+
require "pakada/test_case"
|
9
|
+
Test::Unit::TestCase.class_eval { include(Pakada::TestCase) }
|
10
|
+
|
11
|
+
require "mocha"
|
12
|
+
require "fakefs/safe"
|
13
|
+
require "fakefs/require"
|
14
|
+
require "rack"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Pakada
|
2
|
+
module TestCase
|
3
|
+
def create_files(files)
|
4
|
+
files.each do |name, content|
|
5
|
+
File.open(name, "w") do |f|
|
6
|
+
f.write(content)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_gemspecs(paths)
|
12
|
+
@stubbed_gemspecs ||= []
|
13
|
+
@load_path_diff ||= []
|
14
|
+
|
15
|
+
old_load_path = $LOAD_PATH.dup
|
16
|
+
|
17
|
+
paths.each do |path|
|
18
|
+
spec = eval(File.read(path))
|
19
|
+
dir = File.expand_path(File.dirname(path))
|
20
|
+
|
21
|
+
spec.stubs(:full_gem_path).returns(dir)
|
22
|
+
spec.stubs(:load_paths).returns([dir + "/lib"])
|
23
|
+
Gem.loaded_specs[spec.name] = spec
|
24
|
+
@stubbed_gemspecs << spec.name
|
25
|
+
|
26
|
+
$LOAD_PATH.unshift(spec.load_paths.first)
|
27
|
+
end
|
28
|
+
|
29
|
+
@load_path_diff += $LOAD_PATH - old_load_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def revert_gemspecs()
|
33
|
+
@stubbed_gemspecs.each {|name| Gem.loaded_specs.delete(name) }
|
34
|
+
@load_path_diff.each {|path| $LOAD_PATH.delete(path) }
|
35
|
+
|
36
|
+
@stubbed_gemspecs = nil
|
37
|
+
@load_path_diff = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.included(klass)
|
41
|
+
klass.extend(ClassMethods)
|
42
|
+
end
|
43
|
+
|
44
|
+
module ClassMethods
|
45
|
+
def setup(&block)
|
46
|
+
define_method(:setup, &block)
|
47
|
+
end
|
48
|
+
|
49
|
+
def teardown(&block)
|
50
|
+
define_method(:teardown, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test(name, &block)
|
54
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
55
|
+
|
56
|
+
defined = instance_method(test_name) rescue false
|
57
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
58
|
+
|
59
|
+
if block_given?
|
60
|
+
define_method(test_name, &block)
|
61
|
+
else
|
62
|
+
define_method(test_name) do
|
63
|
+
flunk "No implementation provided for #{name}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/pakada.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require "rack"
|
2
|
+
require "pakada/support"
|
3
|
+
|
4
|
+
require "pakada/application"
|
5
|
+
require "pakada/module"
|
6
|
+
require "pakada/version"
|
7
|
+
|
8
|
+
class Pakada
|
9
|
+
class << self
|
10
|
+
attr_reader :modules, :middleware
|
11
|
+
attr_writer :env
|
12
|
+
|
13
|
+
def boot(env = nil)
|
14
|
+
@env = env.to_sym if env
|
15
|
+
|
16
|
+
load_middleware
|
17
|
+
load_modules if @modules.empty?
|
18
|
+
|
19
|
+
hook(:boot) unless testing?
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_middleware
|
23
|
+
config = YAML.load_file("config/middleware.yml") rescue {}
|
24
|
+
@middleware = Rack::Builder.new
|
25
|
+
config[env].each do |klass|
|
26
|
+
args = []
|
27
|
+
klass, args = klass.to_a[0] if klass.is_a?(Hash)
|
28
|
+
if args.is_a?(Array)
|
29
|
+
@middleware.use(klass.constantize, *args)
|
30
|
+
else
|
31
|
+
@middleware.use(klass.constantize, args)
|
32
|
+
end
|
33
|
+
end if config[env]
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_modules
|
37
|
+
Module.load
|
38
|
+
@modules = Dictionary.new
|
39
|
+
@hooks = {}
|
40
|
+
Module.descendants.each do |name, mod|
|
41
|
+
@modules[name] = mod[:klass].new
|
42
|
+
@modules[name].hook(:activate) unless testing?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def [](name)
|
47
|
+
return modules[name]
|
48
|
+
end
|
49
|
+
|
50
|
+
def []=(name, mod)
|
51
|
+
modules[name] = mod
|
52
|
+
end
|
53
|
+
|
54
|
+
def hook(name, *args)
|
55
|
+
catch(:halt) { @modules.each_value {|mod| mod.hook(name, *args) } }
|
56
|
+
end
|
57
|
+
|
58
|
+
def hook_reverse(name, *args)
|
59
|
+
catch(:halt) { @modules.reverse.each_value {|mod| mod.hook(name, *args) } }
|
60
|
+
end
|
61
|
+
|
62
|
+
def app
|
63
|
+
unless @app
|
64
|
+
@middleware.run(Application)
|
65
|
+
@app = @middleware.to_app
|
66
|
+
end
|
67
|
+
return @app
|
68
|
+
end
|
69
|
+
|
70
|
+
def request
|
71
|
+
return Application.request
|
72
|
+
end
|
73
|
+
|
74
|
+
def response
|
75
|
+
return Application.response
|
76
|
+
end
|
77
|
+
|
78
|
+
def reset
|
79
|
+
@env = nil
|
80
|
+
@middleware = Rack::Builder.new
|
81
|
+
@modules = Dictionary.new
|
82
|
+
@app = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def shutdown
|
86
|
+
hook_reverse(:shutdown) unless testing?
|
87
|
+
|
88
|
+
reset
|
89
|
+
end
|
90
|
+
|
91
|
+
def env
|
92
|
+
return @env ||= (ENV["RACK_ENV"] || :development).to_sym
|
93
|
+
end
|
94
|
+
|
95
|
+
def development?
|
96
|
+
return env == :development
|
97
|
+
end
|
98
|
+
|
99
|
+
def testing?
|
100
|
+
return env == :testing
|
101
|
+
end
|
102
|
+
|
103
|
+
def staging?
|
104
|
+
return env == :staging
|
105
|
+
end
|
106
|
+
|
107
|
+
def production?
|
108
|
+
return env == :production
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
reset
|
113
|
+
end
|
data/tasks/test.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "rake/testtask"
|
2
|
+
|
3
|
+
desc " => rake test"
|
4
|
+
task " " => :default
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc "Test all modules as well as Pakada's core"
|
8
|
+
task :test do
|
9
|
+
Rake::Task["test:*"].execute
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :test do
|
13
|
+
desc "Test the module 'my_module'"
|
14
|
+
task :"my_module"
|
15
|
+
|
16
|
+
desc "Test the modules 'my_module' and 'another_module' as well as Pakada's core"
|
17
|
+
task :"my_module+another_module+core"
|
18
|
+
end
|
19
|
+
|
20
|
+
rule /^test(:.+)?$/ do |t|
|
21
|
+
arg = (t.name || "*").split(":").last
|
22
|
+
modules = []
|
23
|
+
|
24
|
+
if arg == "*"
|
25
|
+
modules << "core"
|
26
|
+
modules += Pakada::Module.descendants.keys
|
27
|
+
else
|
28
|
+
modules = arg.split("+")
|
29
|
+
end
|
30
|
+
|
31
|
+
modules.each do |mod|
|
32
|
+
puts "-----"
|
33
|
+
puts "Testing #{mod}"
|
34
|
+
|
35
|
+
runner = "rake/rake_test_loader.rb"
|
36
|
+
$LOAD_PATH.each do |p|
|
37
|
+
path = File.join p, runner
|
38
|
+
if File.exist? path
|
39
|
+
runner = path
|
40
|
+
break
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
dir = File.expand_path(if mod == "core"
|
45
|
+
File.dirname(__FILE__) + "/.."
|
46
|
+
else
|
47
|
+
Pakada::Module.descendants[mod.to_sym][:path] rescue raise("Unknown module: #{mod}")
|
48
|
+
end)
|
49
|
+
files = FileList[dir + "/test/**/*_test.rb"]
|
50
|
+
|
51
|
+
opts = []
|
52
|
+
opts << "-rubygems"
|
53
|
+
opts << "-C#{dir}"
|
54
|
+
opts << "-I#{Gem.loaded_specs["pakada"].full_gem_path}/lib"
|
55
|
+
|
56
|
+
["_", "PWD", "GEM_PATH", "GEM_HOME"].each {|k| ENV.delete(k) }
|
57
|
+
ENV["BUNDLE_GEMFILE"] = if File.exist?(dir + "/Gemfile")
|
58
|
+
dir + "/Gemfile"
|
59
|
+
else
|
60
|
+
File.expand_path("Gemfile")
|
61
|
+
end
|
62
|
+
|
63
|
+
begin
|
64
|
+
cmd = FileUtils::RUBY + " " + [
|
65
|
+
opts.join(" "),
|
66
|
+
runner,
|
67
|
+
files.map{|f| %("#{f}") }.join(" "),
|
68
|
+
].join(" ")
|
69
|
+
system(cmd)
|
70
|
+
rescue
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/test/files.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
FILES = {
|
2
|
+
|
3
|
+
"config/middleware.yml" => <<-CODE,
|
4
|
+
:testing:
|
5
|
+
- Rack::ShowExceptions
|
6
|
+
- Rack::Static:
|
7
|
+
:urls:
|
8
|
+
- /images
|
9
|
+
:root: public
|
10
|
+
CODE
|
11
|
+
|
12
|
+
"modules/foo/pakada0-foo.gemspec" => <<-CODE,
|
13
|
+
Gem::Specification.new do |s|
|
14
|
+
s.name = "pakada0-foo"
|
15
|
+
s.version = "0.1.0dev"
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.authors = ["Lars Gierth"]
|
18
|
+
s.email = ["lgierth@entwickler.com"]
|
19
|
+
s.homepage = "http://github.com/lgierth/pakada"
|
20
|
+
s.summary = "nothing"
|
21
|
+
|
22
|
+
s.add_dependency "pakada"
|
23
|
+
|
24
|
+
s.files = ["module.rb"]
|
25
|
+
s.require_path = "lib"
|
26
|
+
|
27
|
+
s.required_rubygems_version = ">= 1.3.6"
|
28
|
+
end
|
29
|
+
CODE
|
30
|
+
"modules/foo/module.rb" => <<-CODE,
|
31
|
+
class FooModule
|
32
|
+
include Pakada::Module
|
33
|
+
end
|
34
|
+
CODE
|
35
|
+
|
36
|
+
"modules/bar/pakada0-bar.gemspec" => <<-CODE,
|
37
|
+
Gem::Specification.new do |s|
|
38
|
+
s.name = "pakada0-bar"
|
39
|
+
s.version = "0.1.0dev"
|
40
|
+
s.platform = Gem::Platform::RUBY
|
41
|
+
s.authors = ["Lars Gierth"]
|
42
|
+
s.email = ["lgierth@entwickler.com"]
|
43
|
+
s.homepage = "http://github.com/lgierth/pakada"
|
44
|
+
s.summary = "nothing"
|
45
|
+
|
46
|
+
s.add_dependency "pakada"
|
47
|
+
|
48
|
+
s.files = ["module.rb"]
|
49
|
+
s.require_path = "lib"
|
50
|
+
|
51
|
+
s.required_rubygems_version = ">= 1.3.6"
|
52
|
+
end
|
53
|
+
CODE
|
54
|
+
"modules/bar/module.rb" => <<-CODE,
|
55
|
+
class BarModule
|
56
|
+
include Pakada::Module
|
57
|
+
end
|
58
|
+
CODE
|
59
|
+
|
60
|
+
}
|
data/test/helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "pakada/test"
|
data/test/module_test.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require "test/files"
|
3
|
+
|
4
|
+
class ModuleTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
FakeFS.activate!
|
7
|
+
FakeFS::Require.activate!({
|
8
|
+
:fallback => true,
|
9
|
+
:load => true,
|
10
|
+
:autoload => true,
|
11
|
+
})
|
12
|
+
create_files(FILES)
|
13
|
+
|
14
|
+
stub_gemspecs([
|
15
|
+
"modules/foo/pakada0-foo.gemspec",
|
16
|
+
"modules/bar/pakada0-bar.gemspec",
|
17
|
+
])
|
18
|
+
end
|
19
|
+
|
20
|
+
teardown do
|
21
|
+
revert_gemspecs
|
22
|
+
Mocha::Mockery.instance.teardown
|
23
|
+
|
24
|
+
Pakada.shutdown
|
25
|
+
|
26
|
+
FakeFS::FileSystem.clear
|
27
|
+
FakeFS::Require.deactivate!
|
28
|
+
FakeFS.deactivate!
|
29
|
+
end
|
30
|
+
|
31
|
+
test "prepares modules" do
|
32
|
+
Pakada::Module.prepare
|
33
|
+
modules = Pakada::Module.descendants
|
34
|
+
|
35
|
+
assert_equal 2, modules.length
|
36
|
+
assert_equal File.expand_path("modules/foo"), modules[:foo][:path]
|
37
|
+
assert_equal "pakada0-foo", modules[:foo][:gemspec].name
|
38
|
+
end
|
39
|
+
|
40
|
+
test "loads modules" do
|
41
|
+
Pakada::Module.load
|
42
|
+
modules = Pakada::Module.descendants
|
43
|
+
|
44
|
+
assert_equal 2, modules.length
|
45
|
+
assert_equal FooModule, modules[:foo][:klass]
|
46
|
+
end
|
47
|
+
|
48
|
+
test "has hooks" do
|
49
|
+
Pakada::Module.load
|
50
|
+
|
51
|
+
FooModule.class_eval do
|
52
|
+
hook :asd do
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
assert(FooModule.class_eval { @hooks[:asd] })
|
57
|
+
assert_equal 1, FooModule.class_eval { @hooks[:asd].length }
|
58
|
+
end
|
59
|
+
|
60
|
+
test "executes hooks" do
|
61
|
+
Pakada.boot
|
62
|
+
|
63
|
+
FooModule.class_eval do
|
64
|
+
hook :something do |state|
|
65
|
+
state.called = true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
state = Struct.new(:called).new
|
70
|
+
Pakada.hook :something, state
|
71
|
+
|
72
|
+
assert state.called
|
73
|
+
end
|
74
|
+
|
75
|
+
test "has a version" do
|
76
|
+
Pakada.boot
|
77
|
+
|
78
|
+
version = Gem.loaded_specs["pakada0-foo"].version.to_s
|
79
|
+
assert_equal version, Pakada[:foo].version
|
80
|
+
end
|
81
|
+
end
|
data/test/pakada_test.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "test/helper"
|
2
|
+
require "test/files"
|
3
|
+
|
4
|
+
class PakadaTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
FakeFS.activate!
|
7
|
+
FakeFS::Require.activate!({
|
8
|
+
:fallback => true,
|
9
|
+
:load => true,
|
10
|
+
:autoload => true,
|
11
|
+
})
|
12
|
+
create_files(FILES)
|
13
|
+
|
14
|
+
stub_gemspecs([
|
15
|
+
"modules/foo/pakada0-foo.gemspec",
|
16
|
+
"modules/bar/pakada0-bar.gemspec",
|
17
|
+
])
|
18
|
+
end
|
19
|
+
|
20
|
+
teardown do
|
21
|
+
revert_gemspecs
|
22
|
+
Mocha::Mockery.instance.teardown
|
23
|
+
|
24
|
+
Pakada.shutdown
|
25
|
+
|
26
|
+
FakeFS::FileSystem.clear
|
27
|
+
FakeFS::Require.deactivate!
|
28
|
+
FakeFS.deactivate!
|
29
|
+
end
|
30
|
+
|
31
|
+
test "maintains a Rack middleware stack" do
|
32
|
+
Rack::Builder.any_instance.expects(:use).with(Rack::ShowExceptions)
|
33
|
+
Rack::Builder.any_instance.expects(:use).with(Rack::Static, {
|
34
|
+
:urls => ["/images"],
|
35
|
+
:root => "public",
|
36
|
+
})
|
37
|
+
Pakada.boot
|
38
|
+
end
|
39
|
+
|
40
|
+
test "executes modules' hooks" do
|
41
|
+
Pakada.boot
|
42
|
+
Pakada[:foo].class.class_eval do
|
43
|
+
hook(:foobar) do
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Pakada[:foo].expects(:hook).once.with(:foobar, 123)
|
48
|
+
Pakada.hook(:foobar, 123)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "cancels the execution of a hook when it catches :halt" do
|
52
|
+
Pakada.boot
|
53
|
+
Pakada[:foo].class.class_eval do
|
54
|
+
hook(:foobar) do |state|
|
55
|
+
throw :halt
|
56
|
+
state.after_throw = true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
state = Struct.new(:after_throw).new
|
61
|
+
Pakada.hook(:foobar, state)
|
62
|
+
|
63
|
+
assert !state.after_throw
|
64
|
+
end
|
65
|
+
|
66
|
+
test "provides a Rack application end-point" do
|
67
|
+
Rack::Builder.any_instance.expects(:run).with(Pakada::Application)
|
68
|
+
|
69
|
+
Pakada.boot
|
70
|
+
assert_equal Rack::ShowExceptions, Pakada.app.class
|
71
|
+
end
|
72
|
+
|
73
|
+
test "prints a greeting when the response would be empty" do
|
74
|
+
Pakada.boot
|
75
|
+
Pakada.stubs(:hook)
|
76
|
+
|
77
|
+
resp = Pakada.app.call("PATH_INFO" => "/")
|
78
|
+
assert_equal "Hi, I'm Pakada!", resp[2].body.to_s
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pakada
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 0.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Lars Gierth
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-19 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: extlib
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rack
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: mocha
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: fakefs
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: fakefs-require
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id006
|
105
|
+
description:
|
106
|
+
email:
|
107
|
+
- lgierth@entwickler.com
|
108
|
+
executables: []
|
109
|
+
|
110
|
+
extensions: []
|
111
|
+
|
112
|
+
extra_rdoc_files: []
|
113
|
+
|
114
|
+
files:
|
115
|
+
- lib/pakada/version.rb
|
116
|
+
- lib/pakada/support.rb
|
117
|
+
- lib/pakada/boot.rb
|
118
|
+
- lib/pakada/tasks.rb
|
119
|
+
- lib/pakada/test.rb
|
120
|
+
- lib/pakada/test_case.rb
|
121
|
+
- lib/pakada/application.rb
|
122
|
+
- lib/pakada/module.rb
|
123
|
+
- lib/pakada/support/aliasing.rb
|
124
|
+
- lib/pakada/support/instance_exec.rb
|
125
|
+
- lib/pakada/support/inflection.rb
|
126
|
+
- lib/pakada.rb
|
127
|
+
- tasks/test.rb
|
128
|
+
- test/pakada_test.rb
|
129
|
+
- test/files.rb
|
130
|
+
- test/module_test.rb
|
131
|
+
- test/helper.rb
|
132
|
+
- Gemfile
|
133
|
+
- LICENSE
|
134
|
+
- Rakefile
|
135
|
+
- README.rdoc
|
136
|
+
has_rdoc: true
|
137
|
+
homepage: http://github.com/lgierth/pakada
|
138
|
+
licenses: []
|
139
|
+
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
version: "0"
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
hash: 23
|
160
|
+
segments:
|
161
|
+
- 1
|
162
|
+
- 3
|
163
|
+
- 6
|
164
|
+
version: 1.3.6
|
165
|
+
requirements: []
|
166
|
+
|
167
|
+
rubyforge_project:
|
168
|
+
rubygems_version: 1.3.7
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: Drupal-like awesomeness on Ruby
|
172
|
+
test_files: []
|
173
|
+
|