server.rb 0.2.2 → 0.3.0

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: d86d66d6dd85fd989a0c7cea5e0a89003da4f93c5bbb90e8e59cb24aa92a4273
4
- data.tar.gz: 22d12221ead684c5897cd9138502370852d4869f47a965d0b4678648924baa64
3
+ metadata.gz: 3c1f5315cd2fe6ceaa25725d372a53dbf52f61477cf0798c15fd20a348b28b4d
4
+ data.tar.gz: 35df8a5fb406a8445cbb3c3bd151740dea62635c2c24e167c19bf81dce35fa1d
5
5
  SHA512:
6
- metadata.gz: ba7756e35e925bb88b6dbd82d75ad098a349b0f27fb823a766650d5683df8bc4893cc6017da46458140d059ab6e0e683b34486ff4880da2546c9e41f4f77e8c6
7
- data.tar.gz: 5fee378893a5c0f1c8984f396e2cda243f4fa24d866f2a6b0fe58dfb1db34b160320140cdc08a73196e52b6319317fae0e201290940c1294e9913e1547b50fd9
6
+ metadata.gz: 93f99747c53464ebd6781d75a99945b0e2f90e1614a5e2627e1cb08450bf92f0f7984156ae5ee4773200d191eb2da1e50c55fae3ea7b5cc406001320eb7a4574
7
+ data.tar.gz: ab565ff1c8c9e3c9fe9f6be21134582835d8c87b434012d584829618c005fba27b38ad5ae288849fe189ad9076aa356c5c4707005b9a089e4d0c1acf34d0e7df
data/lib/server/dir.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  ##
4
- # A rack application that serves the contents
5
- # of a directory over HTTP.
4
+ # {Server::Dir Server::Dir} provides a rack application that
5
+ # serves the contents of a directory
6
6
  class Server::Dir
7
7
  prepend Server::Gzip
8
8
 
@@ -1,3 +1,3 @@
1
1
  class Server
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/server.rb CHANGED
@@ -9,10 +9,9 @@ class Server
9
9
 
10
10
  ##
11
11
  # @param [String] path
12
- # The path to a directory.
13
- #
12
+ # The path to a directory
14
13
  # @return [Rack::Builder]
15
- # Returns a Rack app.
14
+ # Returns a Rack app
16
15
  def self.app(path)
17
16
  Rack::Builder.app do
18
17
  use Server::ETag
@@ -24,13 +23,21 @@ class Server
24
23
  ##
25
24
  # @param [String] path
26
25
  # The path to a directory
27
- #
28
26
  # @param [Hash] options
29
27
  # Hash of options
30
- #
31
28
  # @return [Server]
32
29
  # Returns an instance of {Server Server}
33
30
  def self.for(path, options = {})
31
+ new app(path), prepare(options)
32
+ end
33
+
34
+ ##
35
+ # Prepares options for {Server#initialize Server#initialize}
36
+ # @param [#to_h] options
37
+ # @return [Hash]
38
+ # Returns a Hash object
39
+ def self.prepare(options)
40
+ options = options.to_h.dup
34
41
  host = options.delete(:host) ||
35
42
  options.delete("host") ||
36
43
  options.delete(:bind) ||
@@ -42,10 +49,12 @@ class Server
42
49
  unix = options.delete(:unix) ||
43
50
  options.delete("unix") ||
44
51
  nil
45
- new app(path), options.merge!(
52
+ options.merge!(
46
53
  binds: [unix ? "unix://#{unix}" : "tcp://#{host}:#{port}"]
47
54
  )
55
+ options
48
56
  end
57
+
49
58
  class << self
50
59
  alias_method :dir, :for
51
60
  end
@@ -53,10 +62,8 @@ class Server
53
62
  ##
54
63
  # @param [Rack::Builder] app
55
64
  # Rack application
56
- #
57
65
  # @param [Hash] options
58
66
  # Hash of options
59
- #
60
67
  # @return [Server]
61
68
  # Returns an instance of {Server Server}
62
69
  def initialize(app, options = {})
@@ -68,10 +75,8 @@ class Server
68
75
 
69
76
  ##
70
77
  # Starts the web server
71
- #
72
78
  # @param [Boolean] block
73
79
  # When given as true, this method will block
74
- #
75
80
  # @return [Thread]
76
81
  # Returns a thread
77
82
  def start(block: false)
@@ -82,7 +87,6 @@ class Server
82
87
 
83
88
  ##
84
89
  # Stops the web server
85
- #
86
90
  # @return [void]
87
91
  def stop
88
92
  @server.stop
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-04 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubygems_version: 3.5.9
115
+ rubygems_version: 3.5.13
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: A static file web server