mmap-ruby 0.1.0

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,21 @@
1
+ #ifndef MMAP_RUBY_H
2
+ #define MMAP_RUBY_H 1
3
+
4
+ #include "ruby.h"
5
+ #include "ruby/io.h"
6
+ #include "ruby/re.h"
7
+ #include "ruby/util.h"
8
+
9
+ #include <ctype.h>
10
+ #include <fcntl.h>
11
+ #include <unistd.h>
12
+
13
+ #include <sys/mman.h>
14
+ #include <sys/stat.h>
15
+ #include <sys/types.h>
16
+
17
+ #include <sys/ipc.h>
18
+ #include <sys/sem.h>
19
+ #include <sys/shm.h>
20
+
21
+ #endif /* MMAP_RUBY_H */
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MmapRuby
4
+ class Mmap
5
+ include Comparable
6
+ include Enumerable
7
+
8
+ def clone # :nodoc:
9
+ raise TypeError, "can't clone instance of #{self.class}"
10
+ end
11
+
12
+ def dup # :nodoc:
13
+ raise TypeError, "can't dup instance of #{self.class}"
14
+ end
15
+
16
+ # See https://docs.ruby-lang.org/en/master/String.html#method-i-each_byte
17
+ def each_byte(...)
18
+ to_str.each_byte(...)
19
+ end
20
+ alias :each :each_byte
21
+
22
+ # See https://docs.ruby-lang.org/en/master/String.html#method-i-each_line
23
+ def each_line(...)
24
+ to_str.each_line(...)
25
+ end
26
+
27
+ # See https://docs.ruby-lang.org/en/master/String.html#method-i-scan
28
+ def scan(...)
29
+ to_str.scan(...)
30
+ end
31
+
32
+ private
33
+
34
+ def process_options(options)
35
+ options.each do |key, value|
36
+ key_str = key.to_s
37
+ case key_str
38
+ when "initialize" # skip
39
+ when "length" then set_length value
40
+ when "offset" then set_offset value
41
+ when "advice" then set_advice value
42
+ when "increment" then set_increment value
43
+ when "ipc" then set_ipc value
44
+ else raise TypeError, "unknown option #{key_str}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MmapRuby
4
+ VERSION = "0.1.0"
5
+ end
data/lib/mmap-ruby.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mmap-ruby/mmap_ruby"
4
+ require "mmap-ruby/mmap"
5
+
6
+ Mmap = MmapRuby::Mmap
data/mmap-ruby.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mmap-ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mmap-ruby"
7
+ spec.version = MmapRuby::VERSION
8
+ spec.authors = ["Guy Decoux", "Aaron Patterson", "Joshua Young"]
9
+ spec.email = ["ts@moulon.inra.fr", "tenderlove@github.com", "djry1999@gmail.com"]
10
+
11
+ spec.summary = "mmap wrapper for Ruby"
12
+ spec.homepage = "https://github.com/joshuay03/mmap-ruby"
13
+ spec.license = "https://www.ruby-lang.org/en/about/license.txt"
14
+ spec.required_ruby_version = ">= 3.3.0"
15
+
16
+ spec.metadata["documentation_uri"] = "https://joshuay03.github.io/mmap-ruby/"
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
+
20
+ spec.files = Dir["lib/**/*", "ext/**/*", "**/*.{gemspec,md,txt}"]
21
+ spec.require_paths = ["lib"]
22
+ spec.extensions = ["ext/mmap_ruby/extconf.rb"]
23
+ end
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-07-19
4
+
5
+ - Rewrite tenderlove/mmap with modern Ruby support
@@ -0,0 +1,92 @@
1
+ # MmapRuby
2
+
3
+ ![Version](https://img.shields.io/gem/v/mmap-ruby)
4
+ ![Build](https://img.shields.io/github/actions/workflow/status/joshuay03/mmap-ruby/.github/workflows/main.yml?branch=main)
5
+
6
+ [`mmap`](https://en.wikipedia.org/wiki/Mmap) wrapper for Ruby.
7
+
8
+ A modern fork of https://github.com/tenderlove/mmap.
9
+
10
+ **Docs:** https://joshuay03.github.io/mmap-ruby
11
+
12
+ **Example:**
13
+
14
+ ```ruby
15
+ # frozen_string_literal: true
16
+
17
+ require "mmap-ruby"
18
+
19
+ PAGESIZE = 4096
20
+
21
+ file = File.open("aa", "w")
22
+ file.write("\0" * PAGESIZE)
23
+ file.write("test")
24
+ file.write("\0" * PAGESIZE)
25
+ file.close
26
+
27
+ mmap = Mmap.new("aa", "rw", offset: 0)
28
+ p mmap.size == "test".size + (2 * PAGESIZE)
29
+ p mmap.scan(/[a-z.]+/) == ["test"]
30
+ p mmap.index("test") == PAGESIZE
31
+ p mmap.rindex("test") == PAGESIZE
32
+ p mmap.sub!(/[a-z.]+/, "toto") == mmap
33
+ p mmap.scan(/[a-z.]+/) == ["toto"]
34
+ begin
35
+ mmap.sub!(/[a-z.]+/, "alpha")
36
+ puts "not OK, must give an error"
37
+ rescue
38
+ puts "OK: #$!"
39
+ end
40
+ mmap.munmap
41
+
42
+ mmap = Mmap.new("aa", "rw")
43
+ p mmap.index("toto") == PAGESIZE
44
+ p mmap.sub!(/([a-z.]+)/, "alpha") == mmap
45
+ p $& == "toto"
46
+ p $1 == "toto"
47
+ p mmap.index("toto") == nil
48
+ p mmap.index("alpha") == PAGESIZE
49
+ p mmap.size == 5 + 2 * PAGESIZE
50
+ mmap.gsub!(/\0/, "X")
51
+ p mmap.size == 5 + 2 * PAGESIZE
52
+
53
+ File.delete("aa")
54
+ ```
55
+
56
+ ## Installation
57
+
58
+ Install the gem and add to the application's Gemfile by executing:
59
+
60
+ ```bash
61
+ bundle add mmap-ruby
62
+ ```
63
+
64
+ If bundler is not being used to manage dependencies, install the gem by executing:
65
+
66
+ ```bash
67
+ gem install mmap-ruby
68
+ ```
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests.
73
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
76
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
77
+ push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+
79
+ ## Contributing
80
+
81
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[joshuay03]/mmap-ruby. This project is
82
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
83
+ [code of conduct](https://github.com/[joshuay03]/mmap-ruby/blob/main/CODE_OF_CONDUCT.md).
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [Ruby license](https://www.ruby-lang.org/en/about/license.txt).
88
+
89
+ ## Code of Conduct
90
+
91
+ Everyone interacting in the MmapRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to
92
+ follow the [code of conduct](https://github.com/[joshuay03]/mmap-ruby/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mmap-ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mmap-ruby"
7
+ spec.version = MmapRuby::VERSION
8
+ spec.authors = ["Guy Decoux", "Aaron Patterson", "Joshua Young"]
9
+ spec.email = ["ts@moulon.inra.fr", "tenderlove@github.com", "djry1999@gmail.com"]
10
+
11
+ spec.summary = "mmap wrapper for Ruby"
12
+ spec.homepage = "https://github.com/joshuay03/mmap-ruby"
13
+ spec.license = "https://www.ruby-lang.org/en/about/license.txt"
14
+ spec.required_ruby_version = ">= 3.3.0"
15
+
16
+ spec.metadata["documentation_uri"] = "https://joshuay03.github.io/mmap-ruby/"
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
19
+
20
+ spec.files = Dir["lib/**/*", "ext/**/*", "**/*.{gemspec,md,txt}"]
21
+ spec.require_paths = ["lib"]
22
+ spec.extensions = ["ext/mmap_ruby/extconf.rb"]
23
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmap-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guy Decoux
8
+ - Aaron Patterson
9
+ - Joshua Young
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 1980-01-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ email:
15
+ - ts@moulon.inra.fr
16
+ - tenderlove@github.com
17
+ - djry1999@gmail.com
18
+ executables: []
19
+ extensions:
20
+ - ext/mmap_ruby/extconf.rb
21
+ extra_rdoc_files: []
22
+ files:
23
+ - CHANGELOG.md
24
+ - README.md
25
+ - ext/mmap_ruby/extconf.rb
26
+ - ext/mmap_ruby/mmap
27
+ - ext/mmap_ruby/mmap_ruby.c
28
+ - ext/mmap_ruby/mmap_ruby.h
29
+ - lib/mmap-ruby.rb
30
+ - lib/mmap-ruby/mmap.rb
31
+ - lib/mmap-ruby/mmap_ruby.bundle
32
+ - lib/mmap-ruby/version.rb
33
+ - mmap-ruby.gemspec
34
+ - tmp/arm64-darwin25/stage/CHANGELOG.md
35
+ - tmp/arm64-darwin25/stage/README.md
36
+ - tmp/arm64-darwin25/stage/mmap-ruby.gemspec
37
+ homepage: https://github.com/joshuay03/mmap-ruby
38
+ licenses:
39
+ - https://www.ruby-lang.org/en/about/license.txt
40
+ metadata:
41
+ documentation_uri: https://joshuay03.github.io/mmap-ruby/
42
+ source_code_uri: https://github.com/joshuay03/mmap-ruby
43
+ changelog_uri: https://github.com/joshuay03/mmap-ruby/blob/main/CHANGELOG.md
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 3.3.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.6.9
59
+ specification_version: 4
60
+ summary: mmap wrapper for Ruby
61
+ test_files: []