fileverse 0.1.5 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa201a13fbd4310e92d1abb0f0589a84612898af61e5971ba7c6edfa349c47b6
4
- data.tar.gz: 5896f09dd563c6df50b91cd4171a9bef539e926c36c761f3780ace0be32cfebb
3
+ metadata.gz: eb4f08cab20e1b1b98e24f2313733732e0512a1c430eb14e757d87ab8419a9d3
4
+ data.tar.gz: fa9d796257f859c1fa7a94e6b285ef54d6974265679b9721ed9f4882fa696da8
5
5
  SHA512:
6
- metadata.gz: 118538226ff51aa2065abafb8e5a2aa09c0314756619a119e36ef09a6bbc8179085a5c7e98f8a0aa05483be0e22cfcba060afcfd7d0cd1e5789ec318f0220b09
7
- data.tar.gz: 6a487fb4a144e40aa398917d942adfae39e20608a994b0370005f8f213bd4ddd78705a69284606bc0723e8a51a31eb248ad0548022c6e708b8c5abbc9435082d
6
+ metadata.gz: 319a6cd3418244abf49b1769b90e5a4255ce70ad2c3aed01d69d80dc49f88c960c2830d1b4b23b8a86a382acf50a68d73a3c54b228df3695addb72a389bd470f
7
+ data.tar.gz: 104f680f5bf3ee9008c356be7ec8ff4a345f3bcfba3e4e0905697fad62f5e37662283be9c56e048d031ecfc5bc434b87d13f4f555699f17ebf3aa09bed2e5220
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
- - summary {file_path} (sm)
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,90 +4,124 @@ 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
9
  options template: :boolean, name: :string
10
10
  def snap(path)
11
- setup path
11
+ setup_options
12
+ @template ? setup_template_parser(path) : setup_file_parser(path)
12
13
  @parser.parse
13
- @parser.add_snapshot(Files.read(@path), options[:name])
14
+ @parser.add_snapshot(Files.read(@path), @snapshot_name)
14
15
  Files.write_content(@path)
15
- Files.write_content(@hidden_path, @parser.to_writable_lines)
16
+ Files.write_content(@storage_path, @parser.to_writable_lines)
17
+ rescue StandardError => e
18
+ puts e.message
16
19
  end
17
20
  map "s" => "snap"
18
21
 
19
22
  desc "restore content", "restore content in the current cursor"
20
23
  options template: :boolean, name: :string
21
24
  def restore(path)
22
- setup path
23
- @parser.parse
24
- options[:template] ? restore_template : restore_snapshot
25
+ setup_options
26
+ @template ? restore_template_snapshot(path) : restore_file_snapshot(path)
27
+ rescue StandardError => e
28
+ puts e.message
25
29
  end
26
30
  map "r" => "restore"
27
31
 
28
32
  desc "preview snapshot", "preview snapshot at different index or name"
29
33
  options bwd: :boolean, fwd: :boolean, index: :numeric, name: :string, template: :boolean
30
34
  def preview(path)
31
- setup path
35
+ setup_options
36
+ @template ? setup_template_parser(path) : setup_file_parser(path)
32
37
  @parser.parse
33
- @previewer.parse
38
+ setup_previewer
34
39
  @previewer.preview_content = preview_content
35
40
  Files.write_content(@path, @previewer.to_writable_lines)
36
- Files.write_content(@hidden_path, @parser.to_writable_lines)
41
+ Files.write_content(@storage_path, @parser.to_writable_lines)
42
+ rescue StandardError => e
43
+ puts e.message
37
44
  end
38
45
  map "p" => "preview"
39
46
 
40
- desc "reset", "reset files. both the config and original"
47
+ desc "reset", "reset files. both the storage and original"
41
48
  def reset(path)
42
- setup path
49
+ setup_file_parser(path)
43
50
  @parser.parse
51
+ @parser.reset
52
+ setup_previewer
44
53
  @previewer.parse
45
54
  @previewer.preview_content = []
46
- @parser.reset
47
55
  Files.write_content(@path, @previewer.to_writable_lines)
48
- Files.write_content(@hidden_path, @parser.to_writable_lines)
56
+ Files.write_content(@storage_path, @parser.to_writable_lines)
57
+ rescue StandardError => e
58
+ puts e.message
49
59
  end
50
60
  map "x" => "reset"
51
61
 
52
- desc "summary", "return all the summary of snapshots"
53
- def summary(path)
54
- setup path
55
- @parser.parse_head
56
- puts @parser.summary
62
+ desc "snap restore", "snap and restore template"
63
+ options template_name: :string
64
+ def snap_and_restore_template(path)
65
+ snap path
66
+ @snapshot_name = @template_name
67
+ restore_template_snapshot path
68
+ rescue StandardError => e
69
+ puts e.message
57
70
  end
58
- map "sm" => "summary"
71
+ map "sart" => "snap_and_restore_template"
59
72
 
60
73
  private
61
74
 
