dirwait 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b0fe35de0f2eb7d5f23429f224a2cff5626a892
4
+ data.tar.gz: 3243fd1ede7c66535c00d9852da04810b1552095
5
+ SHA512:
6
+ metadata.gz: 98a584af63937e2d1a1cc3f7763edf7fd772293f64bc1842eb2360241e018aa842bcf917aa2eacecdb11a06421d28a9c8cd3c38f916ff38065c6549c1f1fc660
7
+ data.tar.gz: 57b1afe18091be1949b96adb40d1f462322a6ab0f10cec52d77d04b26b07afcbc7c774f6a31c8b52b193526a9c4af0182fe1e46112cb34d5fd15ace9d28fea6a
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ���2_y�}�U�
2
+ و
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dirwait.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 J. Brandt Buckley
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # DirWait
2
+
3
+ Watches and waits for a directory to be created and then exits.
4
+
5
+ When it detects that specified directory was created, it exits cleanly (exit
6
+ code: 0).
7
+
8
+ This was hacked together as part of a proof-of-concept for which I needed a
9
+ portable way to quickly run a command as soon as a specific directory was
10
+ created. It served that purpose well, but it isn't very robust.
11
+
12
+
13
+ ## Installing
14
+
15
+ With RubyGems:
16
+
17
+ gem install dirwait
18
+
19
+ With Bundler:
20
+
21
+ git clone https://github.com/brandt/dirwait.git
22
+ cd dirwait
23
+ bundle install
24
+
25
+
26
+ ## Usage
27
+
28
+ Example: Copy file as soon as the destination become available:
29
+
30
+ dirwait ~/Dropbox/Company && cp -r /tmp/Archive ~/Dropbox/Company/
31
+
32
+
33
+ ## Authors
34
+
35
+ J. Brandt Buckley <brandt@runlevel1.com>
36
+
37
+ Monkey patches [Listen](https://github.com/guard/listen) to enable reporting
38
+ of directory creation events.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/dirwait ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dirwait'
4
+
5
+ if ARGV.empty?
6
+ $stderr.puts "Usage: dirwait <path>"
7
+ exit
8
+ end
9
+
10
+ path = ARGV.shift
11
+ fail ArgumentError, "No path specified" unless path
12
+
13
+ watch = DirWait::Watch.new(path)
14
+ watch.start
data/certs/brandt.pem ADDED
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZicmFu
3
+ ZHQxGTAXBgoJkiaJk/IsZAEZFglydW5sZXZlbDExEzARBgoJkiaJk/IsZAEZFgNj
4
+ b20wHhcNMTQwMTEwMTU1NTE4WhcNMTUwMTEwMTU1NTE4WjBBMQ8wDQYDVQQDDAZi
5
+ cmFuZHQxGTAXBgoJkiaJk/IsZAEZFglydW5sZXZlbDExEzARBgoJkiaJk/IsZAEZ
6
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCsA8nbbjoyfpWl
7
+ 0HTFYisDdnRWvSwJamT4bc2d0fJBZbny68P6YZ0B9oh9NEhSkCZCOdIzWroXJLtR
8
+ FdpYPIJycOqRqw2pvxgw4/Lqp7XWI9/UW1CXA0C8eVR6od06awPxnrKydJaonXQj
9
+ rLgfK4872H+blgXLF7q4m0+1UN1jEWgaTGsUZC3kJVZ7ZefIoWTaU9yo0VAdBy7g
10
+ HewpS1DgwtN7S5Xhz3uNPrH4ubNvlggA7MOAhKAwCiZnvN1fkhvDH1ckn/YCFbVo
11
+ lcgJNUlf7VTfYcFLCVeNMkYBZxKPvTtYkOm1qvIAKWM1wkF4qEaSHrRLhjqt3DWH
12
+ xG15oCbDAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
13
+ BBToCGCZnRNbQThMAD4WVqUejfxxVjAfBgNVHREEGDAWgRRicmFuZHRAcnVubGV2
14
+ ZWwxLmNvbTAfBgNVHRIEGDAWgRRicmFuZHRAcnVubGV2ZWwxLmNvbTANBgkqhkiG
15
+ 9w0BAQUFAAOCAQEAHbIyl3hAKK7FyFxqjXtf1Vjjj1eFzUEyVXBNE7X27TIa6zRH
16
+ JY6E9IJFKk/XP21rRwdbXiWGtTil9FajWpRL8qhyRctKfk5vYE+0PZETk5FhcDWi
17
+ aCsDdYM+6KJLloELCLpMTH+zq6seov+J9ij9TYTfIMUQjOIpT5T+kfMGuHQMtMWA
18
+ Oo4yIK3i5TVW0PkSe/pbGzNtPbFjOlok5Ul2OKElV3GzjQKDRjCizSaDy1JYoJ4w
19
+ cSnnu6V8ZqVMnrx6MHA8YA+6bICobj1jG3JEbk5IwEgWVJIeDZUazRlJb0e8Y30J
20
+ B67msO8YbpqPEeWauXmOXDXQafifmmFwhxZ52w==
21
+ -----END CERTIFICATE-----
data/dirwait.gemspec ADDED
@@ -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 'dirwait/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dirwait"
8
+ spec.version = DirWait::VERSION
9
+ spec.authors = ["J. Brandt Buckley"]
10
+ spec.email = ["brandt@runlevel1.com"]
11
+ spec.summary = %q{Watch and wait for a directory to be created}
12
+ spec.description = %q{Listens to filesystem event notifications until a specified directory is created and then exits.}
13
+ spec.homepage = "https://github.com/brandt/dirwait"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.cert_chain = ['certs/brandt.pem']
21
+ spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_dependency "listen", "~> 2.4.0"
26
+ end
data/lib/dirwait.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "dirwait/version"
2
+ require "dirwait/watch"
3
+
4
+ module DirWait
5
+ end
@@ -0,0 +1,3 @@
1
+ module DirWait
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,72 @@
1
+ require "listen"
2
+
3
+ # Private: Monkeypatch Listen to allow reporting of directory changes
4
+ module Listen
5
+ class Change
6
+ def change(path, options)
7
+ return if _silencer.silenced?(path, options[:type])
8
+
9
+ if change = options[:change]
10
+ _notify_listener(change, path)
11
+ else
12
+ _file_change(path, options)
13
+ _dir_change(path, options) if options[:type] == "Dir"
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ module DirWait
20
+ # Public: Watch the filesystem and wait for a directory to be created.
21
+ class Watch
22
+ # Public: Initialize a new watcher.
23
+ #
24
+ # path - The String path to watch.
25
+ def initialize(path)
26
+ @watch_path = path
27
+ @existing_parent = find_existing(path)
28
+ end
29
+
30
+ # Internal: Find the highest existing directory in a given path.
31
+ #
32
+ # path - A String path to search.
33
+ #
34
+ # Examples
35
+ #
36
+ # find_existing('/usr/local/foo')
37
+ # # => '/usr/local'
38
+ #
39
+ # Returns the String path to the top-most existing directory.
40
+ def find_existing(path)
41
+ until File.directory?(path)
42
+ path = File.dirname(path)
43
+ end
44
+ path
45
+ end
46
+
47
+ # Public: Start the initialized listener.
48
+ #
49
+ # Exits cleanly (exit code: 0) if @watch_path was created.
50
+ def start
51
+ $stderr.puts "Watching filesystem events in: #{@existing_parent}"
52
+
53
+ callback = Proc.new do |modified, added, removed|
54
+ if added.any? {|i| File.fnmatch(@watch_path, i) }
55
+ puts "Added: #{@watch_path}"
56
+ exit 0
57
+ end
58
+ end
59
+
60
+ listener = Listen.to(@existing_parent, ignore!: [], &callback)
61
+ listener.start
62
+
63
+ # Set trap so that we can break out of `sleep`
64
+ Signal.trap("INT") do
65
+ puts "Exiting..."
66
+ exit 4
67
+ end
68
+
69
+ sleep
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dirwait
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - J. Brandt Buckley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZicmFu
14
+ ZHQxGTAXBgoJkiaJk/IsZAEZFglydW5sZXZlbDExEzARBgoJkiaJk/IsZAEZFgNj
15
+ b20wHhcNMTQwMTEwMTU1NTE4WhcNMTUwMTEwMTU1NTE4WjBBMQ8wDQYDVQQDDAZi
16
+ cmFuZHQxGTAXBgoJkiaJk/IsZAEZFglydW5sZXZlbDExEzARBgoJkiaJk/IsZAEZ
17
+ FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCsA8nbbjoyfpWl
18
+ 0HTFYisDdnRWvSwJamT4bc2d0fJBZbny68P6YZ0B9oh9NEhSkCZCOdIzWroXJLtR
19
+ FdpYPIJycOqRqw2pvxgw4/Lqp7XWI9/UW1CXA0C8eVR6od06awPxnrKydJaonXQj
20
+ rLgfK4872H+blgXLF7q4m0+1UN1jEWgaTGsUZC3kJVZ7ZefIoWTaU9yo0VAdBy7g
21
+ HewpS1DgwtN7S5Xhz3uNPrH4ubNvlggA7MOAhKAwCiZnvN1fkhvDH1ckn/YCFbVo
22
+ lcgJNUlf7VTfYcFLCVeNMkYBZxKPvTtYkOm1qvIAKWM1wkF4qEaSHrRLhjqt3DWH
23
+ xG15oCbDAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
+ BBToCGCZnRNbQThMAD4WVqUejfxxVjAfBgNVHREEGDAWgRRicmFuZHRAcnVubGV2
25
+ ZWwxLmNvbTAfBgNVHRIEGDAWgRRicmFuZHRAcnVubGV2ZWwxLmNvbTANBgkqhkiG
26
+ 9w0BAQUFAAOCAQEAHbIyl3hAKK7FyFxqjXtf1Vjjj1eFzUEyVXBNE7X27TIa6zRH
27
+ JY6E9IJFKk/XP21rRwdbXiWGtTil9FajWpRL8qhyRctKfk5vYE+0PZETk5FhcDWi
28
+ aCsDdYM+6KJLloELCLpMTH+zq6seov+J9ij9TYTfIMUQjOIpT5T+kfMGuHQMtMWA
29
+ Oo4yIK3i5TVW0PkSe/pbGzNtPbFjOlok5Ul2OKElV3GzjQKDRjCizSaDy1JYoJ4w
30
+ cSnnu6V8ZqVMnrx6MHA8YA+6bICobj1jG3JEbk5IwEgWVJIeDZUazRlJb0e8Y30J
31
+ B67msO8YbpqPEeWauXmOXDXQafifmmFwhxZ52w==
32
+ -----END CERTIFICATE-----
33
+ date: 2014-01-10 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.5'
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.5'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: listen
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 2.4.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 2.4.0
77
+ description: Listens to filesystem event notifications until a specified directory
78
+ is created and then exits.
79
+ email:
80
+ - brandt@runlevel1.com
81
+ executables:
82
+ - dirwait
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - ".gitignore"
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/dirwait
92
+ - certs/brandt.pem
93
+ - dirwait.gemspec
94
+ - lib/dirwait.rb
95
+ - lib/dirwait/version.rb
96
+ - lib/dirwait/watch.rb
97
+ homepage: https://github.com/brandt/dirwait
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.2.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Watch and wait for a directory to be created
121
+ test_files: []
122
+ has_rdoc:
metadata.gz.sig ADDED
Binary file