tty-file 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/lib/tty/file.rb +75 -85
  4. data/lib/tty/file/create_file.rb +5 -5
  5. data/lib/tty/file/differ.rb +5 -4
  6. data/lib/tty/file/digest_file.rb +4 -4
  7. data/lib/tty/file/download_file.rb +5 -5
  8. data/lib/tty/file/version.rb +1 -1
  9. metadata +19 -56
  10. data/Rakefile +0 -10
  11. data/bin/console +0 -14
  12. data/bin/setup +0 -8
  13. data/spec/fixtures/cli_app/%name%_cli.rb +0 -2
  14. data/spec/fixtures/cli_app/commands/subcommand.rb +0 -2
  15. data/spec/fixtures/cli_app/excluded/%name%_cli.rb +0 -2
  16. data/spec/fixtures/templates/%file_name%.rb +0 -1
  17. data/spec/fixtures/templates/unit_test.rb +0 -1
  18. data/spec/spec_helper.rb +0 -94
  19. data/spec/unit/append_to_file_spec.rb +0 -110
  20. data/spec/unit/binary_spec.rb +0 -230
  21. data/spec/unit/checksum_file_spec.rb +0 -48
  22. data/spec/unit/chmod_spec.rb +0 -92
  23. data/spec/unit/copy_directory_spec.rb +0 -120
  24. data/spec/unit/copy_file_spec.rb +0 -172
  25. data/spec/unit/create_directory_spec.rb +0 -93
  26. data/spec/unit/create_file_spec.rb +0 -130
  27. data/spec/unit/diff_spec.rb +0 -107
  28. data/spec/unit/differ/call_spec.rb +0 -101
  29. data/spec/unit/download_file_spec.rb +0 -68
  30. data/spec/unit/escape_glob_path_spec.rb +0 -14
  31. data/spec/unit/inject_into_file_spec.rb +0 -176
  32. data/spec/unit/prepend_to_file_spec.rb +0 -124
  33. data/spec/unit/read_to_char_spec.rb +0 -24
  34. data/spec/unit/remove_file_spec.rb +0 -67
  35. data/spec/unit/replace_in_file_spec.rb +0 -140
  36. data/spec/unit/tail_file_spec.rb +0 -77
  37. data/tasks/console.rake +0 -11
  38. data/tasks/coverage.rake +0 -11
  39. data/tasks/spec.rake +0 -29
  40. data/tty-file.gemspec +0 -33
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'diff/lcs'
4
- require 'diff/lcs/hunk'
5
- require 'enumerator'
3
+ require "diff/lcs"
4
+ require "diff/lcs/hunk"
5
+ require "enumerator"
6
6
 
7
7
  module TTY
8
8
  module File
@@ -26,7 +26,8 @@ module TTY
26
26
  # @api public
27
27
  def call
28
28
  diffs = Diff::LCS.diff(string_a_lines, string_b_lines)
29
- return '' if diffs.empty?
29
+ return "" if diffs.empty?
30
+
30
31
  hunks = extract_hunks(diffs)
31
32
  format_hunks(hunks)
32
33
  end
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'stringio'
4
- require 'openssl'
3
+ require "stringio"
4
+ require "openssl"
5
5
 
6
6
  module TTY
7
7
  module File
8
8
  class DigestFile
9
9
  attr_reader :source
10
10
 
11
- def initialize(source, mode, options)
11
+ def initialize(source, mode)
12
12
  @source = source
13
13
  @digest = OpenSSL::Digest.new(mode)
14
14
  end
15
15
 
16
16
  def call
17
17
  if ::FileTest.file?(source.to_s)
18
- ::File.open(source, 'rb') { |f| checksum_io(f, @digest) }
18
+ ::File.open(source, "rb") { |f| checksum_io(f, @digest) }
19
19
  else
20
20
  non_file = source
21
21
  if non_file.is_a?(String)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'uri'
4
- require 'net/http'
3
+ require "uri"
4
+ require "net/http"
5
5
 
