satriani 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 357289fe292b1cb8f5ad1ee76b1d0f1d5ee3562e
4
- data.tar.gz: 220ef1bdab31fc04f8847402142e76ab3da56cb2
3
+ metadata.gz: edfdeacc0faf46cfa16e55e6fb23e85b956885ee
4
+ data.tar.gz: d3660fd8a6316d51c51b746747d91ef4010624d7
5
5
  SHA512:
6
- metadata.gz: 6f51ddc7e4582f966940e32cf7f5af5dd013515bcbeea70fd48ad5cac15e55c7794b637b69fab7216f96fd9eb9d29b73d159b69a1c34e02b9e7f7939a811677a
7
- data.tar.gz: 8f0737d5a2e96dd6baff4485bab416eaad9c31c0b4fab152f1bd818427acac1b636b34a290c0e8948e85423ef996c45310097ca7802b275ab92462d05b202201
6
+ metadata.gz: b1c3890f3b1e9e48235f4e1b98be86789f7143e55089bd8b9506affa55062669c0d4b8ca43225675fe3837c33b46b4e999757d00da627b7138829e91a0539877
7
+ data.tar.gz: 28bdc522544b97ee1b163475cd88a819534e76dd0f1a630702cfda787186cbef691254ea97a8ce567a3ff12011a07c8c8d3ab680f6288dd9fc5c8b727983a348
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
@@ -1,5 +1,13 @@
1
1
  require "satriani/version"
2
+ require "satriani/application"
2
3
 
3
4
  module Satriani
4
-
5
+
6
+ def self.define(&block)
7
+ @instance = Satriani::Application.new(&block)
8
+ end
9
+
10
+ def self.instance
11
+ @instance
12
+ end
5
13
  end
@@ -0,0 +1,129 @@
1
+ # Adapted from -> Rum, the gRand Unified Mapper
2
+ #
3
+ # @see http://github.com/chneukirchen/rum
4
+
5
+ require "rack"
6
+
7
+ class Rack::Response
8
+ def redirect(target, status = 302)
9
+ self.status = status
10
+ self["Location"] = target
11
+ end
12
+ end
13
+
14
+ module Satriani
15
+ class Application
16
+ attr_reader :env, :req, :res
17
+
18
+ def initialize(&block)
19
+ @block = block
20
+ end
21
+
22
+ def call(env)
23
+ dup._call(env)
24
+ end
25
+
26
+ def _call(env)
27
+ @env = env
28
+ @req = Rack::Request.new(env)
29
+ @res = Rack::Response.new
30
+ @matched = false
31
+ catch(:satriani_run_next_app) {
32
+ instance_eval(&@block)
33
+ @res.status = 404 unless @matched || !@res.empty?
34
+ return @res.finish
35
+ }.call(env)
36
+ end
37
+
38
+ def on(*arg, &block)
39
+ return if @matched
40
+ s, p = env["SCRIPT_NAME"], env["PATH_INFO"]
41
+ yield *arg.map { |a| a == true || (a != false && a.call) || return }
42
+ env["SCRIPT_NAME"], env["PATH_INFO"] = s, p
43
+ @matched = true
44
+ end
45
+
46
+ def any(*args)
47
+ args.any? { |a| a == true || (a != false && a.call) }
48
+ end
49
+
50
+ def also
51
+ @matched = false
52
+ end
53
+
54
+ def path(p)
55
+ lambda {
56
+ if env["PATH_INFO"] =~ /\A\/(#{p})(\/|\z)/
57
+ env["SCRIPT_NAME"] += "/#{$1}"
58
+ env["PATH_INFO"] = $2 + $'
59
+ $1
60
+ end
61
+ }
62
+ end
63
+
64
+ def number
65
+ path("\\d+")
66
+ end
67
+
68
+ def segment
69
+ path("[^\\/]+")
70
+ end
71
+
72
+ def extension(e="\\w+")
73
+ lambda { env["PATH_INFO"] =~ /\.(#{e})\z/ && $1 }
74
+ end
75
+
76
+ def param(p, default = nil)
77
+ lambda { request[p] || default }
78
+ end
79
+
80
+ def header(p, default = nil)
81
+ lambda { env[p.upcase.tr('-','_')] || default }
82
+ end
83
+
84
+ def default
85
+ true
86
+ end
87
+
88
+ def host(h)
89
+ req.host == h
90
+ end
91
+
92
+ def method(m)
93
+ req.request_method = m
94
+ end
95
+
96
+ def get; req.get?; end
97
+ def post; req.post?; end
98
+ def put; req.put?; end
99
+ def delete; req.delete?; end
100
+
101
+ def accept(mimetype)
102
+ lambda do
103
+ env['HTTP_ACCEPT'].split(',').any? { |s| s.strip == mimetype } &&
104
+ res['Content-Type'] = mimetype
105
+ end
106
+ end
107
+
108
+ def check(&block)
109
+ block
110
+ end
111
+
112
+ def run(app)
113
+ throw :satriani_run_next_app, app
114
+ end
115
+
116
+ def puts(*args)
117
+ args.each do |s|
118
+ res.write s
119
+ res.write "\n"
120
+ end
121
+ end
122
+
123
+ def print(*args)
124
+ args.each do |s|
125
+ res.write s
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,3 +1,3 @@
1
1
  module Satriani
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -11,11 +11,13 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Study purpose only gem."
12
12
  spec.homepage = "http://github.com/marceloboeira/satriani"
13
13
  spec.license = "MIT"
14
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|example)/}) }
15
15
  spec.bindir = "exe"
16
16
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_development_dependency "bundler", "~> 1.10"
20
20
  spec.add_development_dependency "rake", "~> 10.0"
21
- end
21
+
22
+ spec.add_dependency "rack", ">= 1.1.0"
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: satriani
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Boeira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.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.1.0
41
55
  description:
42
56
  email:
43
57
  - me@marceloboeira.com
@@ -53,6 +67,7 @@ files:
53
67
  - bin/console
54
68
  - bin/setup
55
69
  - lib/satriani.rb
70
+ - lib/satriani/application.rb
56
71
  - lib/satriani/version.rb
57
72
  - satriani.gemspec
58
73
  homepage: http://github.com/marceloboeira/satriani
@@ -75,8 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
90
  version: '0'
76
91
  requirements: []
77
92
  rubyforge_project:
78
- rubygems_version: 2.4.8
93
+ rubygems_version: 2.4.7
79
94
  signing_key:
80
95
  specification_version: 4
81
96
  summary: Study purpose only gem.
82
97
  test_files: []
98
+ has_rdoc: