mineral 0.1.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/.gitignore +3 -0
- data/MIT-LICENSE +21 -0
- data/README.markdown +0 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/mineral.rb +58 -0
- data/lib/mineral/response.rb +27 -0
- data/mineral.gemspec +61 -0
- data/test/app/mineral/handler.rb +13 -0
- data/test/helper.rb +18 -0
- data/test/test_mineral.rb +35 -0
- metadata +115 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2010 Jonathan Bell
|
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.
|
21
|
+
|
data/README.markdown
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mineral"
|
8
|
+
gem.summary = %Q{Rack metal with a better interface}
|
9
|
+
gem.description = %Q{Rack metal with a better interface}
|
10
|
+
gem.email = "jonbell@spamcop.net"
|
11
|
+
gem.homepage = "http://github.com/jonbell/mineral"
|
12
|
+
gem.authors = ["jonbell"]
|
13
|
+
gem.add_dependency "rack", ">= 1.0.0"
|
14
|
+
gem.add_development_dependency "shoulda", ">= 2.10.0"
|
15
|
+
gem.add_development_dependency "mocha", ">= 0.9.0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "mineral #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/mineral.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'active_support/ordered_hash'
|
2
|
+
require 'mineral/response'
|
3
|
+
|
4
|
+
module Mineral
|
5
|
+
module Rack
|
6
|
+
class Mineral
|
7
|
+
|
8
|
+
cattr_accessor :mineral_paths
|
9
|
+
self.mineral_paths = ["#{::Rails.root}/app/mineral"]
|
10
|
+
cattr_accessor :requested_minerals
|
11
|
+
|
12
|
+
def self.minerals
|
13
|
+
matcher = /#{Regexp.escape('/app/mineral/')}(.*)\.rb\Z/
|
14
|
+
mineral_glob = mineral_paths.map{ |base| "#{base}/**/*.rb" }
|
15
|
+
all_minerals = {}
|
16
|
+
|
17
|
+
mineral_glob.each do |glob|
|
18
|
+
Dir[glob].sort.map do |file|
|
19
|
+
file = file.match(matcher)[1]
|
20
|
+
all_minerals[file.camelize] = file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
load_list = requested_minerals || all_minerals.keys
|
25
|
+
|
26
|
+
load_list.map do |requested_mineral|
|
27
|
+
if mineral = all_minerals[requested_mineral]
|
28
|
+
require_dependency 'app/mineral/' + mineral
|
29
|
+
requested_mineral.constantize
|
30
|
+
end
|
31
|
+
end.compact
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(app)
|
35
|
+
@app = app
|
36
|
+
@minerals = self.class.minerals.clone
|
37
|
+
freeze
|
38
|
+
end
|
39
|
+
|
40
|
+
def call(env)
|
41
|
+
request = ::Rack::Request.new(env)
|
42
|
+
@minerals.each do |app|
|
43
|
+
if app.methods.include?(request.request_method) && matcher = app.regex.match(request.path_info)
|
44
|
+
args = []
|
45
|
+
1.step(matcher.size - 1){|group| args << matcher[group]}
|
46
|
+
result = app.send(request.request_method.downcase, request, *args)
|
47
|
+
if result.is_a?(Array)
|
48
|
+
return result
|
49
|
+
elsif result.is_a?(::Mineral::Response)
|
50
|
+
return result.to_rack
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
@app.call(env)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mineral
|
2
|
+
class Response
|
3
|
+
attr_accessor :code
|
4
|
+
attr_accessor :headers
|
5
|
+
attr_accessor :body
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
unless args.empty?
|
9
|
+
if args.size == 1 && args[0].is_a?(Hash)
|
10
|
+
opts = args[0]
|
11
|
+
@code = opts[:code]
|
12
|
+
@headers = opts[:headers]
|
13
|
+
@body = opts[:body]
|
14
|
+
else
|
15
|
+
@code = args[0]
|
16
|
+
@headers = args[1]
|
17
|
+
@body = args[2]
|
18
|
+
end
|
19
|
+
@body = [@body] unless @body.is_a? Array
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_rack
|
24
|
+
[@code, @headers, @body]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/mineral.gemspec
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mineral}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["jonbell"]
|
12
|
+
s.date = %q{2010-03-24}
|
13
|
+
s.description = %q{Rack metal with a better interface}
|
14
|
+
s.email = %q{jonbell@spamcop.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.markdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.markdown",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lib/mineral.rb",
|
25
|
+
"lib/mineral/response.rb",
|
26
|
+
"mineral.gemspec",
|
27
|
+
"test/app/mineral/handler.rb",
|
28
|
+
"test/helper.rb",
|
29
|
+
"test/test_mineral.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/jonbell/mineral}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.6}
|
35
|
+
s.summary = %q{Rack metal with a better interface}
|
36
|
+
s.test_files = [
|
37
|
+
"test/app/mineral/handler.rb",
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_mineral.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<shoulda>, [">= 2.10.0"])
|
49
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 2.10.0"])
|
53
|
+
s.add_dependency(%q<mocha>, [">= 0.9.0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
57
|
+
s.add_dependency(%q<shoulda>, [">= 2.10.0"])
|
58
|
+
s.add_dependency(%q<mocha>, [">= 0.9.0"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
require 'rack'
|
4
|
+
require 'active_support/test_case'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
|
11
|
+
module Rails
|
12
|
+
def self.root
|
13
|
+
File.dirname(__FILE__)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
require 'mineral'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMineral < ActiveSupport::TestCase
|
4
|
+
context "on GET to /handler/123" do
|
5
|
+
setup do
|
6
|
+
@response = Mineral::Rack::Mineral.new(stub).call({"REQUEST_METHOD" => "GET", "PATH_INFO" => "/handler/123"})
|
7
|
+
end
|
8
|
+
|
9
|
+
should "respond with 200" do
|
10
|
+
assert_equal 200, @response[0]
|
11
|
+
end
|
12
|
+
|
13
|
+
should "respond with content type plain text" do
|
14
|
+
assert_equal "text/plain", @response[1]['Content-type']
|
15
|
+
end
|
16
|
+
|
17
|
+
should "respond with id in body" do
|
18
|
+
assert_equal ['123'], @response[2]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "on POST to /handler/123" do
|
23
|
+
setup do
|
24
|
+
env = {"REQUEST_METHOD" => "POST", "PATH_INFO" => "/handler/123"}
|
25
|
+
app = stub(:app) do
|
26
|
+
stubs(:call).with(env).returns("STUBBED")
|
27
|
+
end
|
28
|
+
@response = Mineral::Rack::Mineral.new(app).call(env)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "call next in app stack" do
|
32
|
+
assert_equal "STUBBED", @response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mineral
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- jonbell
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-24 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: shoulda
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 10
|
44
|
+
- 0
|
45
|
+
version: 2.10.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mocha
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 9
|
58
|
+
- 0
|
59
|
+
version: 0.9.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Rack metal with a better interface
|
63
|
+
email: jonbell@spamcop.net
|
64
|
+
executables: []
|
65
|
+
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
extra_rdoc_files:
|
69
|
+
- README.markdown
|
70
|
+
files:
|
71
|
+
- .gitignore
|
72
|
+
- MIT-LICENSE
|
73
|
+
- README.markdown
|
74
|
+
- Rakefile
|
75
|
+
- VERSION
|
76
|
+
- lib/mineral.rb
|
77
|
+
- lib/mineral/response.rb
|
78
|
+
- mineral.gemspec
|
79
|
+
- test/app/mineral/handler.rb
|
80
|
+
- test/helper.rb
|
81
|
+
- test/test_mineral.rb
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://github.com/jonbell/mineral
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- --charset=UTF-8
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Rack metal with a better interface
|
112
|
+
test_files:
|
113
|
+
- test/app/mineral/handler.rb
|
114
|
+
- test/helper.rb
|
115
|
+
- test/test_mineral.rb
|