bats 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00046bcaaeda3ff965bebd405f0a03b367dd6500
4
+ data.tar.gz: c4a3f5280aedb96615f2981e073025a48b68f79a
5
+ SHA512:
6
+ metadata.gz: 5c1d583e920304cded4b0a6969f726ee8f2d3aeedb27dd43e60e4e57ba29c547e657c4d1916da8482c3a5fc3b2117b20712cebd3b9c6edb1913e68d0824e3f3c
7
+ data.tar.gz: e00329b45b8ebe6c433bdcf17ae44c7e7c49704096a6828a1f79f50369190c2ed687b0069da8c0caac1ef35e62a6aeb909eb6ec08505605b938537ccafc58f1b
@@ -1,5 +1,5 @@
1
- %w( httpresponse wizarding ).each do |f|
2
- require 'bats/modules/httpresponse'
1
+ %w(httpresponse wizarding).each do |f|
2
+ require_relative "bats/modules/#{f}"
3
3
  end
4
4
 
5
5
  class Bats
@@ -8,48 +8,49 @@ class Bats
8
8
  traits :routes
9
9
 
10
10
  def self.inherited c
11
- c.traits *traits.keys
11
+ c.traits(*traits.keys)
12
12
  end
13
13
 
14
14
  def self.addRoute m, p, o = nil, &b
15
- @traits[ :routes ] ||= {}
16
- @traits[ :routes ][ m ] ||= {}
17
- @traits[ :routes ][ m ][ p ] = ( block_given? ) ? b : o
15
+ @traits[:routes] ||= {}
16
+ @traits[:routes][m] ||= {}
17
+ @traits[:routes][m][p] = (block_given?) ? b : o
18
18
  end
19
19
 
20
- def self.get p, o = nil, &b; addRoute( :get, p, o, &b ); end
21
- def self.post p, o = nil, &b; addRoute( :post, p, o, &b ); end
22
- def self.put p, o = nil, &b; addRoute( :put, p, o, &b ); end
23
- def self.delete p, o = nil, &b; addRoute( :delete, p, o, &b ); end
20
+ [:get, :post, :put, :delete].each do |m|
21
+ self.class.send(:define_method, m) do |p, o = nil, &b|
22
+ addRoute(m, p, o, &b)
23
+ end
24
+ end
24
25
 
25
26
  def self.redirect l, isTemporary = true
26
- i = ( isTemporary ) ? '307' : '301'
27
- s( i ).headers( :Location => l )
27
+ i = (isTemporary) ? '307' : '301'
28
+ s(i).headers("Location" => l)
28
29
  end
29
30
 
30
31
  def self.s i
31
- Class.new( ::HTTPResponse.const_get( "Status#{i}" ) )
32
+ Class.new(::HTTPResponse.const_get("Status#{i}"))
32
33
  end
33
34
 
34
35
  def s i
35
- Class.new( ::HTTPResponse.const_get( "Status#{i}" ) )
36
+ Class.new(::HTTPResponse.const_get("Status#{i}"))
36
37
  end
37
38
 
38
- def self.call env; new.call( env ); end
39
+ def self.call env; new.call(env); end
39
40
  def call env
40
- method = env[ 'REQUEST_METHOD' ].downcase.to_sym
41
- path = env[ 'PATH_INFO' ]
41
+ method = env['REQUEST_METHOD'].downcase.to_sym
42
+ path = env['PATH_INFO']
42
43
  matches ||= nil
43
44
  if @routes && @routes[method] then
44
- if @routes[method].include?( path ) then
45
- route = @routes[method][ path ]
45
+ if @routes[method].include?(path) then
46
+ route = @routes[method][path]
46
47
  else
47
48
  @routes[method].each do | p, b |
48
- if p.kind_of?( Regexp ) then
49
- if matches = path.match( p ) then
50
- matches = matches[ 1, matches.length - 1 ]
49
+ if p.kind_of?(Regexp) then
50
+ if matches = path.match(p) then
51
+ matches = matches[1, matches.length - 1]
51
52
  matches.map! do | i |
