treant 0.0.1.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gems +5 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/lib/treant/version.rb +3 -0
- data/lib/treant.rb +43 -0
- data/makefile +2 -0
- data/test/captures.rb +20 -0
- data/test/composition.rb +27 -0
- data/test/hello.rb +18 -0
- data/test/helper.rb +19 -0
- data/test/middleware.rb +71 -0
- data/test/plugin.rb +70 -0
- data/test/settings.rb +29 -0
- data/treant.gemspec +20 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21738d98e59ed2b467cc9d8cac1999d4d3245f85
|
4
|
+
data.tar.gz: 6b56a30df3e0ba728d0c30e048c2a61ba3db5fa7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ca4e36474563fffbc0a5d7634bef250f0e9e87731b124901e6dce629dda229c171eb168a652ef67ada17e473ccb9efcc3f41973f1ab1c6e257769ad75629b848
|
7
|
+
data.tar.gz: 725e7ed9e68bda3c138eef7aca9f9b710e52df0711a71af1a1aa0ac4beb7c5324647506bda6ff9be8e1318b68fc8632df8660d40293b61a420e5d5968ffe5e3e
|
data/.gems
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Francesco Rodríguez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/lib/treant.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rack"
|
2
|
+
require "seteable"
|
3
|
+
require "syro"
|
4
|
+
|
5
|
+
class Treant < Syro::Deck
|
6
|
+
include Seteable
|
7
|
+
|
8
|
+
def self.define(&block)
|
9
|
+
app.run(Syro.new(self, &block))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.call(env)
|
13
|
+
return prototype.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.prototype
|
17
|
+
return @prototype ||= app.to_app
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.app
|
21
|
+
return @app ||= Rack::Builder.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.reset!
|
25
|
+
@app = @prototype = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.use(middleware, *args, &block)
|
29
|
+
app.use(middleware, *args, &block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.plugin(mod, options = {})
|
33
|
+
self.include(mod)
|
34
|
+
|
35
|
+
if defined?(mod::ClassMethods)
|
36
|
+
self.extend(mod::ClassMethods)
|
37
|
+
end
|
38
|
+
|
39
|
+
if mod.respond_to?(:setup)
|
40
|
+
mod.setup(self, options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/makefile
ADDED
data/test/captures.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
setup do
|
4
|
+
Driver.new(Treant)
|
5
|
+
end
|
6
|
+
|
7
|
+
test "captures" do |app|
|
8
|
+
Treant.define do
|
9
|
+
on :foo do
|
10
|
+
on :bar do
|
11
|
+
res.write(sprintf("%s:%s", inbox[:foo], inbox[:bar]))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
app.get("/foo/bar")
|
17
|
+
|
18
|
+
assert_equal 200, app.res.status
|
19
|
+
assert_equal "foo:bar", app.res.body
|
20
|
+
end
|
data/test/composition.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
setup do
|
4
|
+
Driver.new(Treant)
|
5
|
+
end
|
6
|
+
|
7
|
+
test "composition" do |app|
|
8
|
+
class Foo < Treant
|
9
|
+
end
|
10
|
+
|
11
|
+
Foo.define do
|
12
|
+
get do
|
13
|
+
res.write(inbox[:foo])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Treant.define do
|
18
|
+
on "foo" do
|
19
|
+
run(Foo, foo: 42)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
app.get("/foo")
|
24
|
+
|
25
|
+
assert_equal 200, app.res.status
|
26
|
+
assert_equal "42", app.res.body
|
27
|
+
end
|
data/test/hello.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
setup do
|
4
|
+
Driver.new(Treant)
|
5
|
+
end
|
6
|
+
|
7
|
+
test "hello world" do |app|
|
8
|
+
Treant.define do
|
9
|
+
get do
|
10
|
+
res.write("hello world")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
app.get("/")
|
15
|
+
|
16
|
+
assert_equal 200, app.res.status
|
17
|
+
assert_equal "hello world", app.res.body
|
18
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "cutest"
|
2
|
+
require "rack/test"
|
3
|
+
require_relative "../lib/treant"
|
4
|
+
|
5
|
+
prepare do
|
6
|
+
Treant.reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
class Driver
|
10
|
+
include Rack::Test::Methods
|
11
|
+
|
12
|
+
attr_reader :app
|
13
|
+
|
14
|
+
def initialize(app)
|
15
|
+
@app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
alias_method :res, :last_response
|
19
|
+
end
|
data/test/middleware.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
class Shrimp
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
s, h, resp = @app.call(env)
|
10
|
+
|
11
|
+
return [s, h, resp.reverse]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
setup do
|
16
|
+
Driver.new(Treant)
|
17
|
+
end
|
18
|
+
|
19
|
+
test "use middleware in main application" do |app|
|
20
|
+
Treant.use(Shrimp)
|
21
|
+
|
22
|
+
class API < Treant
|
23
|
+
end
|
24
|
+
|
25
|
+
API.define do
|
26
|
+
get do
|
27
|
+
res.write("2")
|
28
|
+
res.write("1")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Treant.define do
|
33
|
+
on "api" do
|
34
|
+
run(API)
|
35
|
+
end
|
36
|
+
|
37
|
+
get do
|
38
|
+
res.write("1")
|
39
|
+
res.write("2")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
app.get("/")
|
44
|
+
|
45
|
+
assert_equal 200, app.res.status
|
46
|
+
assert_equal "21", app.res.body
|
47
|
+
end
|
48
|
+
|
49
|
+
test "use middleware in child application" do
|
50
|
+
Treant.define do
|
51
|
+
run(API)
|
52
|
+
end
|
53
|
+
|
54
|
+
class API < Treant
|
55
|
+
use(Shrimp)
|
56
|
+
end
|
57
|
+
|
58
|
+
API.define do
|
59
|
+
get do
|
60
|
+
res.write("1")
|
61
|
+
res.write("2")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
app = Driver.new(Treant)
|
66
|
+
|
67
|
+
app.get("/")
|
68
|
+
|
69
|
+
assert_equal 200, app.res.status
|
70
|
+
assert_equal "21", app.res.body
|
71
|
+
end
|
data/test/plugin.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
module Helper
|
4
|
+
def clean(str)
|
5
|
+
return str.strip
|
6
|
+
end
|
7
|
+
|
8
|
+
module Number
|
9
|
+
def self.setup(app, options = {})
|
10
|
+
app.settings[:number] = options.fetch(:number, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
def number
|
14
|
+
return settings[:number]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.setup(app, options = {})
|
19
|
+
app.plugin(Number, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
def foo
|
24
|
+
"foo"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
setup do
|
30
|
+
Driver.new(Treant)
|
31
|
+
end
|
32
|
+
|
33
|
+
test "plugin" do |app|
|
34
|
+
Treant.plugin(Helper)
|
35
|
+
|
36
|
+
Treant.define do
|
37
|
+
get do
|
38
|
+
res.write(clean(" foo "))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
app.get("/")
|
43
|
+
|
44
|
+
assert_equal "foo", app.res.body
|
45
|
+
assert_equal "foo", Treant.foo
|
46
|
+
end
|
47
|
+
|
48
|
+
test "setup" do |app|
|
49
|
+
Treant.plugin(Helper)
|
50
|
+
|
51
|
+
Treant.define do
|
52
|
+
res.write(number)
|
53
|
+
end
|
54
|
+
|
55
|
+
app.get("/")
|
56
|
+
|
57
|
+
assert_equal "1", app.res.body
|
58
|
+
end
|
59
|
+
|
60
|
+
test "setup with options" do |app|
|
61
|
+
Treant.plugin(Helper, number: 2)
|
62
|
+
|
63
|
+
Treant.define do
|
64
|
+
res.write(number)
|
65
|
+
end
|
66
|
+
|
67
|
+
app.get("/")
|
68
|
+
|
69
|
+
assert_equal "2", app.res.body
|
70
|
+
end
|
data/test/settings.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
test "use settings inside the application" do
|
4
|
+
Treant.settings[:message] = "hello"
|
5
|
+
|
6
|
+
Treant.define do
|
7
|
+
get do
|
8
|
+
res.write(settings[:message])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
app = Driver.new(Treant)
|
13
|
+
app.get("/")
|
14
|
+
|
15
|
+
assert_equal "hello", app.res.body
|
16
|
+
end
|
17
|
+
|
18
|
+
test "settings are inheritable and overridable" do
|
19
|
+
Treant.settings[:foo] = "bar"
|
20
|
+
|
21
|
+
class Admin < Treant; end
|
22
|
+
|
23
|
+
assert_equal "bar", Admin.settings[:foo]
|
24
|
+
|
25
|
+
Admin.settings[:foo] = "baz"
|
26
|
+
|
27
|
+
assert_equal "bar", Treant.settings[:foo]
|
28
|
+
assert_equal "baz", Admin.settings[:foo]
|
29
|
+
end
|
data/treant.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "lib/treant/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "treant"
|
5
|
+
s.version = Treant::VERSION
|
6
|
+
s.summary = "treant"
|
7
|
+
s.description = s.summary
|
8
|
+
s.authors = ["Francesco Rodríguez"]
|
9
|
+
s.email = ["frodsan@protonmail.ch"]
|
10
|
+
s.homepage = "https://github.com/harmoni/treant"
|
11
|
+
s.license = "MIT"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
|
15
|
+
s.add_dependency "syro", "~> 0.0.7"
|
16
|
+
s.add_dependency "rack", "~> 1.6.4"
|
17
|
+
s.add_dependency "seteable", "1.0.0"
|
18
|
+
s.add_development_dependency "cutest", "1.2.2"
|
19
|
+
s.add_development_dependency "rack-test", "0.6.3"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: treant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francesco Rodríguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: syro
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: seteable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cutest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.2.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.3
|
83
|
+
description: treant
|
84
|
+
email:
|
85
|
+
- frodsan@protonmail.ch
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gems"
|
91
|
+
- LICENSE
|
92
|
+
- README.md
|
93
|
+
- lib/treant.rb
|
94
|
+
- lib/treant/version.rb
|
95
|
+
- makefile
|
96
|
+
- test/captures.rb
|
97
|
+
- test/composition.rb
|
98
|
+
- test/hello.rb
|
99
|
+
- test/helper.rb
|
100
|
+
- test/middleware.rb
|
101
|
+
- test/plugin.rb
|
102
|
+
- test/settings.rb
|
103
|
+
- treant.gemspec
|
104
|
+
homepage: https://github.com/harmoni/treant
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">"
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.3.1
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.8
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: treant
|
128
|
+
test_files: []
|