6
6
  module TTY
7
7
  module File
@@ -31,11 +31,11 @@ module TTY
31
31
 
32
32
  # @api private
33
33
  def download(uri, path, limit)
34
- raise DownloadError, 'Redirect limit reached!' if limit.zero?
34
+ raise DownloadError, "Redirect limit reached!" if limit.zero?
35
35
  content = []
36
36
 
37
37
  Net::HTTP.start(uri.host, uri.port,
38
- use_ssl: uri.scheme == 'https') do |http|
38
+ use_ssl: uri.scheme == "https") do |http|
39
39
  http.request_get(uri.request_uri) do |response|
40
40
  case response
41
41
  when Net::HTTPSuccess
@@ -43,7 +43,7 @@ module TTY
43
43
  content << seg
44
44
  end
45
45
  when Net::HTTPRedirection
46
- download(URI.parse(response['location']), path, limit - 1)
46
+ download(URI.parse(response["location"]), path, limit - 1)
47
47
  else
48
48
  response.error!
49
49
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module File
5
- VERSION = "0.8.0"
5
+ VERSION = "0.9.0"
6
6
  end # File
7
7
  end # TTY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-25 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.18'
33
+ version: '0.20'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.18'
40
+ version: '0.20'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: diff-lcs
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '1.5'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '1.5'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -84,14 +70,14 @@ dependencies:
84
70
  name: rspec
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - "~>"
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
75
  version: '3.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '3.0'
97
83
  - !ruby/object:Gem::Dependency
@@ -110,17 +96,17 @@ dependencies:
110
96
  version: '3.4'
111
97
  description: File manipulation utility methods.
112
98
  email:
113
- - me@piotrmurach.com
99
+ - piotr@piotrmurach.com
114
100
  executables: []
115
101
  extensions: []
116
- extra_rdoc_files: []
102
+ extra_rdoc_files:
103
+ - README.md
104
+ - CHANGELOG.md
105
+ - LICENSE.txt
117
106
  files:
118
107
  - CHANGELOG.md
119
108
  - LICENSE.txt
120
109
  - README.md
121
- - Rakefile
122
- - bin/console
123
- - bin/setup
124
110
  - lib/tty-file.rb
125
111
  - lib/tty/file.rb
126
112
  - lib/tty/file/create_file.rb
@@ -129,38 +115,15 @@ files:
129
115
  - lib/tty/file/download_file.rb
130
116
  - lib/tty/file/read_backward_file.rb
131
117
  - lib/tty/file/version.rb
132
- - spec/fixtures/cli_app/%name%_cli.rb
133
- - spec/fixtures/cli_app/commands/subcommand.rb
134
- - spec/fixtures/cli_app/excluded/%name%_cli.rb
135
- - spec/fixtures/templates/%file_name%.rb
136
- - spec/fixtures/templates/unit_test.rb
137
- - spec/spec_helper.rb
138
- - spec/unit/append_to_file_spec.rb
139
- - spec/unit/binary_spec.rb
140
- - spec/unit/checksum_file_spec.rb
141
- - spec/unit/chmod_spec.rb
142
- - spec/unit/copy_directory_spec.rb
143
- - spec/unit/copy_file_spec.rb
144
- - spec/unit/create_directory_spec.rb
145
- - spec/unit/create_file_spec.rb
146
- - spec/unit/diff_spec.rb
147
- - spec/unit/differ/call_spec.rb
148
- - spec/unit/download_file_spec.rb
149
- - spec/unit/escape_glob_path_spec.rb
150
- - spec/unit/inject_into_file_spec.rb
151
- - spec/unit/prepend_to_file_spec.rb
152
- - spec/unit/read_to_char_spec.rb
153
- - spec/unit/remove_file_spec.rb
154
- - spec/unit/replace_in_file_spec.rb
155
- - spec/unit/tail_file_spec.rb
156
- - tasks/console.rake
157
- - tasks/coverage.rake
158
- - tasks/spec.rake
159
- - tty-file.gemspec
160
118
  homepage: https://piotrmurach.github.io/tty
