evrone-common-rack-builder 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2eacfc8ae9b3c2a04d54b942e13707cca59731fa
4
+ data.tar.gz: 840d408c8bacd02845616c1618fb3d3d4834b855
5
+ SHA512:
6
+ metadata.gz: b81a6f1efa94c2c5cf8e5469931147a8d19771b1f15c1805cdfdc3a0c86d653865e36e6254c6c5b6ff76e8e649db647bacee98894dcbb495716d8a437708ed03
7
+ data.tar.gz: 57c0e41436f533621e1d1762cee461281f61db2dc66d9e1060d591a759365d39b2ef66d26f2827ff677dcdc11af0003d55af8aed763fd3f66ec0dd4ecec5600d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ script: rake --color -fd --order=rand
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in evrone-common-rack-builder.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012 Christian Neukirchen <purl.org/net/chneukirchen>
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
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell 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
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Evrone::Common::Rack::Builder
2
+
3
+ The Rack::Builder extracted from Rack
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'evrone-common-rack-builder'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install evrone-common-rack-builder
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'evrone/common/rack/builder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "evrone-common-rack-builder"
8
+ spec.version = Evrone::Common::Rack::Builder::VERSION
9
+ spec.authors = ["Dmitry Galinsky"]
10
+ spec.email = ["dima.exe@gmail.com"]
11
+ spec.description = %q{ The Rack::Builder extracted from Rack }
12
+ spec.summary = %q{ The Rack::Builder extracted from Rack }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,75 @@
1
+ require "evrone/common/rack/builder/version"
2
+
3
+ module Evrone
4
+ module Common
5
+ module Rack
6
+
7
+ class Builder
8
+ def initialize(default_app = nil,&block)
9
+ @use, @map, @run = [], nil, default_app
10
+ instance_eval(&block) if block_given?
11
+ end
12
+
13
+ def self.app(default_app = nil, &block)
14
+ self.new(default_app, &block).to_app
15
+ end
16
+
17
+ # Specifies middleware to use in a stack.
18
+ #
19
+ # class Middleware
20
+ # def initialize(app)
21
+ # @app = app
22
+ # end
23
+ #
24
+ # def call(env)
25
+ # env["rack.some_header"] = "setting an example"
26
+ # @app.call(env)
27
+ # end
28
+ # end
29
+ #
30
+ # use Middleware
31
+ # run lambda { |env| [200, { "Content-Type => "text/plain" }, ["OK"]] }
32
+ #
33
+ # All requests through to this application will first be processed by the middleware class.
34
+ # The +call+ method in this example sets an additional environment key which then can be
35
+ # referenced in the application if required.
36
+ def use(middleware, *args, &block)
37
+ if @map
38
+ mapping, @map = @map, nil
39
+ @use << proc { |app| generate_map app, mapping }
40
+ end
41
+ @use << proc { |app| middleware.new(app, *args, &block) }
42
+ end
43
+
44
+ # Takes an argument that is an object that responds to #call and returns a Rack response.
45
+ # The simplest form of this is a lambda object:
46
+ #
47
+ # run lambda { |env| [200, { "Content-Type" => "text/plain" }, ["OK"]] }
48
+ #
49
+ # However this could also be a class:
50
+ #
51
+ # class Heartbeat
52
+ # def self.call(env)
53
+ # [200, { "Content-Type" => "text/plain" }, ["OK"]]
54
+ # end
55
+ # end
56
+ #
57
+ # run Heartbeat
58
+ def run(app)
59
+ @run = app
60
+ end
61
+
62
+ def to_app
63
+ app = @run
64
+ fail "missing run or map statement" unless app
65
+ @use.reverse.inject(app) { |a,e| e[a] }
66
+ end
67
+
68
+ def call(env)
69
+ to_app.call(env)
70
+ end
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ module Evrone
2
+ module Common
3
+ module Rack
4
+ class Builder
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Evrone::Common::Rack::Builder do
4
+ First = Struct.new(:app) do
5
+ def call(env)
6
+ env << 'first.begin'
7
+ app.call(env)
8
+ env << 'first.end'
9
+ end
10
+ end
11
+
12
+ Last = Struct.new(:app) do
13
+ def call(env)
14
+ env << 'last.begin'
15
+ app.call(env)
16
+ env << 'last.end'
17
+ end
18
+ end
19
+
20
+ let(:builder) {
21
+ described_class.new do
22
+ use First
23
+ use Last
24
+ end
25
+ }
26
+
27
+ subject { builder }
28
+
29
+ it "should be work" do
30
+ env = []
31
+ app = ->(c){ c << 'run' }
32
+ builder.run app
33
+ rs = builder.call env
34
+ expect(rs).to eq %w{ first.begin last.begin run last.end first.end }
35
+ end
36
+ end
37
+
@@ -0,0 +1,2 @@
1
+ require 'rspec/autorun'
2
+ require File.expand_path("../../lib/evrone/common/rack/builder", __FILE__)
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evrone-common-rack-builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Galinsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ' The Rack::Builder extracted from Rack '
56
+ email:
57
+ - dima.exe@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - evrone-common-rack-builder.gemspec
69
+ - lib/evrone/common/rack/builder.rb
70
+ - lib/evrone/common/rack/builder/version.rb
71
+ - spec/lib/builder_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: The Rack::Builder extracted from Rack
97
+ test_files:
98
+ - spec/lib/builder_spec.rb
99
+ - spec/spec_helper.rb