server.rb 0.2.1 → 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: 9d807489641411df5fe227174f05d079f1d48356a2d154392beef07fdbf10930
4
- data.tar.gz: 4221e02a661ab7eff5fa3a7775855888c80db2085353c3db8a478fca43dcdd00
3
+ metadata.gz: 3c1f5315cd2fe6ceaa25725d372a53dbf52f61477cf0798c15fd20a348b28b4d
4
+ data.tar.gz: 35df8a5fb406a8445cbb3c3bd151740dea62635c2c24e167c19bf81dce35fa1d
5
5
  SHA512:
6
- metadata.gz: 7644c7cf54fbcfab425ff5f036599a330bd4484c80d2b6314503ab29655d9a54a92571b313d0a9904780bc5b08122d6aa88854c78aceb6934dbd4d5e8758b4ae
7
- data.tar.gz: 60523031a59d70f05d9730dbd7d7a7884ed048a236646fda363d1d8997d24f8539f43d55d1a497ea50ddd911484514b7bb7109018877d457d4a69463433f407f
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.1"
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.1
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
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.5'
83
- description: A static file web server.
83
+ description: A static file web server
84
84
  email:
85
85
  - 0x1eef@protonmail.com
86
86
  executables: []
@@ -112,8 +112,8 @@ 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
- summary: A static file web server.
118
+ summary: A static file web server
119
119
  test_files: []