thrifty_file_applier 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0192a3ecf8330f945f476fcd99adc1a229cf8bfb71765d94542f23a45247c94
4
- data.tar.gz: a88524d1bd10ec15cd6eddfafbc67564b63aee8d06117ec4360609781a55617a
3
+ metadata.gz: 4b56156ca6b54a4a9caa64b78d68786e6228a0a568b066fab4dd1ad30e9491f0
4
+ data.tar.gz: ee5cec60536d69c3a83556a10bbc8c31d59f8938d8b4263c08c975dda4724d0a
5
5
  SHA512:
6
- metadata.gz: 662f8d8d69d25e733d1ef875911cd2a8162e40001035ad3ce09bbd40a137b925fe69b783d00b6f97ae7aebc68eb504446c05e050bd746d3a4767c372d04a6c17
7
- data.tar.gz: 5de8da2d61e3a2dd39cc537fb9f91b2b1b3054425f63c05d4d671e60f65c908665a7af6ae74bb1e1c52bfa9f36999e6c669a7656cced65876507b0affb3876db
6
+ metadata.gz: 94380f9dc0658562320350a1422724d6855a51d882c8e9eacb3affce88fba98052e5adaea11a907eed0ceab4b82bcfbab4f2ebd0cb28deb92d63cc175351150d
7
+ data.tar.gz: 63b7e5562d9997c0a91f3a055cb645d856a998ea1f7d3c6c9799d874566f0687276167b26181dac74fa6554972b8e529c0b3803af612e07d280005d2e5a25619
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- thrifty_file_applier (0.1.2)
4
+ thrifty_file_applier (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -33,6 +33,22 @@ FileUtils.rm "source/file"
33
33
  applier.apply # => compile
34
34
  ```
35
35
 
36
+ `applier` also treats multiple source path.
37
+
38
+ ```ruby
39
+ ThriftyFileApplier.applier("tmp/last_application_time", "source1", "source2") do
40
+ puts "compile"
41
+ end
42
+ ```
43
+
44
+ ### Shorthands
45
+ If reusing applier was not needed, shorthands are available.
46
+ ```ruby
47
+ ThriftyFileApplier.apply("tmp/last_application_time", "source") do
48
+ puts "compile"
49
+ end # => "compile"
50
+ ```
51
+
36
52
  ## Development
37
53
 
38
54
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThriftyFileApplier
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -7,15 +7,19 @@ require "fileutils"
7
7
  module ThriftyFileApplier
8
8
  class Error < StandardError; end
9
9
 
10
- def self.applier(last_execution_log_path, source_path, &executor)
11
- Applier.new(last_execution_log_path, source_path, &executor)
10
+ def self.applier(last_execution_log_path, *source_paths, &executor)
11
+ Applier.new(last_execution_log_path, *source_paths, &executor)
12
+ end
13
+
14
+ def self.apply(last_execution_log_path, *source_paths, &executor)
15
+ applier(last_execution_log_path, *source_paths, &executor).apply
12
16
  end
13
17
 
14
18
  # Actual applier class.
15
19
  class Applier
16
- def initialize(last_execution_log_path, source_path, &executor)
20
+ def initialize(last_execution_log_path, *source_paths, &executor)
17
21
  @last_execution_log_path = Pathname.new last_execution_log_path
18
- @update_source_path = Pathname.new source_path
22
+ @update_source_paths = source_paths.map { Pathname.new _1 }
19
23
  @executor = executor
20
24
  end
21
25
 
@@ -40,11 +44,13 @@ module ThriftyFileApplier
40
44
  end
41
45
 
42
46
  def last_update_time
43
- if @update_source_path.directory? && @update_source_path.children.size.positive?
44
- newest_mtime path
45
- else
46
- @update_source_path.mtime
47
- end
47
+ @update_source_paths.map { last_update_time_in _1 }.max
48
+ end
49
+
50
+ def last_update_time_in(path)
51
+ return Time.at 0 unless path.exist?
52
+
53
+ newest_mtime path
48
54
  end
49
55
 
50
56
  def last_execution_time
@@ -57,8 +63,11 @@ module ThriftyFileApplier
57
63
  end
58
64
 
59
65
  def newest_mtime(path)
60
- path.each_child
61
- .map { File.mtime(_1) }
66
+ return path.mtime if !path.directory? ||
67
+ (path.directory? && path.children.size.zero?)
68
+
69
+ path.children
70
+ .map { newest_mtime(_1) }
62
71
  .max
63
72
  end
64
73
  end
data/sample/sample.rb CHANGED
@@ -10,5 +10,12 @@ applier.apply # => compile
10
10
  applier.apply # => nil
11
11
  FileUtils.touch "source/file"
12
12
  applier.apply # => compile
13
- FileUtils.rm "source/file"
13
+ FileUtils.rm "tmp/last_application_time"
14
14
  applier.apply # => compile
15
+
16
+ FileUtils.rm "tmp/last_application_time"
17
+ ThriftyFileApplier.apply("tmp/last_application_time", "source") do
18
+ puts "compile"
19
+ end # => "compile"
20
+
21
+ FileUtils.rm "source/file"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrifty_file_applier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yudai Tanaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-30 00:00:00.000000000 Z
11
+ date: 2022-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: