rack-file-watcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/lib/rack-file-watcher.rb +1 -0
- data/lib/rack/file_watcher.rb +41 -0
- data/lib/rack/file_watcher/version.rb +5 -0
- data/rack-file-watcher.gemspec +26 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 182bd53f08ffddbfc0731ef10d880f94736c1ac2
|
4
|
+
data.tar.gz: bc4ff24e5dbf006b26c39d3e9f3fec5f58bf9cec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc3ccbf0cd4a94f57234ba6521f56d1ea51bbe5f89771017f3e6959ca2497765121a5206d9f507165a19397f7ca43a1930c58fa0dc14415eeb5f6f2a3726ea54
|
7
|
+
data.tar.gz: c850975fe53dccaab5b783a8e6ed23fe5bc1a0d3ffcfdae231701f78ec0083b8737962cc807823ff3be284fd941d36c28d498112f9266124357410cf48a8b3a1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 daichi.hirata
|
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,73 @@
|
|
1
|
+
# Rack::FileWatcher
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/daic-h/rack-file-watcher.svg?branch=master)](https://travis-ci.org/daic-h/rack-file-watcher)
|
4
|
+
|
5
|
+
|
6
|
+
Rack middleware to handle events on file modifications.
|
7
|
+
|
8
|
+
If you are using an application server of prefork type(unicorn, passenger), it is useful if you want to do a simple processing in the child process. (For example, clear the Rails.cache)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'rack-file-watcher'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install rack-file-watcher
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Basic configuring the middleware:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'rack/file_watcher'
|
32
|
+
|
33
|
+
use Rack::FileWatcher, 'tmp/watch.txt' do
|
34
|
+
puts 'updated.'
|
35
|
+
end
|
36
|
+
|
37
|
+
app = proc do |env|
|
38
|
+
[ 200, {'Content-Type' => 'text/plain'}, 'Hello World' ]
|
39
|
+
end
|
40
|
+
run app
|
41
|
+
```
|
42
|
+
|
43
|
+
## Example
|
44
|
+
|
45
|
+
Example in Rails:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# config/application.rb
|
49
|
+
|
50
|
+
module YourApp
|
51
|
+
class Application < Rails::Application
|
52
|
+
|
53
|
+
# ...
|
54
|
+
|
55
|
+
config.middleware.use Rack::FileWatcher, config.root.join('tmp/clear_cache.txt') do
|
56
|
+
Rails.cache.clear
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it ( https://github.com/daic-h/rack-file-watcher/fork )
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create a new Pull Request
|
70
|
+
|
71
|
+
## Copyright
|
72
|
+
|
73
|
+
Copyright (c) Daichi HIRATA, released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack/file_watcher'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "rack/file_watcher/version"
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class FileWatcher
|
6
|
+
def initialize(app, file_path, &block)
|
7
|
+
@app = app
|
8
|
+
@file_path = file_path
|
9
|
+
@block = block
|
10
|
+
|
11
|
+
initialize_target_file
|
12
|
+
|
13
|
+
@last_update_at = updated_at
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute_if_updated
|
17
|
+
current_updated_at = updated_at
|
18
|
+
|
19
|
+
if @last_update_at != current_updated_at
|
20
|
+
@block.call
|
21
|
+
@last_update_at = current_updated_at
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
execute_if_updated
|
27
|
+
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def initialize_target_file
|
34
|
+
FileUtils.touch(@file_path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def updated_at
|
38
|
+
::File.mtime(@file_path)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/file_watcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-file-watcher"
|
8
|
+
spec.version = Rack::FileWatcher::VERSION
|
9
|
+
spec.authors = ["daichi.hirata"]
|
10
|
+
spec.email = ["hirata.daichi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Rack middleware to handle events on file modifications"
|
13
|
+
spec.description = "Rack middleware to handle events on file modifications"
|
14
|
+
spec.homepage = "https://github.com/daic-h/rack-file-watcher"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "rack"
|
21
|
+
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "pry"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rack-test"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-file-watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- daichi.hirata
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
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
|
+
description: Rack middleware to handle events on file modifications
|
84
|
+
email:
|
85
|
+
- hirata.daichi@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/rack-file-watcher.rb
|
98
|
+
- lib/rack/file_watcher.rb
|
99
|
+
- lib/rack/file_watcher/version.rb
|
100
|
+
- rack-file-watcher.gemspec
|
101
|
+
homepage: https://github.com/daic-h/rack-file-watcher
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.2.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Rack middleware to handle events on file modifications
|
125
|
+
test_files: []
|