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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5edf7aff9bcb4c6c6b9f59f9cc0b50d1413183e884aad9f38de7e2be7057eb80
4
- data.tar.gz: 2c62e407c449f6985232d838be9d04ba3c4b50ad55658afa74c251507e5ef42f
3
+ metadata.gz: 6335d9bc181aff24cf101ed933f2db142bf316d193a0e17683d165f72f435d1e
4
+ data.tar.gz: 05c445c1ec51228d4a3a3861222804e8c13715ae0f14213155422666ebb0224e
5
5
  SHA512:
6
- metadata.gz: 40729a548fafc408dc36a2484e151e42af3e1fd5cff309a28814c4f3e2f00da2a6ca7799b99608d6747d0135537fd2ad83979ea191b68f7f8de7b6f901867ec2
7
- data.tar.gz: 713f376692bc057597933f737a4686aca65153b83d6ad7093617bf7782afa1a67fa54efc5a27b8dda1464198fd8f793cbcdb210b58bbd6f4358463523f314605
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
- - 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,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
- 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
- Files.write_content(@path)
15
- Files.write_content(@hidden_path, @parser.to_writable_lines)
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
- setup path
23
- @parser.parse
24
- options[:template] ? restore_template : restore_snapshot
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
- setup path
37
+ setup_options
38
+ @template ? setup_template_parser(path) : setup_file_parser(path)
32
39
  @parser.parse
33
- @previewer.parse
40
+ setup_previewer
34
41
  @previewer.preview_content = preview_content
35
42
  Files.write_content(@path, @previewer.to_writable_lines)
36
- Files.write_content(@hidden_path, @parser.to_writable_lines)
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 config and original"
43
- def reset(path)
44
- setup path
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(@hidden_path, @parser.to_writable_lines)
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 "summary", "return all the summary of snapshots"
55
- def summary(path)
56
- setup path
57
- @parser.parse_head
58
- puts @parser.summary
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 "sm" => "summary"
76
+ map "sart" => "snap_and_restore_template"
61
77
 
62
78
  private
63
79
 
64
- def setup(path)
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
- @hidden_path = options[:template] ? Files.template_path : Files.expand_hidden_path(path)
67
- @parser = Parser.new(@hidden_path)
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 restore_snapshot
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(@hidden_path, @parser.to_writable_lines)
111
+ Files.write_content(@storage_path, @parser.to_writable_lines)
75
112
  end
76
113
 
77
- def restore_template
78
- template_content = @parser.snapshot_content_by_name(options[:name])
79
- return if template_content.nil?
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,Metrics/AbcSize
85
- if options[:name]
120
+ def preview_content # rubocop:disable Metrics/MethodLength
121
+ if @template_name
86
122
  @parser.snapshot_content_by_name(options[:name])
87
- elsif options[:bwd]
123
+ elsif @move_backward
88
124
  @parser.snapshot_content_backward
89
- elsif options[:fwd]
125
+ elsif @move_forward
90
126
  @parser.snapshot_content_forward
91
- elsif options[:index]
127
+ elsif @index
92
128
  @parser.snapshot_content_by_index(options[:index])
93
129
  else
94
130
  @parser.cursor_content
@@ -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
@@ -23,6 +23,10 @@ module Fileverse
23
23
  File.open(full_path, "w") { |file| file.puts content }
24
24
  end
25
25
 
26
+ def clear_content(path)
27
+ write_content path, []
28
+ end
29
+
26
30
  def template_path
27
31
  File.expand_path ".fileverse.template", Dir.home
28
32
  end
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fileverse
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
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.6
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-21 00:00:00.000000000 Z
11
+ date: 2025-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor