tansu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6a494e03db5288f809efafa34da0b9e6ce81bad
4
+ data.tar.gz: be13adff36064062a618995ad8ccc19d020f4aee
5
+ SHA512:
6
+ metadata.gz: 84c2f35cca74ccdcb48cba1c47ed2648cf1c77945b75219e291dd481bbe58560f7a11d086cfc2afecf733226fe8b23cc1d5b153711e282fbf7ab3ac46bf60915
7
+ data.tar.gz: fec37752fc4a277e8a106ed6cf5289a17be7639f1006b636101c494e8fea23e65400a462625b7cd22686474db9fa147d1af3e78f646da9acb252911f0306413d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ *.swp
3
+ .ruby-version
4
+ .bundle
5
+ .DS_Store
6
+ Gemfile.lock
7
+ coverage
8
+ pkg
9
+ vendor/bundle
10
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 daisuko
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
@@ -0,0 +1,24 @@
1
+ # Tansu
2
+
3
+ Tansu is a web-application framework.
4
+
5
+ ## Installation
6
+
7
+ `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'tansu'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tansu
20
+
21
+ ## License
22
+
23
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
24
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "spec"
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tansu"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,49 @@
1
+ module Tansu
2
+ class Application
3
+ class << self
4
+ attr_accessor :before, :after
5
+ end
6
+
7
+ def call(env)
8
+ Application.before.() if Application.before
9
+
10
+ response = action(env)
11
+
12
+ Application.after.() if Application.after
13
+
14
+ response
15
+ end
16
+
17
+ private
18
+
19
+ def action(env)
20
+ request = Rack::Request.new(env)
21
+ environment = Environment.new(request, Rack::Response.new)
22
+
23
+ path = parse(request.path_info)
24
+ router = path.inject(Tansu.root) { |a, e| a[e] }[request.request_method]
25
+
26
+ if Minicontext::Router::Just === router
27
+ response = router.value.(environment).response
28
+
29
+ Rack::Response === response ? response : internal_server_error
30
+ else
31
+ not_found
32
+ end
33
+ end
34
+
35
+ def parse(path)
36
+ ret = (path[1..-1] || '').split('/').map(&:to_sym)
37
+
38
+ ret.empty? ? [:*] : ret
39
+ end
40
+
41
+ def internal_server_error
42
+ ['500', { 'Context-Type' => 'text/html' }, ['internal server error.']]
43
+ end
44
+
45
+ def not_found
46
+ ['404', { 'Context-Type' => 'text/html' }, ['not found.']]
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,16 @@
1
+ module Tansu
2
+ class Context < Minicontext::Context
3
+ METHODS = %w(GET POST PATCH PUT DELETE)
4
+ KEYWORD = Minicontext::Context::KEYWORD + METHODS
5
+
6
+ METHODS.each do |method|
7
+ define_method(method.downcase.to_sym) do |name, &block|
8
+ context(name) { task method, &block }
9
+ end
10
+ end
11
+
12
+ def call(name)
13
+ (val = super(name)) ? val : super(:*)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module Tansu
2
+ class Environment < Minicontext::Environment
3
+ def bind(val)
4
+ res = if Minicontext::Halt === val || Rack::Response === val
5
+ val
6
+ elsif val.respond_to?(:each)
7
+ response.body = val
8
+
9
+ response
10
+ elsif Fixnum === val
11
+ response.status = val
12
+
13
+ response
14
+ elsif String === val
15
+ response.body = [val]
16
+
17
+ response
18
+ else
19
+ nil
20
+ end
21
+
22
+ super res
23
+ end
24
+
25
+ def redirect(uri, status = 302)
26
+ response.redirect(uri, status)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Tansu
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tansu.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "tansu/version"
2
+ require "tansu/context"
3
+ require "tansu/environment"
4
+ require "tansu/application"
5
+
6
+ module Tansu
7
+ class << self
8
+ def application
9
+ Application.new
10
+ end
11
+
12
+ def root
13
+ @root ||= Context.new
14
+ end
15
+ end
16
+ end
data/tansu.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tansu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tansu"
8
+ spec.version = Tansu::VERSION
9
+ spec.authors = ["daisuko"]
10
+ spec.email = ["striker.daisuko@gmail.com"]
11
+
12
+ spec.summary = %q{Tansu is a web-application framework.}
13
+ spec.homepage = "https://github.com/daisuko/tansu"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rack"
23
+ spec.add_dependency "minicontext"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest"
28
+ spec.add_development_dependency "rack-test"
29
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tansu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - daisuko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: minicontext
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - striker.daisuko@gmail.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - lib/tansu.rb
116
+ - lib/tansu/application.rb
117
+ - lib/tansu/context.rb
118
+ - lib/tansu/environment.rb
119
+ - lib/tansu/version.rb
120
+ - tansu.gemspec
121
+ homepage: https://github.com/daisuko/tansu
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.5
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Tansu is a web-application framework.
145
+ test_files: []