lmkplz 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/lib/lmkplz/encasement.rb +74 -0
- data/lib/lmkplz/file_filter.rb +47 -0
- data/lib/lmkplz/metal.rb +44 -0
- data/lib/lmkplz/repeatedly.rb +47 -0
- data/lib/lmkplz/version.rb +3 -0
- data/lib/lmkplz.rb +12 -0
- data/lmkplz.gemspec +35 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 82e82948b2d9a2add011652c29c20d66d70dbc11
|
4
|
+
data.tar.gz: dabc6102fb266bac86539dde32c6a87f31091bdf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55531253878e6a32db5158490b154b31b5c9a7152da45a7cbaafdcf73467643c1e6d067c2f175cf8102d0fc939a6f4f0d0c391cf6ced2c7b3e77094578cee424
|
7
|
+
data.tar.gz: 755269235fb0fd7481cf7e313487bf3c96e190de857a134d3e15a74311ae2ba3b88b7881570cdb0a63854f65b97f2980bafd7fea5a0ba8f4862e5297967c68a3
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Zach Ahn
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# LMKPLZ
|
2
|
+
|
3
|
+
(Let Me Know PLeaZe)
|
4
|
+
|
5
|
+
Lmkplz is a gem that lets you know when it notices filesystem changes.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "lmkplz"
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install lmkplz
|
23
|
+
|
24
|
+
You will also probably need to have [Rust](https://www.rust-lang.org/) installed
|
25
|
+
to compile the backend
|
26
|
+
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
31
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
32
|
+
prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
35
|
+
release a new version, update the version number in `version.rb`, and then run
|
36
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
37
|
+
git commits and tags, and push the `.gem` file to
|
38
|
+
[rubygems.org](https://rubygems.org).
|
39
|
+
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at
|
44
|
+
https://github.com/zachahn/lmkplz.
|
45
|
+
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the
|
50
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Lmkplz
|
2
|
+
class Encasement
|
3
|
+
def initialize
|
4
|
+
@callback_mutex = Mutex.new
|
5
|
+
@add_paths_mutex = Mutex.new
|
6
|
+
@add_paths_queue = []
|
7
|
+
@gather_event_duration_ms = 200
|
8
|
+
@callbacks = Hash.new { -> {} }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.define_settable_callback(name)
|
12
|
+
define_method("on_#{name}") do |&block|
|
13
|
+
@callback_mutex.synchronize { @callbacks[name] = block }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
define_settable_callback :success
|
18
|
+
define_settable_callback :failure
|
19
|
+
define_settable_callback :timeout
|
20
|
+
define_settable_callback :end
|
21
|
+
|
22
|
+
def malloc
|
23
|
+
kkttyl
|
24
|
+
|
25
|
+
@add_paths_mutex.synchronize do
|
26
|
+
while @add_paths_queue.any?
|
27
|
+
add(@add_paths_queue.pop)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def free
|
33
|
+
if !active?
|
34
|
+
return
|
35
|
+
end
|
36
|
+
|
37
|
+
Metal.kkttyl_free(kkttyl)
|
38
|
+
@kkttyl = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def add(dir)
|
42
|
+
if active?
|
43
|
+
Metal.kkttyl_add(kkttyl, dir)
|
44
|
+
else
|
45
|
+
@add_paths_mutex.synchronize do
|
46
|
+
@add_paths_queue.push(dir)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def await
|
52
|
+
if !active?
|
53
|
+
raise "Call #malloc before #await"
|
54
|
+
end
|
55
|
+
|
56
|
+
callbacks =
|
57
|
+
@callback_mutex.synchronize do
|
58
|
+
@callbacks.values_at(:success, :failure, :timeout, :end)
|
59
|
+
end
|
60
|
+
|
61
|
+
Metal.kkttyl_await(kkttyl, 40, *callbacks)
|
62
|
+
end
|
63
|
+
|
64
|
+
def active?
|
65
|
+
!!@kkttyl
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def kkttyl
|
71
|
+
@kkttyl ||= Metal.kkttyl_new(@gather_event_duration_ms)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lmkplz
|
2
|
+
class FileFilter
|
3
|
+
def initialize(only: nil, except: nil)
|
4
|
+
@matcher =
|
5
|
+
if only && except
|
6
|
+
raise "`only` and `except` params are mutually exclusive"
|
7
|
+
elsif only
|
8
|
+
-> (path) { path =~ only }
|
9
|
+
elsif except
|
10
|
+
-> (path) { path !~ except }
|
11
|
+
else
|
12
|
+
-> (_path) { true }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(modified_raw, created_raw, removed_raw)
|
17
|
+
paths =
|
18
|
+
[modified_raw, created_raw, removed_raw]
|
19
|
+
.map(&method(:match_or_empty))
|
20
|
+
.map(&method(:empty_to_nil))
|
21
|
+
|
22
|
+
if paths.none?
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
yield(*paths)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def match_or_empty(path)
|
32
|
+
if @matcher.call(path)
|
33
|
+
path
|
34
|
+
else
|
35
|
+
""
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty_to_nil(path)
|
40
|
+
if path == ""
|
41
|
+
nil
|
42
|
+
else
|
43
|
+
path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/lmkplz/metal.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Lmkplz
|
2
|
+
module External
|
3
|
+
def self.path
|
4
|
+
if $USE_DEBUG_KKTTYL
|
5
|
+
warn "Using debug build"
|
6
|
+
debug_path
|
7
|
+
else
|
8
|
+
release_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.release_path
|
13
|
+
"ext/kkttyl/target/release/libkkttyl.#{FFI::Platform::LIBSUFFIX}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.debug_path
|
17
|
+
"ext/kkttyl/target/debug/libkkttyl.#{FFI::Platform::LIBSUFFIX}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module Metal
|
22
|
+
extend FFI::Library
|
23
|
+
|
24
|
+
ffi_lib External.path
|
25
|
+
|
26
|
+
callback :success_callback, %i[string string string], :void
|
27
|
+
callback :failure_callback, %i[], :void
|
28
|
+
callback :timeout_callback, %i[], :void
|
29
|
+
callback :end_callback, %i[], :void
|
30
|
+
|
31
|
+
attach_function :kkttyl_new, %i[uint64], :pointer
|
32
|
+
attach_function :kkttyl_free, %i[pointer], :void
|
33
|
+
attach_function :kkttyl_add, %i[pointer string], :void
|
34
|
+
attach_function :kkttyl_await, \
|
35
|
+
%i[
|
36
|
+
pointer
|
37
|
+
uint64
|
38
|
+
success_callback
|
39
|
+
failure_callback
|
40
|
+
timeout_callback
|
41
|
+
end_callback
|
42
|
+
], :void
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lmkplz
|
2
|
+
class Repeatedly
|
3
|
+
attr_reader :callbacker
|
4
|
+
|
5
|
+
def initialize(*paths, only: nil, except: nil, &block)
|
6
|
+
@block = block
|
7
|
+
@file_filter = FileFilter.new(only: only, except: except)
|
8
|
+
paths.each { |path| interface.add(path) }
|
9
|
+
|
10
|
+
interface.on_success do |m, c, r|
|
11
|
+
@file_filter.call(m, c, r) do |mm, cc, rr|
|
12
|
+
@block.call(mm, cc, rr)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
interface.malloc
|
19
|
+
the_loop
|
20
|
+
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def pause
|
25
|
+
if @the_loop.nil?
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
the_loop.kill
|
30
|
+
@the_loop = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def the_loop
|
36
|
+
@the_loop ||= Thread.new do
|
37
|
+
loop do
|
38
|
+
interface.await
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def interface
|
44
|
+
@interface ||= Encasement.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/lmkplz.rb
ADDED
data/lmkplz.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "lmkplz/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "lmkplz"
|
7
|
+
spec.version = Lmkplz::VERSION
|
8
|
+
spec.authors = ["Zach Ahn"]
|
9
|
+
spec.email = ["engineering@zachahn.com"]
|
10
|
+
|
11
|
+
spec.summary = "LMK when a file changes"
|
12
|
+
spec.description = "Filesystem watcher"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files =
|
16
|
+
`git ls-files -z`
|
17
|
+
.split("\x0")
|
18
|
+
.+(Dir.glob("ext/kkttyl/target/release/libkkttyl.*"))
|
19
|
+
.reject { |f| f.match(%r{^(bin|test|spec|features|ext)/}) }
|
20
|
+
.reject { |f| f == "Rakefile" }
|
21
|
+
.reject { |f| f.match(/^\./) }
|
22
|
+
.reject { |f| f.match(%r{\Aext/kkttyl/.*\.d\z}) }
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_runtime_dependency "ffi", "~> 1.9"
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
32
|
+
spec.add_development_dependency "rubocop"
|
33
|
+
spec.add_development_dependency "the_bath_of_zahn"
|
34
|
+
spec.add_development_dependency "pry-byebug"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lmkplz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zach Ahn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: the_bath_of_zahn
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Filesystem watcher
|
112
|
+
email:
|
113
|
+
- engineering@zachahn.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- lib/lmkplz.rb
|
122
|
+
- lib/lmkplz/encasement.rb
|
123
|
+
- lib/lmkplz/file_filter.rb
|
124
|
+
- lib/lmkplz/metal.rb
|
125
|
+
- lib/lmkplz/repeatedly.rb
|
126
|
+
- lib/lmkplz/version.rb
|
127
|
+
- lmkplz.gemspec
|
128
|
+
homepage:
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.6.13
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: LMK when a file changes
|
152
|
+
test_files: []
|