thrifty_file_applier 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/untitled3.iml +7 -5
- data/.rubocop.yml +10 -3
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -0
- data/README.md +2 -2
- data/lib/thrifty_file_applier/version.rb +1 -1
- data/lib/thrifty_file_applier.rb +69 -74
- data/sample/sample.rb +1 -1
- data/sig/lib/thrifty_file_applier.rbs +28 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f6cd08648563d8596214ac2e8787b35656024a371b4d8473189e962477a6d8d
|
4
|
+
data.tar.gz: 31f35bf90ea022b62ae03c01d2218e3ba921cca742390d2271390d77e9309063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc0452f1fe2778ded4133713ff085715307b660fd5073323c7edaecf4b7d02425c35a1b3d62133d2861deeeb5911989c9734ad4f07264aba4f0ea125a96cbb4e
|
7
|
+
data.tar.gz: aa6bcdcd8a6ca9f1400dc3f531e11b1341a778d7f1c39f1faf00185310f1a842543de670ecd3a1b22f095b2ab2c66bcc8c106e6e4382c7261a49200b79efd51f
|
data/.idea/untitled3.iml
CHANGED
@@ -27,6 +27,8 @@
|
|
27
27
|
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
28
28
|
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.30.0, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
29
29
|
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.18.0, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-rake (v0.6.0, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v2.11.1, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
30
32
|
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
31
33
|
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, ruby-3.1.1-p18 (2)) [gem]" level="application" />
|
32
34
|
</component>
|
@@ -34,21 +36,21 @@
|
|
34
36
|
<option name="myRootTask">
|
35
37
|
<RakeTaskImpl id="rake">
|
36
38
|
<subtasks>
|
37
|
-
<RakeTaskImpl description="Build thrifty_file_applier-0.1.
|
39
|
+
<RakeTaskImpl description="Build thrifty_file_applier-0.1.5.gem into the pkg directory" fullCommand="build" id="build" />
|
38
40
|
<RakeTaskImpl id="build">
|
39
41
|
<subtasks>
|
40
|
-
<RakeTaskImpl description="Generate SHA512 checksum if thrifty_file_applier-0.1.
|
42
|
+
<RakeTaskImpl description="Generate SHA512 checksum if thrifty_file_applier-0.1.5.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
41
43
|
</subtasks>
|
42
44
|
</RakeTaskImpl>
|
43
45
|
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
44
46
|
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
45
|
-
<RakeTaskImpl description="Build and install thrifty_file_applier-0.1.
|
47
|
+
<RakeTaskImpl description="Build and install thrifty_file_applier-0.1.5.gem into system gems" fullCommand="install" id="install" />
|
46
48
|
<RakeTaskImpl id="install">
|
47
49
|
<subtasks>
|
48
|
-
<RakeTaskImpl description="Build and install thrifty_file_applier-0.1.
|
50
|
+
<RakeTaskImpl description="Build and install thrifty_file_applier-0.1.5.gem into system gems without network access" fullCommand="install:local" id="local" />
|
49
51
|
</subtasks>
|
50
52
|
</RakeTaskImpl>
|
51
|
-
<RakeTaskImpl description="Create tag v0.1.
|
53
|
+
<RakeTaskImpl description="Create tag v0.1.5 and build and push thrifty_file_applier-0.1.5.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
52
54
|
<RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
|
53
55
|
<RakeTaskImpl id="rubocop">
|
54
56
|
<subtasks>
|
data/.rubocop.yml
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
NewCops: enable
|
3
4
|
|
4
5
|
Style/StringLiterals:
|
5
6
|
Enabled: true
|
6
7
|
EnforcedStyle: double_quotes
|
8
|
+
Lint/ScriptPermission:
|
9
|
+
Enabled: false
|
7
10
|
|
8
11
|
Style/StringLiteralsInInterpolation:
|
9
12
|
Enabled: true
|
@@ -11,5 +14,9 @@ Style/StringLiteralsInInterpolation:
|
|
11
14
|
|
12
15
|
Layout/LineLength:
|
13
16
|
Max: 120
|
14
|
-
|
15
|
-
EnforcedStyle: lf
|
17
|
+
Layout/EndOfLine:
|
18
|
+
EnforcedStyle: lf
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Exclude:
|
22
|
+
- 'spec/**/*'
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -39,6 +39,10 @@ GEM
|
|
39
39
|
unicode-display_width (>= 1.4.0, < 3.0)
|
40
40
|
rubocop-ast (1.18.0)
|
41
41
|
parser (>= 3.1.1.0)
|
42
|
+
rubocop-rake (0.6.0)
|
43
|
+
rubocop (~> 1.0)
|
44
|
+
rubocop-rspec (2.11.1)
|
45
|
+
rubocop (~> 1.19)
|
42
46
|
ruby-progressbar (1.11.0)
|
43
47
|
unicode-display_width (2.1.0)
|
44
48
|
|
@@ -50,6 +54,8 @@ DEPENDENCIES
|
|
50
54
|
rake (~> 13.0)
|
51
55
|
rspec (~> 3.0)
|
52
56
|
rubocop (~> 1.21)
|
57
|
+
rubocop-rake
|
58
|
+
rubocop-rspec
|
53
59
|
thrifty_file_applier!
|
54
60
|
|
55
61
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ applier.apply # => compile
|
|
29
29
|
applier.apply # => nil
|
30
30
|
FileUtils.touch "source/file"
|
31
31
|
applier.apply # => compile
|
32
|
-
FileUtils.rm "
|
32
|
+
FileUtils.rm "tmp/last_application_time"
|
33
33
|
applier.apply # => compile
|
34
34
|
```
|
35
35
|
|
@@ -46,7 +46,7 @@ If reusing applier was not needed, shorthands are available.
|
|
46
46
|
```ruby
|
47
47
|
ThriftyFileApplier.apply("tmp/last_application_time", "source") do
|
48
48
|
puts "compile"
|
49
|
-
end # =>
|
49
|
+
end # => compile
|
50
50
|
```
|
51
51
|
|
52
52
|
## Development
|
data/lib/thrifty_file_applier.rb
CHANGED
@@ -1,74 +1,69 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "thrifty_file_applier/version"
|
4
|
-
require "fileutils"
|
5
|
-
|
6
|
-
# Executes specified block only if source file had been updated.
|
7
|
-
module ThriftyFileApplier
|
8
|
-
class Error < StandardError; end
|
9
|
-
|
10
|
-
def self.applier(
|
11
|
-
Applier.new(
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.apply(
|
15
|
-
applier(
|
16
|
-
end
|
17
|
-
|
18
|
-
# Actual applier class.
|
19
|
-
class Applier
|
20
|
-
def initialize(
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@executor = executor
|
24
|
-
end
|
25
|
-
|
26
|
-
def apply
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
result
|
44
|
-
end
|
45
|
-
|
46
|
-
def
|
47
|
-
@
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
.map { newest_mtime(_1) }
|
71
|
-
.max
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "thrifty_file_applier/version"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
# Executes specified block only if source file had been updated.
|
7
|
+
module ThriftyFileApplier
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
def self.applier(applied_time_path, *source_paths, &executor)
|
11
|
+
Applier.new(applied_time_path, *source_paths, &executor)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.apply(applied_time_path, *source_paths, &executor)
|
15
|
+
applier(applied_time_path, *source_paths, &executor).apply
|
16
|
+
end
|
17
|
+
|
18
|
+
# Actual applier class.
|
19
|
+
class Applier
|
20
|
+
def initialize(applied_time_path, *source_paths, &executor)
|
21
|
+
@last_applied_log_path = Pathname.new applied_time_path
|
22
|
+
@source_paths = source_paths.map { Pathname.new _1 }
|
23
|
+
@executor = executor
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply
|
27
|
+
exec_if_updated(&@executor)
|
28
|
+
end
|
29
|
+
|
30
|
+
def exec_if_updated(&block)
|
31
|
+
update_time_f = source_update_time.to_f
|
32
|
+
exec_with_log(update_time_f, &block) if update_time_f > last_applied_time_f
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def exec_with_log(time_f)
|
38
|
+
result = yield
|
39
|
+
|
40
|
+
FileUtils.mkdir_p(@last_applied_log_path.dirname)
|
41
|
+
@last_applied_log_path.open("wb") { |f| f.write(time_f) }
|
42
|
+
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
def source_update_time
|
47
|
+
@source_paths.map do |path|
|
48
|
+
path.exist? ? newest_mtime(path) : Time.at(0)
|
49
|
+
end.max
|
50
|
+
end
|
51
|
+
|
52
|
+
def newest_mtime(path)
|
53
|
+
return path.mtime if !path.directory? ||
|
54
|
+
(path.directory? && path.children.size.zero?)
|
55
|
+
|
56
|
+
path.children
|
57
|
+
.map { newest_mtime(_1) }
|
58
|
+
.max
|
59
|
+
end
|
60
|
+
|
61
|
+
def last_applied_time_f
|
62
|
+
if @last_applied_log_path.exist?
|
63
|
+
@last_applied_log_path.read.to_f
|
64
|
+
else
|
65
|
+
0.0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/sample/sample.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Executes specified block only if source file had been updated.
|
2
|
+
module ThriftyFileApplier
|
3
|
+
class Error < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.applier: [T] (String applied_time_path, *String source_paths) { () -> T } -> T
|
7
|
+
|
8
|
+
def self.apply: [T] (String applied_time_path, *String source_paths) { () -> T } -> T
|
9
|
+
|
10
|
+
# Actual applier class.
|
11
|
+
class Applier[T]
|
12
|
+
def initialize: (String applied_time_path, *String source_paths) { () -> T } -> void
|
13
|
+
|
14
|
+
def apply: () -> T
|
15
|
+
|
16
|
+
def exec_if_updated: [U] () { () -> U } -> U
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def exec_with_log: [U] (Float time_f) { () -> U } -> U
|
21
|
+
|
22
|
+
def source_update_time: () -> Time
|
23
|
+
|
24
|
+
def newest_mtime: (Pathname path) -> Time
|
25
|
+
|
26
|
+
def last_applied_time_f: () -> Float
|
27
|
+
end
|
28
|
+
end
|
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.
|
4
|
+
version: 0.1.6
|
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-06-
|
11
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/thrifty_file_applier.rb
|
34
34
|
- lib/thrifty_file_applier/version.rb
|
35
35
|
- sample/sample.rb
|
36
|
+
- sig/lib/thrifty_file_applier.rbs
|
36
37
|
- sig/update_watcher.rbs
|
37
38
|
homepage: https://github.com/ytnk531/thrifty_file_applier
|
38
39
|
licenses:
|
@@ -40,6 +41,7 @@ licenses:
|
|
40
41
|
metadata:
|
41
42
|
homepage_uri: https://github.com/ytnk531/thrifty_file_applier
|
42
43
|
source_code_uri: https://github.com/ytnk531/thrifty_file_applier
|
44
|
+
rubygems_mfa_required: 'true'
|
43
45
|
post_install_message:
|
44
46
|
rdoc_options: []
|
45
47
|
require_paths:
|
@@ -48,7 +50,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
50
|
requirements:
|
49
51
|
- - ">="
|
50
52
|
- !ruby/object:Gem::Version
|
51
|
-
version: 2.
|
53
|
+
version: 2.7.0
|
52
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
55
|
requirements:
|
54
56
|
- - ">="
|