62
- def setup(path)
75
+ def setup_file_parser(path)
76
+ @path = Files.expand_path(path)
77
+ @storage_path = Files.expand_hidden_path(path)
78
+ @parser = Parser.new(@storage_path)
79
+ end
80
+
81
+ def setup_template_parser(path)
63
82
  @path = Files.expand_path(path)
64
- @hidden_path = options[:template] ? Files.template_path : Files.expand_hidden_path(path)
65
- @parser = Parser.new(@hidden_path)
83
+ @storage_path = Files.template_path
84
+ @parser = Parser.new(@storage_path)
85
+ end
86
+
87
+ def setup_previewer
66
88
  @previewer = Previewer.new(@path)
67
89
  end
68
90
 
69
- def restore_snapshot
91
+ def setup_options
92
+ @template = options[:template]
93
+ @snapshot_name = options[:name]
94
+ @move_backward = options[:bwd]
95
+ @move_forward = options[:fwd]
96
+ @index = options[:index]
97
+ @template_name = options[:template_name]
98
+ end
99
+
100
+ def restore_file_snapshot(path)
101
+ setup_file_parser(path)
102
+ @parser.parse
70
103
  Files.write_content(@path, @parser.cursor_content)
71
104
  @parser.remove_cursor_snapshot
72
- Files.write_content(@hidden_path, @parser.to_writable_lines)
105
+ Files.write_content(@storage_path, @parser.to_writable_lines)
73
106
  end
74
107
 
75
- def restore_template
76
- template_content = @parser.snapshot_content_by_name(options[:name])
77
- return if template_content.nil?
78
-
79
- Files.write_content(@path, template_content)
108
+ def restore_template_snapshot(path)
109
+ setup_template_parser(path)
110
+ @parser.parse
111
+ Files.write_content(@path, @parser.snapshot_content_by_name(@snapshot_name))
80
112
  end
81
113
 
82
- def preview_content
83
- if options[:name]
114
+ def preview_content # rubocop:disable Metrics/MethodLength
115
+ if @template_name
84
116
  @parser.snapshot_content_by_name(options[:name])
85
- elsif options[:bwd]
117
+ elsif @move_backward
86
118
  @parser.snapshot_content_backward
87
- elsif options[:fwd]
119
+ elsif @move_forward
88
120
  @parser.snapshot_content_forward
89
- elsif options[:index]
121
+ elsif @index
90
122
  @parser.snapshot_content_by_index(options[:index])
123
+ else
124
+ @parser.cursor_content
91
125
  end
92
126
  end
93
127
  end
@@ -17,10 +17,24 @@ module Fileverse
17
17
  end
18
18
  end
19
19
 
20
- # Error for invalid cursor
21
- class InvalidCursorPointer < StandardError
22
- def initialize(section = nil)
23
- super("Invalid cursor.#{section}")
20
+ # Error for negative cursor
21
+ class NegativeCursorPointer < StandardError
22
+ def initialize
23
+ super("Cursor can not be negative.")
24
+ end
25
+ end
26
+
27
+ # Error for maximum cursor
28
+ class MaxCursorPointer < StandardError
29
+ def initialize
30
+ super("Cursor can not be larger that snapped length.")
31
+ end
32
+ end
33
+
34
+ # Error for maximum cursor
35
+ class NoContentForName < StandardError
36
+ def initialize(name)
37
+ super("No snapshot content for name: '#{name}'.")
24
38
  end
25
39
  end
26
40
  end
@@ -105,19 +105,21 @@ module Fileverse
105
105
  end
106
106
 
107
107
  def cursor_content
108
- raise InvalidCursorPointer if @cursor.negative? || @cursor > @snapshots.length
108
+ raise NegativeCursorPointer if @cursor.negative?
109
+ raise MaxCursorPointer if @cursor >= @snapshots.length
109
110
 
110
111
  @snapshots[@cursor].content
111
112
  end
112
113
 
113
114
  def snapshot_content_by_name(name)
114
- find_named_snapshot(name)&.content
115
+ content = find_named_snapshot(name)&.content
116
+ raise NoContentForName, name if content.nil?
117
+
118
+ content
115
119
  end
116
120
 
117
121
  def snapshot_content_by_index(index)
118
- raise InvalidCursorPointer if index.negative? || index > @snapshots.length
119
-
120
- @cursor = value
122
+ @cursor = index
121
123
  cursor_content
122
124
  end
123
125
 
@@ -173,14 +175,10 @@ module Fileverse
173
175
  end
174
176
 
175
177
  def decrement_cursor
176
- raise InvalidCursorPointer if (@cursor - 1).negative?
177
-
178
178
  @cursor -= 1
179
179
  end
180
180
 
181
181
  def increment_cursor
182
- raise InvalidCursorPointer if @cursor + 1 >= @snapshots.length
183
-
184
182
  @cursor += 1
185
183
  end
186
184
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fileverse
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.7"
5
5
  end
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.5
4
+ version: 0.1.7
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-16 00:00:00.000000000 Z
11
+ date: 2025-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor