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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b56156ca6b54a4a9caa64b78d68786e6228a0a568b066fab4dd1ad30e9491f0
4
- data.tar.gz: ee5cec60536d69c3a83556a10bbc8c31d59f8938d8b4263c08c975dda4724d0a
3
+ metadata.gz: 8f6cd08648563d8596214ac2e8787b35656024a371b4d8473189e962477a6d8d
4
+ data.tar.gz: 31f35bf90ea022b62ae03c01d2218e3ba921cca742390d2271390d77e9309063
5
5
  SHA512:
6
- metadata.gz: 94380f9dc0658562320350a1422724d6855a51d882c8e9eacb3affce88fba98052e5adaea11a907eed0ceab4b82bcfbab4f2ebd0cb28deb92d63cc175351150d
7
- data.tar.gz: 63b7e5562d9997c0a91f3a055cb645d856a998ea1f7d3c6c9799d874566f0687276167b26181dac74fa6554972b8e529c0b3803af612e07d280005d2e5a25619
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.0.gem into the pkg directory" fullCommand="build" id="build" />
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.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
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.0.gem into system gems" fullCommand="install" id="install" />
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.0.gem into system gems without network access" fullCommand="install:local" id="local" />
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.0 and build and push thrifty_file_applier-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
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.6
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
- Style/EndOfLine:
15
- EnforcedStyle: lf
17
+ Layout/EndOfLine:
18
+ EnforcedStyle: lf
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'spec/**/*'
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+ gem "rubocop-rake", require: false
14
+ gem "rubocop-rspec", require: false
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 "source/file"
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 # => "compile"
49
+ end # => compile
50
50
  ```
51
51
 
52
52
  ## Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThriftyFileApplier
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
@@ -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(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
16
- end
17
-
18
- # Actual applier class.
19
- class Applier
20
- def initialize(last_execution_log_path, *source_paths, &executor)
21
- @last_execution_log_path = Pathname.new last_execution_log_path
22
- @update_source_paths = source_paths.map { Pathname.new _1 }
23
- @executor = executor
24
- end
25
-
26
- def apply
27
- exec_if_needed(&@executor)
28
- end
29
-
30
- def exec_if_needed(&block)
31
- return if last_execution_time >= last_update_time
32
-
33
- log_execution(&block)
34
- end
35
-
36
- private
37
-
38
- def log_execution
39
- execution_time = Time.now.to_f
40
- result = yield
41
- FileUtils.mkdir_p(@last_execution_log_path.dirname)
42
- @last_execution_log_path.open("wb") { |f| f.write(execution_time) }
43
- result
44
- end
45
-
46
- def last_update_time
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
54
- end
55
-
56
- def last_execution_time
57
- time_float = if @last_execution_log_path.exist?
58
- @last_execution_log_path.read.to_f
59
- else
60
- 0.0
61
- end
62
- Time.at time_float
63
- end
64
-
65
- def newest_mtime(path)
66
- return path.mtime if !path.directory? ||
67
- (path.directory? && path.children.size.zero?)
68
-
69
- path.children
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
@@ -16,6 +16,6 @@ applier.apply # => compile
16
16
  FileUtils.rm "tmp/last_application_time"
17
17
  ThriftyFileApplier.apply("tmp/last_application_time", "source") do
18
18
  puts "compile"
19
- end # => "compile"
19
+ end
20
20
 
21
21
  FileUtils.rm "source/file"
@@ -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.5
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-03 00:00:00.000000000 Z
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.6.0
53
+ version: 2.7.0
52
54
  required_rubygems_version: !ruby/object:Gem::Requirement
53
55
  requirements:
54
56
  - - ">="