fileverse 0.1.6 → 0.1.8
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/README.md +1 -1
- data/lib/fileverse/cli.rb +74 -38
- data/lib/fileverse/errors.rb +7 -0
- data/lib/fileverse/files.rb +4 -0
- data/lib/fileverse/parser.rb +4 -1
- data/lib/fileverse/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6335d9bc181aff24cf101ed933f2db142bf316d193a0e17683d165f72f435d1e
|
4
|
+
data.tar.gz: 05c445c1ec51228d4a3a3861222804e8c13715ae0f14213155422666ebb0224e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5377a9535ac854ac7942ee4c119646efc924e81660cbf9dfe5150f64ca61ad490194d8e740bf108a7e7c09530ab44b9850ff9dda4e0b55f4fc81e7b823de14a7
|
7
|
+
data.tar.gz: d34e16c7dd38c67d57c6bf52c837857b814f5f1832ad1db2526239b825679c50b289a4d29ba054ed2db7ab839efc0e016a90991efb03baa0d45185215362323e
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ A simple ruby cli tool for keeping different versions of a file.
|
|
17
17
|
- preview --name="" {file_path} (p)
|
18
18
|
- preview --index=0 {file_path} (p)
|
19
19
|
- reset {file_path} (x)
|
20
|
-
-
|
20
|
+
- snap_and_restore_template {file_path} (sart)
|
21
21
|
- restore {file_path} (r)
|
22
22
|
|
23
23
|
## Sample
|
data/lib/fileverse/cli.rb
CHANGED
@@ -4,91 +4,127 @@ require "thor"
|
|
4
4
|
|
5
5
|
module Fileverse
|
6
6
|
# CLI class
|
7
|
-
class CLI < Thor
|
7
|
+
class CLI < Thor # rubocop:disable Metrics/ClassLength
|
8
8
|
desc "snap file content", "store current file content"
|
9
|
-
options template: :boolean, name: :string
|
9
|
+
options template: :boolean, name: :string, clear: :boolean
|
10
10
|
def snap(path)
|
11
|
-
|
11
|
+
setup_options
|
12
|
+
@template ? setup_template_parser(path) : setup_file_parser(path)
|
12
13
|
@parser.parse
|
13
|
-
@parser.add_snapshot(Files.read(@path),
|
14
|
-
Files.
|
15
|
-
Files.write_content(@
|
14
|
+
@parser.add_snapshot(Files.read(@path), @snapshot_name)
|
15
|
+
Files.clear_content(@path) if @clear
|
16
|
+
Files.write_content(@storage_path, @parser.to_writable_lines)
|
17
|
+
puts "snapped#{@clear ? " and cleared" : ""}."
|
18
|
+
rescue StandardError => e
|
19
|
+
puts e.message
|
16
20
|
end
|
17
21
|
map "s" => "snap"
|
18
22
|
|
19
23
|
desc "restore content", "restore content in the current cursor"
|
20
24
|
options template: :boolean, name: :string
|
21
25
|
def restore(path)
|
22
|
-
|
23
|
-
@
|
24
|
-
|
26
|
+
setup_options
|
27
|
+
@template ? restore_template_snapshot(path) : restore_file_snapshot(path)
|
28
|
+
puts "#{@snapshot_name || "snapshot at cursor index"} for #{@template ? "template" : "file"} restored."
|
29
|
+
rescue StandardError => e
|
30
|
+
puts e.message
|
25
31
|
end
|
26
32
|
map "r" => "restore"
|
27
33
|
|
28
34
|
desc "preview snapshot", "preview snapshot at different index or name"
|
29
35
|
options bwd: :boolean, fwd: :boolean, index: :numeric, name: :string, template: :boolean
|
30
36
|
def preview(path)
|
31
|
-
|
37
|
+
setup_options
|
38
|
+
@template ? setup_template_parser(path) : setup_file_parser(path)
|
32
39
|
@parser.parse
|
33
|
-
|
40
|
+
setup_previewer
|
34
41
|
@previewer.preview_content = preview_content
|
35
42
|
Files.write_content(@path, @previewer.to_writable_lines)
|
36
|
-
Files.write_content(@
|
43
|
+
Files.write_content(@storage_path, @parser.to_writable_lines)
|
37
44
|
rescue StandardError => e
|
38
45
|
puts e.message
|
39
46
|
end
|
40
47
|
map "p" => "preview"
|
41
48
|
|
42
|
-
desc "reset", "reset files. both the
|
43
|
-
def reset(path)
|
44
|
-
|
49
|
+
desc "reset", "reset files. both the storage and original"
|
50
|
+
def reset(path) # rubocop:disable Metrics/MethodLength
|
51
|
+
setup_file_parser(path)
|
45
52
|
@parser.parse
|
53
|
+
@parser.reset
|
54
|
+
setup_previewer
|
46
55
|
@previewer.parse
|
47
56
|
@previewer.preview_content = []
|
48
|
-
@parser.reset
|
49
57
|
Files.write_content(@path, @previewer.to_writable_lines)
|
50
|
-
Files.write_content(@
|
58
|
+
Files.write_content(@storage_path, @parser.to_writable_lines)
|
59
|
+
puts "storage reset."
|
60
|
+
rescue StandardError => e
|
61
|
+
puts e.message
|
51
62
|
end
|
52
63
|
map "x" => "reset"
|
53
64
|
|
54
|
-
desc "
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
65
|
+
desc "snap restore", "snap and restore template"
|
66
|
+
options template_name: :string
|
67
|
+
def snap_and_restore_template(path)
|
68
|
+
snap path
|
69
|
+
@snapshot_name = @template_name
|
70
|
+
Files.clear_content path
|
71
|
+
restore_template_snapshot path
|
72
|
+
puts "And restored template '#{@template_name}'."
|
73
|
+
rescue StandardError => e
|
74
|
+
puts e.message
|
59
75
|
end
|
60
|
-
map "
|
76
|
+
map "sart" => "snap_and_restore_template"
|
61
77
|
|
62
78
|
private
|
63
79
|
|
64
|
-
def
|
80
|
+
def setup_file_parser(path)
|
81
|
+
@path = Files.expand_path(path)
|
82
|
+
@storage_path = Files.expand_hidden_path(path)
|
83
|
+
@parser = Parser.new(@storage_path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def setup_template_parser(path)
|
65
87
|
@path = Files.expand_path(path)
|
66
|
-
@
|
67
|
-
@parser = Parser.new(@
|
88
|
+
@storage_path = Files.template_path
|
89
|
+
@parser = Parser.new(@storage_path)
|
90
|
+
end
|
91
|
+
|
92
|
+
def setup_previewer
|
68
93
|
@previewer = Previewer.new(@path)
|
69
94
|
end
|
70
95
|
|
71
|
-
def
|
96
|
+
def setup_options
|
97
|
+
@template = options[:template]
|
98
|
+
@snapshot_name = options[:name]
|
99
|
+
@move_backward = options[:bwd]
|
100
|
+
@move_forward = options[:fwd]
|
101
|
+
@index = options[:index]
|
102
|
+
@clear = options[:clear]
|
103
|
+
@template_name = options[:template_name]
|
104
|
+
end
|
105
|
+
|
106
|
+
def restore_file_snapshot(path)
|
107
|
+
setup_file_parser(path)
|
108
|
+
@parser.parse
|
72
109
|
Files.write_content(@path, @parser.cursor_content)
|
73
110
|
@parser.remove_cursor_snapshot
|
74
|
-
Files.write_content(@
|
111
|
+
Files.write_content(@storage_path, @parser.to_writable_lines)
|
75
112
|
end
|
76
113
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
Files.write_content(@path, template_content)
|
114
|
+
def restore_template_snapshot(path)
|
115
|
+
setup_template_parser(path)
|
116
|
+
@parser.parse
|
117
|
+
Files.write_content(@path, @parser.snapshot_content_by_name(@snapshot_name))
|
82
118
|
end
|
83
119
|
|
84
|
-
def preview_content # rubocop:disable Metrics/MethodLength
|
85
|
-
if
|
120
|
+
def preview_content # rubocop:disable Metrics/MethodLength
|
121
|
+
if @template_name
|
86
122
|
@parser.snapshot_content_by_name(options[:name])
|
87
|
-
elsif
|
123
|
+
elsif @move_backward
|
88
124
|
@parser.snapshot_content_backward
|
89
|
-
elsif
|
125
|
+
elsif @move_forward
|
90
126
|
@parser.snapshot_content_forward
|
91
|
-
elsif
|
127
|
+
elsif @index
|
92
128
|
@parser.snapshot_content_by_index(options[:index])
|
93
129
|
else
|
94
130
|
@parser.cursor_content
|
data/lib/fileverse/errors.rb
CHANGED
@@ -30,4 +30,11 @@ module Fileverse
|
|
30
30
|
super("Cursor can not be larger that snapped length.")
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
# Error for maximum cursor
|
35
|
+
class NoContentForName < StandardError
|
36
|
+
def initialize(name)
|
37
|
+
super("No snapshot content for name: '#{name}'.")
|
38
|
+
end
|
39
|
+
end
|
33
40
|
end
|
data/lib/fileverse/files.rb
CHANGED
data/lib/fileverse/parser.rb
CHANGED
@@ -112,7 +112,10 @@ module Fileverse
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def snapshot_content_by_name(name)
|
115
|
-
find_named_snapshot(name)&.content
|
115
|
+
content = find_named_snapshot(name)&.content
|
116
|
+
raise NoContentForName, name if content.nil?
|
117
|
+
|
118
|
+
content
|
116
119
|
end
|
117
120
|
|
118
121
|
def snapshot_content_by_index(index)
|
data/lib/fileverse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fileverse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Unegbu Kingsley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|