thrifty_file_applier 0.1.3 → 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: 4b1666a3ee44acad92c754263c4f5293f38ad08c8fd886ad23efcc1695e192c9
4
- data.tar.gz: a07a11186f32bc2e6c53a22dd62275f83f0844bcf41024ffd1a5507415fbed2c
3
+ metadata.gz: 8f6cd08648563d8596214ac2e8787b35656024a371b4d8473189e962477a6d8d
4
+ data.tar.gz: 31f35bf90ea022b62ae03c01d2218e3ba921cca742390d2271390d77e9309063
5
5
  SHA512:
6
- metadata.gz: 3207fcb861f4a3da5c22612b10bbfd514e916a13fc5191fa6f640f9d12385e8f7d777e6ab550218484a17ce6b94d93474251f1f8b5f2099dd90ddf053e8c7ed9
7
- data.tar.gz: 3e6d5eed91164714ba3a10b630fa8ae676f53f869738992bfd50b661a161684a51a26663910ba47de5182ac12e5ec8db9c3f805b0fa360e6995c5ecbac243635
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
@@ -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/
@@ -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
 
@@ -41,6 +41,14 @@ ThriftyFileApplier.applier("tmp/last_application_time", "source1", "source2") do
41
41
  end
42
42
  ```
43
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
+
44
52
  ## Development
45
53
 
46
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.3"
4
+ VERSION = "0.1.6"
5
5
  end
@@ -1,71 +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_path, &executor)
11
- Applier.new(last_execution_log_path, source_path, &executor)
12
- end
13
-
14
- # Actual applier class.
15
- class Applier
16
- def initialize(last_execution_log_path, *source_paths, &executor)
17
- @last_execution_log_path = Pathname.new last_execution_log_path
18
- @update_source_paths = source_paths.map { Pathname.new _1 }
19
- @executor = executor
20
- end
21
-
22
- def apply
23
- exec_if_needed(&@executor)
24
- end
25
-
26
- def exec_if_needed(&block)
27
- return if last_execution_time >= last_update_time
28
-
29
- log_execution(&block)
30
- end
31
-
32
- private
33
-
34
- def log_execution
35
- execution_time = Time.now.to_f
36
- result = yield
37
- FileUtils.mkdir_p(@last_execution_log_path.dirname)
38
- @last_execution_log_path.open("wb") { |f| f.write(execution_time) }
39
- result
40
- end
41
-
42
- def last_update_time
43
- @update_source_paths.map { last_update_time_in _1 }.max
44
- end
45
-
46
- def last_update_time_in(path)
47
- return Time.at 0 unless path.exist?
48
-
49
- if path.directory? && path.children.size.positive?
50
- newest_mtime path
51
- else
52
- path.mtime
53
- end
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
- path.each_child
67
- .map { File.mtime(_1) }
68
- .max
69
- end
70
- end
71
- 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
@@ -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
20
+
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.3
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-02 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
  - - ">="