protocol-media-registry 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ # @namespace
7
+ module Protocol
8
+ # Models media types used by internet protocols and data formats.
9
+ module Media
10
+ # @namespace
11
+ module Registry
12
+ VERSION = "0.0.1"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ require "protocol/media/type"
7
+
8
+ require_relative "registry/version"
9
+ require_relative "registry/index"
10
+ require_relative "registry/record"
11
+
12
+ module Protocol
13
+ module Media
14
+ # Provides indexed access to registered media type data.
15
+ module Registry
16
+ # Look up a media type by name.
17
+ #
18
+ # @parameter name [String] The complete media type name.
19
+ # @returns [Record | Nil]
20
+ def self.[](name)
21
+ if record = Index.lookup(name)
22
+ Record.new(Type.parse(record[0]), encoding: record[1], extensions: record[2])
23
+ end
24
+ end
25
+
26
+ # Look up a media type by filename extension.
27
+ #
28
+ # @parameter extension [String] A filename extension, with or without a leading dot.
29
+ # @returns [Record | Nil]
30
+ def self.for_extension(extension)
31
+ extension = extension.delete_prefix(".").downcase
32
+
33
+ if name = Index.lookup_extension(extension)
34
+ self[name]
35
+ end
36
+ end
37
+
38
+ # Look up a media type for a path.
39
+ #
40
+ # @parameter path [String] A path containing a filename extension.
41
+ # @returns [Record | Nil]
42
+ def self.for_path(path)
43
+ extension = File.extname(path)
44
+ for_extension(extension) unless extension.empty?
45
+ end
46
+ end
47
+ end
48
+ end
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright, 2016-2026, by Samuel Williams.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,14 @@
1
+ # Protocol::Media::Registry
2
+
3
+ Provides generated, indexed media type registry data for `protocol-media`. It uses a native static index when available and transparently falls back to a generated Ruby index.
4
+
5
+ ``` ruby
6
+ require "protocol/media/registry"
7
+
8
+ record = Protocol::Media::Registry["application/json"]
9
+ record.type # => #<Protocol::Media::Type ...>
10
+ record.extensions # => ["json", ...]
11
+
12
+ Protocol::Media::Registry.for_extension("json").type
13
+ Protocol::Media::Registry.for_path("document.json").type
14
+ ```
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protocol-media-registry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: protocol-media
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.0'
26
+ executables: []
27
+ extensions:
28
+ - ext/extconf.rb
29
+ extra_rdoc_files: []
30
+ files:
31
+ - ext/depend
32
+ - ext/extconf.rb
33
+ - ext/protocol/media/registry/extensions.gperf
34
+ - ext/protocol/media/registry/extensions.h
35
+ - ext/protocol/media/registry/native.c
36
+ - ext/protocol/media/registry/records.gperf
37
+ - ext/protocol/media/registry/records.h
38
+ - lib/protocol/media/registry.rb
39
+ - lib/protocol/media/registry/fallback.rb
40
+ - lib/protocol/media/registry/index.rb
41
+ - lib/protocol/media/registry/record.rb
42
+ - lib/protocol/media/registry/records.rb
43
+ - lib/protocol/media/registry/version.rb
44
+ - license.md
45
+ - readme.md
46
+ homepage: https://github.com/socketry/protocol-media-registry
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ documentation_uri: https://socketry.github.io/protocol-media-registry/
51
+ source_code_uri: https://github.com/socketry/protocol-media-registry.git
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '3.3'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 4.0.10
67
+ specification_version: 4
68
+ summary: Provides indexed media type registry data.
69
+ test_files: []