restore_bundled_with 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -30
- data/lib/restore_bundled_with/cli.rb +23 -22
- data/lib/restore_bundled_with/lock.rb +62 -0
- data/lib/restore_bundled_with/repository.rb +24 -0
- data/lib/restore_bundled_with/version.rb +1 -1
- data/lib/restore_bundled_with.rb +2 -4
- data/restore_bundled_with.gemspec +2 -0
- metadata +3 -7
- data/.rubocop.yml +0 -8
- data/.rubocop_todo.yml +0 -15
- data/lib/restore_bundled_with/delete.rb +0 -13
- data/lib/restore_bundled_with/fetch.rb +0 -38
- data/lib/restore_bundled_with/insert.rb +0 -18
- data/lib/restore_bundled_with/restore.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af8a858be7e0523b6a271185753b3d615e9a9189
|
4
|
+
data.tar.gz: 0de4d442d934795308181450bdd15b2f76dbe33c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c9d3785360cf8485a5536aa2f792aa1e81b8332ccf657f158d56fd7c4a13cc969b60aba5d6bae7035b90886b83bb2ff355ce36f7f3eebbaf2d73e34c3d2e8e3
|
7
|
+
data.tar.gz: 25b8d557fb2a1e51f3e35613a1167db1b1977060ad4e5ebca48adc662ded22524c70ce4bf2b8aa022956f6f4f1b2dde9715ee32fc72cd24ed980051969ab587a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -102,10 +102,10 @@ There is no diff, because this restores `BUNDLED WITH` from git repository.
|
|
102
102
|
|
103
103
|
```text
|
104
104
|
Commands:
|
105
|
-
restore-bundled-with delete # Delete BUNDLED WITH
|
105
|
+
restore-bundled-with delete # Delete BUNDLED WITH section
|
106
106
|
restore-bundled-with fetch # Fetch BUNDLED WITH section
|
107
107
|
restore-bundled-with help [COMMAND] # Describe available commands or one specific command
|
108
|
-
restore-bundled-with restore # Restore BUNDLED WITH
|
108
|
+
restore-bundled-with restore # Restore BUNDLED WITH section in Gemfile.lock
|
109
109
|
restore-bundled-with version # Show the RestoreBundledWith version
|
110
110
|
|
111
111
|
Usage:
|
@@ -126,34 +126,7 @@ Options:
|
|
126
126
|
[--debug], [--no-debug]
|
127
127
|
[--verbose], [--no-verbose]
|
128
128
|
|
129
|
-
Restore BUNDLED WITH
|
130
|
-
|
131
|
-
Usage:
|
132
|
-
restore-bundled-with delete
|
133
|
-
|
134
|
-
Options:
|
135
|
-
[--data=DATA]
|
136
|
-
[--file=FILE]
|
137
|
-
[--debug], [--no-debug]
|
138
|
-
[--verbose], [--no-verbose]
|
139
|
-
|
140
|
-
Delete BUNDLED WITH
|
141
|
-
|
142
|
-
Usage:
|
143
|
-
restore-bundled-with fetch
|
144
|
-
|
145
|
-
Options:
|
146
|
-
[--lockfile=LOCKFILE]
|
147
|
-
# Default: Gemfile.lock
|
148
|
-
[--ref=REF]
|
149
|
-
# Default: HEAD
|
150
|
-
[--git-path=GIT_PATH]
|
151
|
-
# Default: .
|
152
|
-
[--git-options=key:value]
|
153
|
-
[--debug], [--no-debug]
|
154
|
-
[--verbose], [--no-verbose]
|
155
|
-
|
156
|
-
Fetch BUNDLED WITH section
|
129
|
+
Restore BUNDLED WITH section in Gemfile.lock
|
157
130
|
```
|
158
131
|
|
159
132
|
## Installation
|
@@ -17,14 +17,14 @@ module RestoreBundledWith
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
desc 'restore', 'Restore BUNDLED WITH
|
20
|
+
desc 'restore', 'Restore BUNDLED WITH section in Gemfile.lock'
|
21
21
|
option :data
|
22
22
|
option :file
|
23
|
-
option :lockfile, type: :string, default:
|
24
|
-
option :ref, type: :string, default:
|
25
|
-
option :git_path, type: :string, default:
|
26
|
-
option :git_options, type: :hash, default:
|
27
|
-
option :new_line, type: :string, default:
|
23
|
+
option :lockfile, type: :string, default: Repository::LOCK_FILE
|
24
|
+
option :ref, type: :string, default: Repository::REF
|
25
|
+
option :git_path, type: :string, default: Repository::GIT_PATH
|
26
|
+
option :git_options, type: :hash, default: Repository::GIT_OPTIONS
|
27
|
+
option :new_line, type: :string, default: Repository::NEW_LINE
|
28
28
|
option :debug, type: :boolean, default: false
|
29
29
|
option :verbose, type: :boolean, default: false
|
30
30
|
def restore
|
@@ -33,7 +33,7 @@ module RestoreBundledWith
|
|
33
33
|
params = options.dup
|
34
34
|
params[:file] = options[:lockfile] if !options[:data] && !options[:file]
|
35
35
|
data = read_data(params)
|
36
|
-
|
36
|
+
lock_file = Lock.restore(
|
37
37
|
data,
|
38
38
|
options[:lockfile],
|
39
39
|
options[:ref],
|
@@ -41,15 +41,14 @@ module RestoreBundledWith
|
|
41
41
|
options[:git_options],
|
42
42
|
options[:new_line]
|
43
43
|
)
|
44
|
-
lockfile
|
45
|
-
lockfile.write
|
44
|
+
lock_file.write_to(options[:lockfile])
|
46
45
|
rescue StandardError => e
|
47
46
|
suggest_messages(options)
|
48
47
|
raise e
|
49
48
|
end
|
50
49
|
default_command :restore
|
51
50
|
|
52
|
-
desc 'delete', 'Delete BUNDLED WITH'
|
51
|
+
desc 'delete', 'Delete BUNDLED WITH section'
|
53
52
|
option :data
|
54
53
|
option :file
|
55
54
|
option :debug, type: :boolean, default: false
|
@@ -58,28 +57,30 @@ module RestoreBundledWith
|
|
58
57
|
setup_logger(options)
|
59
58
|
|
60
59
|
data = read_data(options)
|
61
|
-
puts
|
60
|
+
puts Lock.new(data).delete_bundled_with
|
62
61
|
rescue StandardError => e
|
63
62
|
suggest_messages(options)
|
64
63
|
raise e
|
65
64
|
end
|
66
65
|
|
67
66
|
desc 'fetch', 'Fetch BUNDLED WITH section'
|
68
|
-
option :lockfile, type: :string, default:
|
69
|
-
option :ref, type: :string, default:
|
70
|
-
option :git_path, type: :string, default:
|
71
|
-
option :git_options, type: :hash, default:
|
67
|
+
option :lockfile, type: :string, default: Repository::LOCK_FILE
|
68
|
+
option :ref, type: :string, default: Repository::REF
|
69
|
+
option :git_path, type: :string, default: Repository::GIT_PATH
|
70
|
+
option :git_options, type: :hash, default: Repository::GIT_OPTIONS
|
71
|
+
option :new_line, type: :string, default: Repository::NEW_LINE
|
72
72
|
option :debug, type: :boolean, default: false
|
73
73
|
option :verbose, type: :boolean, default: false
|
74
74
|
def fetch
|
75
75
|
setup_logger(options)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
lock_file = Repository
|
77
|
+
.new(options[:git_path], options[:git_options])
|
78
|
+
.fetch_file(
|
79
|
+
options[:lockfile],
|
80
|
+
options[:ref],
|
81
|
+
options[:new_line])
|
82
|
+
puts Lock
|
83
|
+
.new(lock_file)
|
83
84
|
.pick
|
84
85
|
rescue StandardError => e
|
85
86
|
suggest_messages(options)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module RestoreBundledWith
|
2
|
+
class Lock
|
3
|
+
attr_reader :body
|
4
|
+
|
5
|
+
REGEX_BUNDLED_WITH = /^(?<pick>(?:\r\n|\r|\n)^BUNDLED WITH.*(?:\r\n|\r|\n).+(?:\r\n|\r|\n))/
|
6
|
+
|
7
|
+
def self.insert(text, section)
|
8
|
+
if section && !section.empty?
|
9
|
+
new(text + section)
|
10
|
+
else
|
11
|
+
new(text)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.restore(
|
16
|
+
data,
|
17
|
+
lockfile = Repository::LOCK_FILE,
|
18
|
+
ref = Repository::REF,
|
19
|
+
git_path = Repository::GIT_PATH,
|
20
|
+
git_options = Repository::GIT_OPTIONS,
|
21
|
+
new_line = Repository::NEW_LINE
|
22
|
+
)
|
23
|
+
trimmed = new(data).delete_bundled_with
|
24
|
+
lock_file_data = Repository
|
25
|
+
.new(git_path, git_options)
|
26
|
+
.fetch_file(lockfile, ref, new_line)
|
27
|
+
section = new(lock_file_data)
|
28
|
+
.pick
|
29
|
+
insert(trimmed.body, section)
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(text)
|
33
|
+
@body = text
|
34
|
+
end
|
35
|
+
|
36
|
+
# "\n\nBUNDLED WITH\n 1.10.4\n" => "\n"
|
37
|
+
def delete_bundled_with
|
38
|
+
self.class.new(body.sub(REGEX_BUNDLED_WITH) { '' })
|
39
|
+
end
|
40
|
+
|
41
|
+
def pick
|
42
|
+
match = REGEX_BUNDLED_WITH.match(body)
|
43
|
+
if match
|
44
|
+
match[:pick]
|
45
|
+
else
|
46
|
+
''
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_s
|
51
|
+
body
|
52
|
+
end
|
53
|
+
|
54
|
+
def ==(other)
|
55
|
+
body == other.body
|
56
|
+
end
|
57
|
+
|
58
|
+
def write_to(path)
|
59
|
+
File.write(path, body)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RestoreBundledWith
|
2
|
+
class Repository
|
3
|
+
LOCK_FILE = 'Gemfile.lock'
|
4
|
+
REF = 'HEAD'
|
5
|
+
GIT_PATH = '.'
|
6
|
+
GIT_OPTIONS = {}
|
7
|
+
NEW_LINE = "\n"
|
8
|
+
|
9
|
+
def initialize(git_path = GIT_PATH, git_options = GIT_OPTIONS)
|
10
|
+
@git_path = git_path
|
11
|
+
@git_options = git_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def git
|
15
|
+
@git ||= Git.open(@git_path, @git_options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def fetch_file(file = LOCK_FILE, ref = REF, new_line = NEW_LINE)
|
19
|
+
# NOTE: git.cat_file trims last \n?
|
20
|
+
text = git.cat_file("#{ref}:#{file}")
|
21
|
+
text + new_line
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/restore_bundled_with.rb
CHANGED
@@ -2,10 +2,8 @@ require 'git'
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
require 'restore_bundled_with/error'
|
5
|
-
require 'restore_bundled_with/
|
6
|
-
require 'restore_bundled_with/
|
7
|
-
require 'restore_bundled_with/insert'
|
8
|
-
require 'restore_bundled_with/restore'
|
5
|
+
require 'restore_bundled_with/lock'
|
6
|
+
require 'restore_bundled_with/repository'
|
9
7
|
require 'restore_bundled_with/version'
|
10
8
|
|
11
9
|
module RestoreBundledWith
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restore_bundled_with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sanemat
|
@@ -104,8 +104,6 @@ extensions: []
|
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
106
|
- ".gitignore"
|
107
|
-
- ".rubocop.yml"
|
108
|
-
- ".rubocop_todo.yml"
|
109
107
|
- CHANGELOG.md
|
110
108
|
- CODE_OF_CONDUCT.md
|
111
109
|
- Gemfile
|
@@ -120,11 +118,9 @@ files:
|
|
120
118
|
- exe/restore-bundled-with
|
121
119
|
- lib/restore_bundled_with.rb
|
122
120
|
- lib/restore_bundled_with/cli.rb
|
123
|
-
- lib/restore_bundled_with/delete.rb
|
124
121
|
- lib/restore_bundled_with/error.rb
|
125
|
-
- lib/restore_bundled_with/
|
126
|
-
- lib/restore_bundled_with/
|
127
|
-
- lib/restore_bundled_with/restore.rb
|
122
|
+
- lib/restore_bundled_with/lock.rb
|
123
|
+
- lib/restore_bundled_with/repository.rb
|
128
124
|
- lib/restore_bundled_with/version.rb
|
129
125
|
- restore_bundled_with.gemspec
|
130
126
|
homepage: https://github.com/packsaddle/ruby-restore_bundled_with
|
data/.rubocop.yml
DELETED
data/.rubocop_todo.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-06-20 02:51:10 +0900 using RuboCop version 0.32.0.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
Metrics/AbcSize:
|
9
|
-
Exclude:
|
10
|
-
- lib/restore_bundled_with/cli.rb
|
11
|
-
|
12
|
-
# Configuration parameters: CountComments.
|
13
|
-
Metrics/MethodLength:
|
14
|
-
Exclude:
|
15
|
-
- lib/restore_bundled_with/cli.rb
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module RestoreBundledWith
|
2
|
-
class Fetch
|
3
|
-
LOCK_FILE = 'Gemfile.lock'
|
4
|
-
REF = 'HEAD'
|
5
|
-
GIT_PATH = '.'
|
6
|
-
GIT_OPTIONS = {}
|
7
|
-
# REGEX_PICK = /^(?<pick>\n^BUNDLED WITH.*\n.+\n)/
|
8
|
-
# git.cat_file trims last \n?
|
9
|
-
REGEX_PICK = /^(?<pick>\n^BUNDLED WITH.*\n.+)/
|
10
|
-
def initialize(
|
11
|
-
file = LOCK_FILE,
|
12
|
-
ref = REF,
|
13
|
-
git_path = GIT_PATH,
|
14
|
-
git_options = GIT_OPTIONS)
|
15
|
-
@file = file
|
16
|
-
@ref = ref
|
17
|
-
@git_path = git_path
|
18
|
-
@git_options = git_options
|
19
|
-
end
|
20
|
-
|
21
|
-
def pick
|
22
|
-
match = REGEX_PICK.match(target_file_contents)
|
23
|
-
if match
|
24
|
-
match[:pick]
|
25
|
-
else
|
26
|
-
''
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def target_file_contents
|
31
|
-
git.cat_file("#{@ref}:#{@file}")
|
32
|
-
end
|
33
|
-
|
34
|
-
def git
|
35
|
-
@git ||= ::Git.open(@git_path, @git_options)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module RestoreBundledWith
|
2
|
-
class Insert
|
3
|
-
NEW_LINE = "\n"
|
4
|
-
def initialize(body, section, new_line = NEW_LINE)
|
5
|
-
@body = body
|
6
|
-
@section = section
|
7
|
-
@new_line = new_line
|
8
|
-
end
|
9
|
-
|
10
|
-
def insert
|
11
|
-
if @section && !@section.empty?
|
12
|
-
@body + @section + @new_line
|
13
|
-
else
|
14
|
-
@body
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module RestoreBundledWith
|
2
|
-
class Restore
|
3
|
-
def initialize(
|
4
|
-
data,
|
5
|
-
lockfile = Fetch::LOCK_FILE,
|
6
|
-
ref = Fetch::REF,
|
7
|
-
git_path = Fetch::GIT_PATH,
|
8
|
-
git_options = Fetch::GIT_OPTIONS,
|
9
|
-
new_line = Insert::NEW_LINE
|
10
|
-
)
|
11
|
-
@data = data
|
12
|
-
@lockfile = lockfile
|
13
|
-
@ref = ref
|
14
|
-
@git_path = git_path
|
15
|
-
@git_options = git_options
|
16
|
-
@new_line = new_line
|
17
|
-
end
|
18
|
-
|
19
|
-
def restore
|
20
|
-
data = Delete.new(@data).delete
|
21
|
-
section = Fetch
|
22
|
-
.new(
|
23
|
-
@lockfile,
|
24
|
-
@ref,
|
25
|
-
@git_path,
|
26
|
-
@git_options)
|
27
|
-
.pick
|
28
|
-
@data = Insert.new(data, section, @new_line).insert
|
29
|
-
end
|
30
|
-
|
31
|
-
def write
|
32
|
-
File.write(@lockfile, @data)
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_s
|
36
|
-
@data
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|