fileverse 0.1.3 → 0.1.4
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/exe/fileverse +1 -0
- data/lib/fileverse/cli.rb +12 -11
- data/lib/fileverse/files.rb +4 -0
- data/lib/fileverse/parser.rb +59 -65
- data/lib/fileverse/version.rb +1 -1
- data/lib/fileverse.rb +1 -2
- 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: b739dd6750e9f37a5720e9789800efa69c545abb67855d8f38630841f3c30870
|
4
|
+
data.tar.gz: d575e0eec8c760353b5b61d54f5e5e923cd6d261dd55d8a75533ed7079e7ecf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c64c1dca0991f50667bf048d74f88971b0611da8e309a9287f7bb679b8b8332c7cfc221e63eb4b411a6ce144a29243ee512a25c3f48e5f75173a25fe0e382fb
|
7
|
+
data.tar.gz: f551ff2f97acabd6299fea567425425261822361b789ef6065a966a25edaebc413c6938ad0db52068ba9d8d4c1a4527ae180176acb9ed38cef95f6ac0dbde98b
|
data/exe/fileverse
CHANGED
data/lib/fileverse/cli.rb
CHANGED
@@ -10,7 +10,7 @@ module Fileverse
|
|
10
10
|
def snap(path)
|
11
11
|
setup path
|
12
12
|
@parser.parse
|
13
|
-
@parser.add_snapshot(Files.read(@path),
|
13
|
+
@parser.add_snapshot(Files.read(@path), options[:name])
|
14
14
|
Files.write_content(@path)
|
15
15
|
Files.write_content(@hidden_path, @parser.to_writable_lines)
|
16
16
|
end
|
@@ -26,12 +26,12 @@ module Fileverse
|
|
26
26
|
map "r" => "restore"
|
27
27
|
|
28
28
|
desc "preview snapshot", "preview snapshot at different index or name"
|
29
|
-
options bwd: :boolean, fwd: :boolean, index: :numeric, name: :string
|
29
|
+
options bwd: :boolean, fwd: :boolean, index: :numeric, name: :string, template: :boolean
|
30
30
|
def preview(path)
|
31
31
|
setup path
|
32
32
|
@parser.parse
|
33
33
|
@previewer.parse
|
34
|
-
|
34
|
+
@previewer.preview_content = preview_content
|
35
35
|
Files.write_content(@path, @previewer.to_writable_lines)
|
36
36
|
Files.write_content(@hidden_path, @parser.to_writable_lines)
|
37
37
|
end
|
@@ -61,7 +61,7 @@ module Fileverse
|
|
61
61
|
|
62
62
|
def setup(path)
|
63
63
|
@path = Files.expand_path(path)
|
64
|
-
@hidden_path = Files.expand_hidden_path(path)
|
64
|
+
@hidden_path = options[:template] ? Files.template_path : Files.expand_hidden_path(path)
|
65
65
|
@parser = Parser.new(@hidden_path)
|
66
66
|
@previewer = Previewer.new(@path)
|
67
67
|
end
|
@@ -73,21 +73,22 @@ module Fileverse
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def restore_template
|
76
|
-
template_content = @parser.
|
76
|
+
template_content = @parser.snapshot_content_by_name(options[:name])
|
77
77
|
return if template_content.nil?
|
78
78
|
|
79
79
|
Files.write_content(@path, template_content)
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
83
|
-
if options[:
|
84
|
-
@parser.
|
82
|
+
def preview_content
|
83
|
+
if options[:name]
|
84
|
+
@parser.snapshot_content_by_name(options[:name])
|
85
|
+
elsif options[:bwd]
|
86
|
+
@parser.snapshot_content_backward
|
85
87
|
elsif options[:fwd]
|
86
|
-
@parser.
|
88
|
+
@parser.snapshot_content_forward
|
87
89
|
elsif options[:index]
|
88
|
-
@parser.
|
90
|
+
@parser.snapshot_content_by_index(options[:index])
|
89
91
|
end
|
90
|
-
@previewer.preview_content = @parser.cursor_content
|
91
92
|
end
|
92
93
|
end
|
93
94
|
end
|
data/lib/fileverse/files.rb
CHANGED
data/lib/fileverse/parser.rb
CHANGED
@@ -7,7 +7,7 @@ module Fileverse
|
|
7
7
|
# == Storage file Example content
|
8
8
|
#
|
9
9
|
# <######0
|
10
|
-
#
|
10
|
+
# shot> 6 ~> 9
|
11
11
|
# 9 ~> 12
|
12
12
|
# 12 ~> 15
|
13
13
|
# 15 ~> 18
|
@@ -28,12 +28,11 @@ module Fileverse
|
|
28
28
|
#
|
29
29
|
# == Example end
|
30
30
|
#
|
31
|
-
# It uses the head section which is what is between "<######{cursor}" and "######>".
|
32
|
-
#
|
33
|
-
# templates are represented as "template>{name}>{range}". While files are just represented as "{range}".
|
31
|
+
# It uses the head section which is what is between "<######{cursor}" and "######>" as the table to parse the file.
|
32
|
+
# Each line is a range represented like "{name}> {start} ~> {stop}". the "{name}>" part is optional.
|
34
33
|
# so the above example will parse as follows:
|
35
34
|
#
|
36
|
-
# -
|
35
|
+
# - shot> 6 ~> 9
|
37
36
|
#
|
38
37
|
# =======================================
|
39
38
|
# | // New file
|
@@ -77,14 +76,12 @@ module Fileverse
|
|
77
76
|
@line_index = 0
|
78
77
|
@cursor = -1
|
79
78
|
@snapshots = []
|
80
|
-
@templates = []
|
81
79
|
end
|
82
80
|
|
83
81
|
def parse
|
84
82
|
return unless File.exist?(@path) && !peek_line.nil?
|
85
83
|
|
86
84
|
verify_first_header
|
87
|
-
parse_header_template_lines
|
88
85
|
parse_header_snapshot_lines
|
89
86
|
parse_snapshots
|
90
87
|
|
@@ -95,14 +92,15 @@ module Fileverse
|
|
95
92
|
@snapshots.length
|
96
93
|
end
|
97
94
|
|
98
|
-
def add_snapshot(content,
|
99
|
-
|
95
|
+
def add_snapshot(content, name = nil)
|
96
|
+
return if name && update_named_snapshot(name, content)
|
97
|
+
|
98
|
+
prev_snapshot = @snapshots[-1]
|
100
99
|
start = prev_snapshot&.stop || 3
|
101
|
-
snapshot = Snapshot.new(start, start + content.length,
|
100
|
+
snapshot = Snapshot.new(start, start + content.length, name)
|
102
101
|
snapshot.content = content
|
103
102
|
prev_snapshot&.next_snapshot = snapshot
|
104
|
-
|
105
|
-
(is_template ? @templates : @snapshots).push(snapshot)
|
103
|
+
@snapshots.push(snapshot)
|
106
104
|
reset
|
107
105
|
end
|
108
106
|
|
@@ -112,8 +110,25 @@ module Fileverse
|
|
112
110
|
@snapshots[@cursor].content
|
113
111
|
end
|
114
112
|
|
115
|
-
def
|
116
|
-
|
113
|
+
def snapshot_content_by_name(name)
|
114
|
+
find_named_snapshot(name)&.content
|
115
|
+
end
|
116
|
+
|
117
|
+
def snapshot_content_by_index(index)
|
118
|
+
raise InvalidCursorPointer if index.negative? || index > @snapshots.length
|
119
|
+
|
120
|
+
@cursor = value
|
121
|
+
cursor_content
|
122
|
+
end
|
123
|
+
|
124
|
+
def snapshot_content_backward
|
125
|
+
decrement_cursor
|
126
|
+
cursor_content
|
127
|
+
end
|
128
|
+
|
129
|
+
def snapshot_content_forward
|
130
|
+
increment_cursor
|
131
|
+
cursor_content
|
117
132
|
end
|
118
133
|
|
119
134
|
def remove_cursor_snapshot
|
@@ -127,53 +142,46 @@ module Fileverse
|
|
127
142
|
end
|
128
143
|
|
129
144
|
def to_writable_lines
|
130
|
-
[*head_lines, *
|
131
|
-
end
|
132
|
-
|
133
|
-
def increment_cursor
|
134
|
-
raise InvalidCursorPointer if @cursor + 1 >= @snapshots.length
|
135
|
-
|
136
|
-
@cursor += 1
|
137
|
-
end
|
138
|
-
|
139
|
-
def decrement_cursor
|
140
|
-
raise InvalidCursorPointer if (@cursor - 1).negative?
|
141
|
-
|
142
|
-
@cursor -= 1
|
143
|
-
end
|
144
|
-
|
145
|
-
def cursor=(value)
|
146
|
-
raise InvalidCursorPointer if value.negative? || value > @snapshots.length
|
147
|
-
|
148
|
-
@cursor = value
|
145
|
+
[*head_lines, *snapshot_lines]
|
149
146
|
end
|
150
147
|
|
151
148
|
def reset
|
152
149
|
@cursor = @snapshots.length - 1
|
153
|
-
|
154
|
-
all_snapshots[0]&.update_start all_snapshots.length + 2
|
150
|
+
@snapshots[0]&.update_start @snapshots.length + 2
|
155
151
|
end
|
156
152
|
|
157
153
|
def parse_head
|
158
154
|
return unless File.exist?(@path) && !peek_line.nil?
|
159
155
|
|
160
156
|
verify_first_header
|
161
|
-
parse_header_template_lines
|
162
157
|
parse_header_snapshot_lines
|
163
158
|
end
|
164
159
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
160
|
+
private
|
161
|
+
|
162
|
+
def update_named_snapshot(name, content)
|
163
|
+
snapshot = find_named_snapshot(name)
|
164
|
+
return false unless snapshot
|
165
|
+
|
166
|
+
snapshot.content = content
|
167
|
+
reset
|
168
|
+
true
|
171
169
|
end
|
172
170
|
|
173
|
-
|
171
|
+
def find_named_snapshot(name)
|
172
|
+
@snapshots.find { |snapshot| snapshot.name == name }
|
173
|
+
end
|
174
|
+
|
175
|
+
def decrement_cursor
|
176
|
+
raise InvalidCursorPointer if (@cursor - 1).negative?
|
174
177
|
|
175
|
-
|
176
|
-
|
178
|
+
@cursor -= 1
|
179
|
+
end
|
180
|
+
|
181
|
+
def increment_cursor
|
182
|
+
raise InvalidCursorPointer if @cursor + 1 >= @snapshots.length
|
183
|
+
|
184
|
+
@cursor += 1
|
177
185
|
end
|
178
186
|
|
179
187
|
def verify_first_header
|
@@ -184,32 +192,23 @@ module Fileverse
|
|
184
192
|
@cursor = cursor.to_i
|
185
193
|
end
|
186
194
|
|
187
|
-
def parse_header_template_lines
|
188
|
-
loop do
|
189
|
-
break unless /\A\s*template>(?<name>\w+)>\s*(?<start>\d+)\s*~>\s*(?<stop>\d+)\s*\z/ =~ peek_line
|
190
|
-
|
191
|
-
next_line
|
192
|
-
@templates.push(Snapshot.new(start.to_i, stop.to_i, name))
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
195
|
def parse_header_snapshot_lines
|
197
196
|
loop do
|
198
197
|
line = next_line
|
199
|
-
unless /\A\s*(?<start>\d+)\s*~>\s*(?<stop>\d+)\s*\z/ =~ line
|
198
|
+
unless /\A\s*(?<name>\w*>)?\s*(?<start>\d+)\s*~>\s*(?<stop>\d+)\s*\z/ =~ line
|
200
199
|
break if line == CLOSE_TAG
|
201
200
|
|
202
|
-
raise CorruptFormat
|
201
|
+
raise CorruptFormat, "Unknow format found."
|
203
202
|
end
|
204
|
-
raise CorruptFormat if stop.to_i < start.to_i
|
203
|
+
raise CorruptFormat, "Start index cannot be larger than stop." if stop.to_i < start.to_i
|
205
204
|
|
206
|
-
@snapshots.push Snapshot.new(start.to_i, stop.to_i)
|
205
|
+
@snapshots.push Snapshot.new(start.to_i, stop.to_i, name&.chomp(">"))
|
207
206
|
end
|
208
207
|
end
|
209
208
|
|
210
209
|
def parse_snapshots
|
211
210
|
last_snap = nil
|
212
|
-
[*@
|
211
|
+
[*@snapshots].each do |snap|
|
213
212
|
raise CorruptFormat, " Wrong indexing in header." if line_index != snap.start
|
214
213
|
|
215
214
|
snap.content = parse_snap_content(snap)
|
@@ -241,16 +240,11 @@ module Fileverse
|
|
241
240
|
def head_lines
|
242
241
|
[
|
243
242
|
"#{START_TAG}#{cursor}",
|
244
|
-
*@
|
245
|
-
*@snapshots.map { |snap| "#{snap.start} ~> #{snap.stop}" },
|
243
|
+
*@snapshots.map { |snap| "#{snap.name ? "#{snap.name}>" : ""}#{snap.start} ~> #{snap.stop}" },
|
246
244
|
CLOSE_TAG
|
247
245
|
]
|
248
246
|
end
|
249
247
|
|
250
|
-
def template_lines
|
251
|
-
@templates.map(&:content).flatten
|
252
|
-
end
|
253
|
-
|
254
248
|
def snapshot_lines
|
255
249
|
@snapshots.map(&:content).flatten
|
256
250
|
end
|
data/lib/fileverse/version.rb
CHANGED
data/lib/fileverse.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.4
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|