161
119
  licenses:
162
120
  - MIT
163
- metadata: {}
121
+ metadata:
122
+ allowed_push_host: https://rubygems.org
123
+ changelog_uri: https://github.com/piotrmurach/tty-file/blob/master/CHANGELOG.md
124
+ documentation_uri: https://www.rubydoc.info/gems/tty-file
125
+ homepage_uri: https://piotrmurach.github.io/tty
126
+ source_code_uri: https://github.com/piotrmurach/tty-file
164
127
  post_install_message:
165
128
  rdoc_options: []
166
129
  require_paths:
@@ -176,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
139
  - !ruby/object:Gem::Version
177
140
  version: '0'
178
141
  requirements: []
179
- rubygems_version: 3.0.3
142
+ rubygems_version: 3.1.2
180
143
  signing_key:
181
144
  specification_version: 4
182
145
  summary: File manipulation utility methods.
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- task default: :spec
8
-
9
- desc 'Run all specs'
10
- task ci: %w[ spec ]
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tty/file"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,2 +0,0 @@
1
- class AppCLI
2
- end
@@ -1,2 +0,0 @@
1
- class Subcommand < Command
2
- end
@@ -1,2 +0,0 @@
1
- class AppCLI
2
- end
@@ -1 +0,0 @@
1
- <%= foo %>
@@ -1 +0,0 @@
1
- class <%= class_name %>Test; end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'tty/file'
19
- require 'find'
20
- require "webmock/rspec"
21
-
22
- module Helpers
23
- def gem_root
24
- ::File.join(File.dirname(__FILE__), "..")
25
- end
26
-
27
- def dir_path(*args)
28
- path = ::File.join(gem_root, *args)
29
- ::FileUtils.mkdir_p(path) unless ::File.exist?(path)
30
- ::File.realpath(path)
31
- end
32
-
33
- def fixtures_path(*args)
34
- ::File.join(dir_path('spec', 'fixtures'), *args)
35
- end
36
-
37
- def tmp_path(*args)
38
- ::File.join(dir_path('tmp'), *args)
39
- end
40
-
41
- def tmp_pathname(*args)
42
- Pathname.new(tmp_path(*args))
43
- end
44
-
45
- def exists_and_identical?(source, dest)
46
- dest_path = tmp_path(dest)
47
- expect(::File.exist?(dest_path)).to be(true)
48
-
49
- source_path = fixtures_path(source)
50
- expect(::FileUtils).to be_identical(source_path, dest_path)
51
- end
52
-
53
- def strip_heredoc(content)
54
- indent = content.scan(/^[ \t]*(?=\S)/).min.size || 0
55
- content.gsub(/^[ \t]{#{indent}}/, '')
56
- end
57
- end
58
-
59
- RSpec.configure do |config|
60
- config.include(Helpers)
61
-
62
- config.before(:each) do
63
- FileUtils.cp_r(fixtures_path('/.'), tmp_path)
64
- end
65
-
66
- config.after(:each) do
67
- FileUtils.rm_rf(tmp_path)
68
- end
69
-
70
- config.expect_with :rspec do |expectations|
71
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
72
- end
73
-
74
- config.mock_with :rspec do |mocks|
75
- mocks.verify_partial_doubles = true
76
- end
77
-
78
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
79
- config.disable_monkey_patching!
80
-
81
- # This setting enables warnings. It's recommended, but in some cases may
82
- # be too noisy due to issues in dependencies.
83
- config.warnings = true
84
-
85
- if config.files_to_run.one?
86
- config.default_formatter = 'doc'
87
- end
88
-
89
- config.profile_examples = 2
90
-
91
- config.order = :random
92
-
93
- Kernel.srand config.seed
94
- end
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::File, "#append_to_file" do
4
- shared_context "appending to files" do
5
- it "appends to file" do
6
- file = path_factory.call('Gemfile')
7
-
8
- TTY::File.append_to_file(file, "gem 'tty'", verbose: false)
9
-
10
- expect(File.read(file)).to eq([
11
- "gem 'nokogiri'\n",
12
- "gem 'rails', '5.0.0'\n",
13
- "gem 'rack', '>=1.0'\n",
14
- "gem 'tty'"
15
- ].join)
16
- end
17
-
18
- it "appends multiple lines to file" do
19
- file = path_factory.call('Gemfile')
20
-
21
- TTY::File.append_to_file(file, "gem 'tty'\n", "gem 'rake'", verbose: false)
22
-
23
- expect(File.read(file)).to eq([
24
- "gem 'nokogiri'\n",
25
- "gem 'rails', '5.0.0'\n",
26
- "gem 'rack', '>=1.0'\n",
27
- "gem 'tty'\n",
28
- "gem 'rake'"
29
- ].join)
30
- end
31
-
32
- it "appends content in a block" do
33
- file = path_factory.call('Gemfile')
34
-
35
- TTY::File.append_to_file(file, verbose: false) { "gem 'tty'"}
36
-
37
- expect(File.read(file)).to eq([
38
- "gem 'nokogiri'\n",
39
- "gem 'rails', '5.0.0'\n",
40
- "gem 'rack', '>=1.0'\n",
41
- "gem 'tty'"
42
- ].join)
43
- end
44
-
45
- it "doesn't append if already present" do
46
- file = path_factory.call('Gemfile')
47
-
48
- TTY::File.append_to_file(file, "gem 'rack', '>=1.0'\n", force: false, verbose: false)
49
-
50
- expect(::File.read(file)).to eq([
51
- "gem 'nokogiri'\n",
52
- "gem 'rails', '5.0.0'\n",
53
- "gem 'rack', '>=1.0'\n",
54
- ].join)
55
- end
56
-
57
- it "appends safely checking if content already present" do
58
- file = path_factory.call('Gemfile')
59
-
60
- TTY::File.safe_append_to_file(file, "gem 'rack', '>=1.0'\n", verbose: false)
61
-
62
- expect(::File.read(file)).to eq([
63
- "gem 'nokogiri'\n",
64
- "gem 'rails', '5.0.0'\n",
65
- "gem 'rack', '>=1.0'\n",
66
- ].join)
67
- end
68
-
69
- it "appends multiple times by default" do
70
- file = path_factory.call('Gemfile')
71
-
72
- TTY::File.append_to_file(file, "gem 'tty'\n", verbose: false)
73
- TTY::File.append_to_file(file, "gem 'tty'\n", verbose: false)
74
-
75
- expect(::File.read(file)).to eq([
76
- "gem 'nokogiri'\n",
77
- "gem 'rails', '5.0.0'\n",
78
- "gem 'rack', '>=1.0'\n",
79
- "gem 'tty'\n",
80
- "gem 'tty'\n"
81
- ].join)
82
- end
83
-
84
- it "logs action" do
85
- file = path_factory.call('Gemfile')
86
- expect {
87
- TTY::File.add_to_file(file, "gem 'tty'")
88
- }.to output(/\e\[32mappend\e\[0m.*Gemfile/).to_stdout_from_any_process
89
- end
90
-
91
- it "logs action without color" do
92
- file = path_factory.call('Gemfile')
93
- expect {
94
- TTY::File.add_to_file(file, "gem 'tty'", color: false)
95
- }.to output(/\s+append.*Gemfile/).to_stdout_from_any_process
96
- end
97
- end
98
-
99
- context "when passed a String instance for the file argument" do
100
- let(:path_factory) { method(:tmp_path) }
101
-
102
- include_context "appending to files"
103
- end
104
-
105
- context "when passed a Pathname instance for the file argument" do
106
- let(:path_factory) { method(:tmp_pathname) }
107
-
108
- include_context "appending to files"
109
- end
110
- end