ustack 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.
Files changed (5) hide show
  1. data/README.md +75 -0
  2. data/Rakefile +1 -0
  3. data/lib/ustack.rb +19 -0
  4. data/lib/ustack/version.rb +3 -0
  5. metadata +87 -0
@@ -0,0 +1,75 @@
1
+ # Ustack
2
+
3
+ Micro middleware stack for general purpose.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ # Gemfile
9
+ gem 'ustack'
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ class M1 < Struct.new(:app)
16
+ def call(env)
17
+ puts self
18
+ puts app.call(env)
19
+ puts self
20
+ 'zzz'
21
+ end
22
+ end
23
+
24
+ class M2 < Struct.new(:app, :options)
25
+ def call(env)
26
+ puts self
27
+ options[:return]
28
+ end
29
+ end
30
+
31
+ app = Ustack.new do
32
+ use M1
33
+ use M2, return: 'xxx'
34
+ end
35
+
36
+ puts app.run
37
+ # => M1
38
+ # => M2
39
+ # => xxx
40
+ # => M1
41
+ # => zzz
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
51
+
52
+ ## License
53
+
54
+ Copyright (c) 2013 Kostiantyn Kahanskyi
55
+
56
+ MIT License
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining
59
+ a copy of this software and associated documentation files (the
60
+ "Software"), to deal in the Software without restriction, including
61
+ without limitation the rights to use, copy, modify, merge, publish,
62
+ distribute, sublicense, and/or sell copies of the Software, and to
63
+ permit persons to whom the Software is furnished to do so, subject to
64
+ the following conditions:
65
+
66
+ The above copyright notice and this permission notice shall be
67
+ included in all copies or substantial portions of the Software.
68
+
69
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
70
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
71
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
72
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
73
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
74
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
75
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,19 @@
1
+ require 'ustack/version'
2
+
3
+ class Ustack
4
+ def initialize(&block)
5
+ instance_eval(&block) if block_given?
6
+ end
7
+
8
+ def use(klass, options=nil)
9
+ @stack ||= []
10
+ @stack << [klass, options]
11
+ end
12
+
13
+ def run(env={})
14
+ @stack.reverse.each do |(klass, options)|
15
+ @app = options ? klass.new(@app, options) : klass.new(@app)
16
+ end
17
+ @app.call(env)
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ class Ustack
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ustack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kostiantyn Kahanskyi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Micro middleware stack for general purpose
47
+ email:
48
+ - kostiantyn.kahanskyi@googlemail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/ustack/version.rb
54
+ - lib/ustack.rb
55
+ - Rakefile
56
+ - README.md
57
+ homepage: https://github.com/kostia/ustack
58
+ licenses: []
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ segments:
70
+ - 0
71
+ hash: -62502703547411652
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: -62502703547411652
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.25
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Micro middleware stack for general purpose
87
+ test_files: []