tynn 0.0.1.alpha1 → 0.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd7deda7bb8d025b5fc079fe7b5bb65db7a8881f
4
- data.tar.gz: ee21d84e0d21c64e907de50930053834e29a0079
3
+ metadata.gz: 79036ec0ceb3a8dc00cf95004df88b0e6a0a3f2d
4
+ data.tar.gz: 89adaa34ed372a4f271f61bf95b05d4f5673211a
5
5
  SHA512:
6
- metadata.gz: 8554a61d479ce222a6bf266ee264bd0e2f6cadfbf1b5f8698aa8499048ef474a1d230b03c64987d59fdef1daaecc9120fae7ca952de4da16b6d92a38e3985d73
7
- data.tar.gz: 24de271d0802231c755811522f972c4e08fd68ffdd990991ead4a9e4501942172bdb9b5937881680cca9266f77d553dfc586fb1a6f1c7489febaf868247ad471
6
+ metadata.gz: 28f394aeaeae75432f8bb87d598d30c9062bdad4d760735193566e7fab27f8bfe4288f95acaabf52e5bcb797f56bb7a9fbb64788cc2e6e7cacb27b7187c7c543
7
+ data.tar.gz: 2fb11894379614565e6deb18a110ba2e43e79b2310cf38fabe4ef9a654f003968ed909bda0c0ca360c0fef236bfdd62ea3cf7817115c32c3d9dcd6fc95785082
data/.gems CHANGED
@@ -1,5 +1,5 @@
1
1
  cutest -v 1.2.2
2
2
  syro -v 0.0.7
3
3
  rack -v 1.6.4
4
- seteable -v 1.0.0
5
4
  rack-test -v 0.6.3
5
+ seteable -v 1.0.0
data/README.md CHANGED
@@ -1,2 +1,42 @@
1
1
  tynn
2
2
  ====
3
+
4
+ Simple library to create [Rack][rack] applications.
5
+
6
+ Description
7
+ -----------
8
+
9
+ Tynn is a thin abstraction on top of [Syro][syro], a very simple and fast
10
+ router for web applications.
11
+
12
+ Usage
13
+ -----
14
+
15
+ Here's a minimal application:
16
+
17
+ ```ruby
18
+ # config.ru
19
+ require "tynn"
20
+
21
+ Tynn.define do
22
+ root do
23
+ res.write("Hello World!")
24
+ end
25
+ end
26
+
27
+ run(Tynn)
28
+ ```
29
+
30
+ You can run `rackup` and open <http://localhost:9292/> to see the greeting
31
+ message.
32
+
33
+ Installation
34
+ ------------
35
+
36
+ ```
37
+ $ gem install tynn
38
+ ```
39
+
40
+ [cuba]: https://github.com/soveran/cuba
41
+ [rack]: https://github.com/rack/rack
42
+ [syro]: https://github.com/soveran/syro
data/lib/tynn.rb CHANGED
@@ -1,35 +1,34 @@
1
- require "rack"
2
1
  require "seteable"
3
2
  require "syro"
4
3
 
5
4
  class Tynn < Syro::Deck
6
5
  include Seteable
7
6
 
8
- def self.define(&block)
9
- app.run(Syro.new(self, &block))
10
- end
11
-
12
7
  def self.call(env)
13
- return prototype.call(env)
8
+ return to_app.call(env)
14
9
  end
15
10
 
16
- def self.prototype
17
- return @prototype ||= app.to_app
11
+ def self.to_app
12
+ if __middleware.empty?
13
+ return @__syro
14
+ else
15
+ return __middleware.inject(@__syro) { |a, m| m.call(a) }
16
+ end
18
17
  end
19
18
 
20
- def self.app
21
- return @app ||= Rack::Builder.new
19
+ def self.__middleware
20
+ return @__middleware ||= []
22
21
  end
23
22
 
24
- def self.reset!
25
- @app = @prototype = nil
23
+ def self.define(&block)
24
+ @__syro = Syro.new(self, &block)
26
25
  end
27
26
 
28
27
  def self.use(middleware, *args, &block)
29
- app.use(middleware, *args, &block)
28
+ __middleware.unshift(Proc.new { |app| middleware.new(app, *args, &block) })
30
29
  end
31
30
 
32
- def self.plugin(mod, options = {})
31
+ def self.helpers(mod)
33
32
  self.include(mod)
34
33
 
35
34
  if defined?(mod::ClassMethods)
@@ -37,7 +36,7 @@ class Tynn < Syro::Deck
37
36
  end
38
37
 
39
38
  if mod.respond_to?(:setup)
40
- mod.setup(self, options)
39
+ mod.setup(self)
41
40
  end
42
41
  end
43
42
  end
data/lib/tynn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Tynn
2
- VERSION = "0.0.1.alpha1"
2
+ VERSION = "0.0.1"
3
3
  end
data/makefile CHANGED
@@ -1,2 +1,2 @@
1
1
  default:
