woah 1.2.1 → 1.2.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
  SHA256:
3
- metadata.gz: 9301cad20ebaf896c239f25ade186b723f9f01a09493557590fbaff7da1bb610
4
- data.tar.gz: 7165d88451d5d03d397e38602818ac2d972b7b4384e6cbaa97dd1419024c9c7c
3
+ metadata.gz: cb45f60031e5467ff757e5095e822a7bef583a6225840bfc917b2795afd40bc3
4
+ data.tar.gz: 63afa8fe95815849bdd0f2362336cc21d50ebb902e3b8c424d6891c586f3a3da
5
5
  SHA512:
6
- metadata.gz: aa9663c853c588d9c2bf66f2b2be756233e4b5a76e7d795fe65fdec9adfc1aa0f3619e76693db42a70ab49162aaaa5446b7966114f64438caf7c4fd550d5452e
7
- data.tar.gz: b562426f30b5b5a0aa0123a0e34fbfe5ed196d59a8e46dc683e48833dd1f9ae55e828b033fca637329ca9c00921382e9aa64ce612904364ef72658a9dbd247b8
6
+ metadata.gz: 29cb1e9b4287a3ee58d25c1db92138d7eb1572e6665bcefcfc4679908639d8af4a5d0d3b7a1e01b906fcbc2d3ae8584fc1530737e66d8e098f4472d4c85acb45
7
+ data.tar.gz: 39c4fa1fa939c57a4ccc44eeb27e5c46689995a4394691d7f51c0300aade6d0772ae881bc11ec25c55ce0251ccaf2d86259bcc2ba90770897b2ea536c43fdd5a
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Woah!
2
2
  [![Build Status](https://travis-ci.org/knarka/woah.svg?branch=master)](https://travis-ci.org/knarka/woah)
3
3
  [![Coverage Status](https://coveralls.io/repos/github/knarka/woah/badge.svg?branch=master&service=github)](https://coveralls.io/github/knarka/woah?branch=master)
4
+ [![Code Climate](https://codeclimate.com/github/knarka/woah/badges/gpa.svg)](https://codeclimate.com/github/knarka/woah)
4
5
  [![Gem Version](https://badge.fury.io/rb/woah.svg)](https://badge.fury.io/rb/woah)
5
6
 
6
7
  Woah! is an unobtrusive, (extremely) minimal web framework built on Rack.
@@ -89,7 +90,7 @@ class MyApp < Woah::Base
89
90
  end
90
91
  ```
91
92
 
92
- Now, visiting `/greet/Socrates` will greet you with your own name. Wonderful. By the way, you may have noticed the regex here is delimited by `%r{}`, instead of the more common `//`. This is because of how common slashes are in routes, so it's recommended to use this syntax. You can use slashes to delimit your regex though, if you like. I won't judge you.
93
+ Now, visiting `/greet/Socrates` will greet you with your own name (assuming your name is Socrates). Wonderful. By the way, you may have noticed the regex here is delimited by `%r{}`, instead of the more common `//`. This is because of how common slashes are in routes, so it's recommended to use this syntax. You can use slashes to delimit your regex though, if you like. I won't judge you.
93
94
 
94
95
  Redirects are possible as well:
95
96
 
data/lib/woah/base.rb CHANGED
@@ -5,13 +5,12 @@ module Woah
5
5
  class Base
6
6
  @@before = nil
7
7
  @@after = nil
8
- @@match = nil
9
- @@request = nil
10
8
  @@routes = []
11
9
 
12
10
  def initialize
13
11
  @@override = {}
14
12
  @@match = nil
13
+ @@request = nil
15
14
  @@response = nil
16
15
  end
17
16
 
@@ -47,7 +46,7 @@ module Woah
47
46
 
48
47
  # Resolves and executes a round
49
48
  # @param path [String, Regexp] the path to respond to
50
- # @param method [String] the HHTP method to use
49
+ # @param method [String] the HTTP method to use
51
50
  # @return [Hash] the route's response
52
51
  def resolve_route(path, method)
53
52
  route = @@routes.select { |r| r.matches?(method, path) }[0]
@@ -72,15 +71,15 @@ module Woah
72
71
  end
73
72
 
74
73
  # Get this show on the road.
75
- # @host [String] the host to use
76
- # @port [Integer] the port to use
74
+ # @param host [String] the host to use
75
+ # @param port [Integer] the port to use
77
76
  def run!(host = '0.0.0.0', port = 4422)
78
77
  Rack::Handler.pick(%w[thin puma]).run new, Host: host, Port: port
79
78
  end
80
79
 
81
80
  # Register new routes. The optional method argument can be used to specify a method
82
81
  # @param path [String, Regexp] the path to respond to
83
- # @param method [String] the HHTP method to use
82
+ # @param method [String] the HTTP method to use
84
83
  # @raise [ArgumentError] if `method` is not a valid HTTP method
85
84
  def on(path, method = 'GET', &action)
86
85
  unless %w[DELETE GET HEAD OPTIONS PATCH POST PUT].include? method
@@ -131,25 +130,12 @@ module Woah
131
130
  # @param key [String] the name of the cookie
132
131
  # @param value [nil, :delete, String]
133
132
  def cookie(key, value = nil)
134
- # Read cookie
135
133
  if value.nil?
136
- @@request.env['HTTP_COOKIE']&.split('; ')&.each do |c|
137
- s = c.split('=')
138
- return s[1] if s[0] == key
139
- end
140
- nil # if not found
141
-
142
- # Delete cookie
134
+ read_cookie key
143
135
  elsif value == :delete
144
- @@override[:headers] = {}
145
- Rack::Utils.delete_cookie_header! @@override[:headers], key
146
-
147
- # Set cookie
136
+ del_cookie key
148
137
  elsif value.is_a? String
149
- @@override[:headers] = {}
150
- Rack::Utils.set_cookie_header! @@override[:headers], key, value
151
-
152
- # Invalid argument
138
+ set_cookie key, value
153
139
  else
154
140
  raise ArgumentError, 'Value should be either nil, :delete, or a string'
155
141
  end
@@ -164,6 +150,26 @@ module Woah
164
150
  def request
165
151
  @@request
166
152
  end
153
+
154
+ private
155
+
156
+ def read_cookie(key)
157
+ @@request.env['HTTP_COOKIE']&.split('; ')&.each do |c|
158
+ s = c.split('=')
159
+ return s[1] if s[0] == key
160
+ end
161
+ nil # if not found
162
+ end
163
+
164
+ def del_cookie(key)
165
+ @@override[:headers] ||= {}
166
+ Rack::Utils.delete_cookie_header! @@override[:headers], key
167
+ end
168
+
169
+ def set_cookie(key, value)
170
+ @@override[:headers] ||= {}
171
+ Rack::Utils.set_cookie_header! @@override[:headers], key, value
172
+ end
167
173
  end
168
174
  end
169
175
  end
data/lib/woah/route.rb CHANGED
@@ -7,6 +7,7 @@ module Woah
7
7
 
8
8
  def initialize(path, method, &action)
9
9
  raise 'only strings and regexps are valid paths' unless [String, Regexp].include? path.class
10
+
10
11
  @path = path
11
12
  @method = method
12
13
  @action = action
data/lib/woah/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Woah
4
4
  # Woah!'s current version.
5
- VERSION = '1.2.1'
5
+ VERSION = '1.2.2'
6
6
  end
data/test/test_helper.rb CHANGED
@@ -16,5 +16,6 @@ require_relative 'test_app'
16
16
 
17
17
  Dir.foreach('test/') do |test|
18
18
  next if ['.', '..'].include? test
19
+
19
20
  require_relative test
20
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woah
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - knarka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-20 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -16,16 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.5
19
+ version: 2.0.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.0.5
27
- description: "Woah! is a minimal web framework built on Rack. It's primary\n\tdesign
28
- goal is to be unobtrusive, and to just let you do your thing, dude."
26
+ version: 2.0.6
27
+ description: "Woah! is a minimal web framework built on Rack designed to let you just
28
+ do your\n\tthing."
29
29
  email: knarka@airmail.cc
30
30
  executables: []
31
31
  extensions: []