52
- i = ( i ) ? i : ''
53
+ i = (i) ? i : ''
53
54
  i = i.to_i if i =~ /^\d+$/
54
55
  i
55
56
  end
@@ -60,16 +61,16 @@ class Bats
60
61
  end
61
62
  end
62
63
  end
63
- route ||= s( 404 )
64
- args = ( matches ) ? [ env, *matches ] : [ env ]
64
+ route ||= s(404)
65
+ args = (matches) ? [env, *matches] : [env]
65
66
  begin
66
- route = route.call( *args ) if route.kind_of?( Proc )
67
- route.call( env )
67
+ route = route.call(*args) if route.kind_of?(Proc)
68
+ route.call(env)
68
69
  rescue
69
70
  b = '<h1>Ooops... The code broke.</h1>'
70
- b += "<h3>#{$!.to_s}</h3>#{$!.backtrace.join( '<br/>' )}"
71
+ b += "<h3>#{$!.to_s}</h3>#{$!.backtrace.join('<br/>')}"
71
72
  route = s(500).body b
72
- route.call( env )
73
+ route.call(env)
73
74
  end
74
75
  end
75
76
  end
metadata CHANGED
@@ -1,70 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bats
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Hans Oksendahl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2009-11-13 00:00:00 -08:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rack
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
11
+ date: 2015-08-08 00:00:00.000000000 Z
12
+ dependencies: []
25
13
  description:
26
14
  email: hansoksendahl@gmail.com
27
15
  executables: []
28
-
29
16
  extensions: []
30
-
31
- extra_rdoc_files:
32
- - README
33
- files:
34
- - lib/bats/modules/httpresponse.rb
35
- - lib/bats/modules/classbaker.rb
36
- - lib/bats/modules/wizarding.rb
37
- - lib/bats/modules/metaid.rb
38
- - lib/bats/yaml/statuses.yaml
17
+ extra_rdoc_files: []
18
+ files:
39
19
  - lib/bats.rb
40
- - README
41
- has_rdoc: true
42
- homepage: http://hansoksendahl.com/bats
43
- licenses: []
44
-
20
+ homepage: https://rubygems.org/gems/bats
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
45
24
  post_install_message:
46
25
  rdoc_options: []
47
-
48
- require_paths:
26
+ require_paths:
49
27
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
51
- requirements:
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
52
30
  - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
55
- version:
56
- required_rubygems_version: !ruby/object:Gem::Requirement
57
- requirements:
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
58
35
  - - ">="
59
- - !ruby/object:Gem::Version
60
- version: "0"
61
- version:
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
62
38
  requirements: []
63
-
64
39
  rubyforge_project:
65
- rubygems_version: 1.3.5
40
+ rubygems_version: 2.4.6
66
41
  signing_key:
67
- specification_version: 3
42
+ specification_version: 4
68
43
  summary: A microframework built on Rack.
69
44
  test_files: []
70
-
data/README DELETED
@@ -1,23 +0,0 @@
1
- ~~~(^._.^)~~~ Bats!
2
-
3
- A micro-framework.
4
-
5
- Bats! implements an easy to use router on top of Rack for handling REST
6
- requests. This makes getting an app up and running ridiculously easy.
7
-
8
- Bats! stays out of your way. It doesn't ask you to use any particular
9
- development methodology, templating framework, or other such tom-foolery.
10
-
11
- Example usage:
12
-
13
- # config.ru
14
-
15
- require 'bats'
16
-
17
- class App < Bats
18
- get '/' do
19
- s( 200 ).b 'Flap flap flap'
20
- end
21
- end
22
-
23
- run App
@@ -1,26 +0,0 @@
1
- %w( metaid wizarding ).each { | f | require "bats/modules/#{f}" }
2
-
3
- module ClassBaker
4
- include Metaid
5
-
6
- def makeClass n, c = nil
7
- c = ( c.nil? ) ? Class.new : c
8
- c = ( c.is_a?( String ) ) ? Class.new( const_get( c ) ) : c
9
- const_set n, c
10
- c
11
- end
12
-
13
- def bakeClass h
14
- h.each do | c, o |
15
- t = o.include?( :inherit ) ? o[ :inherit ] : nil
16
- o.delete( :inherit )
17
- i = makeClass( c, t )
18
- i.extend( Wizarding )
19
- unless o.empty? then
20
- i.traits *o.keys
21
- o.each { | k, v | i.send( k, v ) }
22
- end
23
- end
24
- end
25
-
26
- end
@@ -1,42 +0,0 @@
1
- require 'bats/modules/classbaker'
2
-
3
- module HTTPResponse
4
- extend ClassBaker
5
-
6
- class Response
7
- extend ::Wizarding
8
-
9
- traits :body, :headers, :status
10
-
11
- def self.call env; new.call( env ); end
12
-
13
- def self.h h
14
- @traits[:headers].merge!( h )
15
- self
16
- end
17
-
18
- def self.b b
19
- @traits[:body] = b
20
- self
21
- end
22
-
23
- def call env
24
- @headers.merge! 'Content-Length' => @body.length.to_s
25
- [ @status, @headers, @body ]
26
- end
27
- end
28
-
29
- require 'yaml'
30
- statuses = YAML.load_file( "#{File.expand_path( '../yaml', File.dirname( __FILE__ ) )}/statuses.yaml" ) # Somewhere in the nether regions beyond column 80!
31
- statuses.each do | k, v |
32
- bakeClass(
33
- "Status#{k}" => {
34
- :inherit => 'Response',
35
- :status => k,
36
- :headers => v[0],
37
- :body => v[1]
38
- }
39
- )
40
- end
41
-
42
- end
@@ -1,16 +0,0 @@
1
- # Sorry _why I don't feel like extending Ruby's Object class.
2
- module Metaid
3
- def metaclass; class << self; self; end; end
4
-
5
- def meta_eval &b
6
- metaclass.instance_eval &b
7
- end
8
-
9
- def meta_def( n, &b )
10
- meta_eval { define_method( n, &b ) }
11
- end
12
-
13
- def class_def( n, &b )
14
- class_eval { define_method( n, &b ) }
15
- end
16
- end
@@ -1,28 +0,0 @@
1
- require 'bats/modules/metaid'
2
-
3
- module Wizarding
4
- include Metaid
5
-
6
- def traits *a
7
- return @traits if a.empty?
8
- attr_accessor *a
9
- a.each do | m |
10
- @traits ||= {}
11
- @traits[m] = nil
12
- meta_def m do | *v |
13
- @traits[m] = v[0] unless v.empty?
14
- ( v.empty? ) ? @traits[m] : self
15
- end
16
- end
17
- class_def :initialize do
18
- self.class.traits.each do | k, v |
19
- instance_variable_set( "@#{k}", v )
20
- end
21
- end
22
- end
23
-
24
- def inherited c
25
- c.traits *traits.keys
26
- c.instance_variable_set( :@traits, traits.dup )
27
- end
28
- end
@@ -1,21 +0,0 @@
1
- 404:
2
- - Content-Type: text/plain
3
- - '404: Page not found.'
4
- 301:
5
- - Content-Type: text/html
6
- Location: '/'
7
- - '301: Moved Permanently.'
8
- 307:
9
- - Content-Type: text/html
10
- Location: '/'
11
- - '307: Moved Temporarily.'
12
- 200:
13
- - Content-Type: text/html
14
- - '200: Page Successfully Loaded.'
15
- 401:
16
- - Content-Type: text/html
17
- WWW-Authenticate: 'Basic Realm="Bats! Authentication"'
18
- - '401: Unauthorized!'
19
- 500:
20
- - Content-Type: text/html
21
- - '500: Oh noes... an error.'