2
- cutest -r ./test/helper.rb ./test/*.rb
2
+ cutest ./test/*.rb
data/test/hello.rb CHANGED
@@ -1,18 +1,15 @@
1
1
  require_relative "helper"
2
2
 
3
- setup do
4
- Driver.new(Tynn)
5
- end
6
-
7
- test "hello world" do |app|
3
+ test "hello" do
8
4
  Tynn.define do
9
5
  get do
10
- res.write("hello world")
6
+ res.write("hello")
11
7
  end
12
8
  end
13
9
 
10
+ app = Driver.new(Tynn)
14
11
  app.get("/")
15
12
 
16
13
  assert_equal 200, app.res.status
17
- assert_equal "hello world", app.res.body
14
+ assert_equal "hello", app.res.body
18
15
  end
data/test/helper.rb CHANGED
@@ -1,11 +1,9 @@
1
+ $VERBOSE = ENV["VERBOSE"]
2
+
1
3
  require "cutest"
2
4
  require "rack/test"
3
5
  require_relative "../lib/tynn"
4
6
 
5
- prepare do
6
- Tynn.reset!
7
- end
8
-
9
7
  class Driver
10
8
  include Rack::Test::Methods
11
9
 
@@ -6,17 +6,13 @@ module Helper
6
6
  end
7
7
 
8
8
  module Number
9
- def self.setup(app, options = {})
10
- app.settings[:number] = options.fetch(:number, 1)
11
- end
12
-
13
9
  def number
14
- return settings[:number]
10
+ return 1
15
11
  end
16
12
  end
17
13
 
18
- def self.setup(app, options = {})
19
- app.plugin(Number, options)
14
+ def self.setup(app)
15
+ app.helpers(Number)
20
16
  end
21
17
 
22
18
  module ClassMethods
@@ -30,8 +26,8 @@ setup do
30
26
  Driver.new(Tynn)
31
27
  end
32
28
 
33
- test "plugin" do |app|
34
- Tynn.plugin(Helper)
29
+ test "helpers" do |app|
30
+ Tynn.helpers(Helper)
35
31
 
36
32
  Tynn.define do
37
33
  get do
@@ -46,7 +42,7 @@ test "plugin" do |app|
46
42
  end
47
43
 
48
44
  test "setup" do |app|
49
- Tynn.plugin(Helper)
45
+ Tynn.helpers(Helper)
50
46
 
51
47
  Tynn.define do
52
48
  res.write(number)
@@ -56,15 +52,3 @@ test "setup" do |app|
56
52
 
57
53
  assert_equal "1", app.res.body
58
54
  end
59
-
60
- test "setup with options" do |app|
61
- Tynn.plugin(Helper, number: 2)
62
-
63
- Tynn.define do
64
- res.write(number)
65
- end
66
-
67
- app.get("/")
68
-
69
- assert_equal "2", app.res.body
70
- end
data/test/middleware.rb CHANGED
@@ -13,42 +13,57 @@ class Shrimp
13
13
  end
14
14
 
15
15
  setup do
16
- Driver.new(Tynn)
16
+ Tynn.__middleware.clear
17
17
  end
18
18
 
19
- test "use middleware in main application" do |app|
19
+ test "use middleware in main application" do
20
20
  Tynn.use(Shrimp)
21
21
 
22
- class API < Tynn
23
- end
24
-
25
- API.define do
22
+ Tynn.define do
26
23
  get do
27
- res.write("2")
28
24
  res.write("1")
25
+ res.write("2")
29
26
  end
30
27
  end
31
28
 
29
+ app = Driver.new(Tynn)
30
+ app.get("/")
31
+
32
+ assert_equal 200, app.res.status
33
+ assert_equal "21", app.res.body
34
+ end
35
+
36
+ test "use middleware with composition" do
37
+ Tynn.use(Shrimp)
38
+
32
39
  Tynn.define do
33
40
  on "api" do
34
41
  run(API)
35
42
  end
43
+ end
36
44
 
45
+ class API < Tynn
46
+ end
47
+
48
+ API.define do
37
49
  get do
38
50
  res.write("1")
39
51
  res.write("2")
40
52
  end
41
53
  end
42
54
 
43
- app.get("/")
55
+ app = Driver.new(Tynn)
56
+ app.get("/api")
44
57
 
45
58
  assert_equal 200, app.res.status
46
59
  assert_equal "21", app.res.body
47
60
  end
48
61
 
49
- test "use middleware in child application" do
62
+ test "use middleware only in child application" do
50
63
  Tynn.define do
51
- run(API)
64
+ on "api" do
65
+ run(API)
66
+ end
52
67
  end
53
68
 
54
69
  class API < Tynn
@@ -64,7 +79,7 @@ test "use middleware in child application" do
64
79
 
65
80
  app = Driver.new(Tynn)
66
81
 
67
- app.get("/")
82
+ app.get("/api")
68
83
 
69
84
  assert_equal 200, app.res.status
70
85
  assert_equal "21", app.res.body
data/tynn.gemspec CHANGED
@@ -3,7 +3,7 @@ require_relative "lib/tynn/version"
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "tynn"
5
5
  s.version = Tynn::VERSION
6
- s.summary = ""
6
+ s.summary = "Simple library to create Rack applications"
7
7
  s.description = s.summary
8
8
  s.authors = ["Francesco Rodríguez"]
9
9
  s.email = ["frodsan@protonmail.ch"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tynn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha1
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodríguez
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.6.3
83
- description: ''
83
+ description: Simple library to create Rack applications
84
84
  email:
85
85
  - frodsan@protonmail.ch
86
86
  executables: []
@@ -97,8 +97,8 @@ files:
97
97
  - test/composition.rb
98
98
  - test/hello.rb
99
99
  - test/helper.rb
100
+ - test/helpers.rb
100
101
  - test/middleware.rb
101
- - test/plugin.rb
102
102
  - test/settings.rb
103
103
  - tynn.gemspec
104
104
  homepage: https://github.com/harmoni/tynn
@@ -116,13 +116,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - ">"
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
- version: 1.3.1
121
+ version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
124
  rubygems_version: 2.4.8
125
125
  signing_key:
126
126
  specification_version: 4
127
- summary: ''
127
+ summary: Simple library to create Rack applications
128
128
  test_files: []