thrifty_file_applier 0.1.1 → 0.1.4

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: 3e9c744c999f0768be1741c27c65f06bf48460164d6539e30ffb9cad384610be
4
- data.tar.gz: e75877da08240d7a15ae5e1308da2d9ebb74d2942af0ad7eba0d7995e73a97f2
3
+ metadata.gz: b2b182ac8ec44b18363dd385c06ecb2be25a59ee4739843a5a50acaf991b50cb
4
+ data.tar.gz: e10c9c36a3edd194e307cd0d4596f3bce1810fe4fcc13a46167795821687c6b8
5
5
  SHA512:
6
- metadata.gz: 8c7a6ae858ee4db371d22575c05ca670ad3c4bc563712c305fbd76a19770308cb6b0aae8185157b4c98542dd3a415b23d863edebdd8b5fb804056d97b7e24071
7
- data.tar.gz: 3a0d49dadb55467c5f4940c3235bbce5a9513c126c1c1a35de57646ebe12d6cf65f2cf66a0e543d93714efd31f9d76d53d33e6074a19195c02e4b6c714cb333f
6
+ metadata.gz: 83c1ca72d170b537be81f24f7d10f36fe9e3b24c69b0ee9edc45842cd4d7cc255a1976635cf90768454234f9d25571218783ee4bf105b45ef3f54357e21e5d26
7
+ data.tar.gz: 3a558bf863bcc064820c899c95c2dd9f4287c8c75eeb56492ccdb46ca11d9cb7341a068e6c4b97fd4ee4630c869960cdb8c15bab0610cbe184f280c86957d0ef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- thrifty_file_applier (0.1.0)
4
+ thrifty_file_applier (0.1.3)
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.1"
4
+ VERSION = "0.1.4"
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,10 +44,16 @@ 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?
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
+ if path.directory? && path.children.size.positive?
44
54
  newest_mtime path
45
55
  else
46
- @update_source_path.mtime
56
+ path.mtime
47
57
  end
48
58
  end
49
59
 
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.1
4
+ version: 0.1.4
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:
@@ -34,12 +34,12 @@ files:
34
34
  - lib/thrifty_file_applier/version.rb
35
35
  - sample/sample.rb
36
36
  - sig/update_watcher.rbs
37
- homepage: https://github.com/ytnk531/thrifty_file_appiler
37
+ homepage: https://github.com/ytnk531/thrifty_file_applier
38
38
  licenses:
39
39
  - MIT
40
40
  metadata:
41
- homepage_uri: https://github.com/ytnk531/thrifty_file_appiler
42
- source_code_uri: https://github.com/ytnk531/thrifty_file_appiler
41
+ homepage_uri: https://github.com/ytnk531/thrifty_file_applier
42
+ source_code_uri: https://github.com/ytnk531/thrifty_file_applier
43
43
  post_install_message:
44
44
  rdoc_options: []
45
45
  require_paths: