fileverse 0.1.6 → 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: 5edf7aff9bcb4c6c6b9f59f9cc0b50d1413183e884aad9f38de7e2be7057eb80
4
- data.tar.gz: 2c62e407c449f6985232d838be9d04ba3c4b50ad55658afa74c251507e5ef42f
3
+ metadata.gz: eb4f08cab20e1b1b98e24f2313733732e0512a1c430eb14e757d87ab8419a9d3
4
+ data.tar.gz: fa9d796257f859c1fa7a94e6b285ef54d6974265679b9721ed9f4882fa696da8
5
5
  SHA512:
6
- metadata.gz: 40729a548fafc408dc36a2484e151e42af3e1fd5cff309a28814c4f3e2f00da2a6ca7799b99608d6747d0135537fd2ad83979ea191b68f7f8de7b6f901867ec2
7
- data.tar.gz: 713f376692bc057597933f737a4686aca65153b83d6ad7093617bf7782afa1a67fa54efc5a27b8dda1464198fd8f793cbcdb210b58bbd6f4358463523f314605
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,91 +4,121 @@ 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)
37
42
  rescue StandardError => e
38
43
  puts e.message
39
44
  end
40
45
  map "p" => "preview"
41
46
 
42
- desc "reset", "reset files. both the config and original"
47
+ desc "reset", "reset files. both the storage and original"
43
48
  def reset(path)
44
- setup path
49
+ setup_file_parser(path)
45
50
  @parser.parse
51
+ @parser.reset
52
+ setup_previewer
46
53
  @previewer.parse
47
54
  @previewer.preview_content = []
48
- @parser.reset
49
55
  Files.write_content(@path, @previewer.to_writable_lines)
50
- 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
51
59
  end
52
60
  map "x" => "reset"
53
61
 
54
- desc "summary", "return all the summary of snapshots"
55
- def summary(path)
56
- setup path
57
- @parser.parse_head
58
- 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
59
70
  end
60
- map "sm" => "summary"
71
+ map "sart" => "snap_and_restore_template"
61
72
 
62
73
  private
63
74
 
64
- 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)
65
82
  @path = Files.expand_path(path)
66
- @hidden_path = options[:template] ? Files.template_path : Files.expand_hidden_path(path)
67
- @parser = Parser.new(@hidden_path)
83
+ @storage_path = Files.template_path
84
+ @parser = Parser.new(@storage_path)
85
+ end
86
+
87
+ def setup_previewer
68
88
  @previewer = Previewer.new(@path)
69
89
  end
70
90
 
71
- 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
72
103
  Files.write_content(@path, @parser.cursor_content)
73
104
  @parser.remove_cursor_snapshot
74
- Files.write_content(@hidden_path, @parser.to_writable_lines)
105
+ Files.write_content(@storage_path, @parser.to_writable_lines)
75
106
  end
76
107
 
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)
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))
82
112
  end
83
113
 
84
- def preview_content # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
85
- if options[:name]
114
+ def preview_content # rubocop:disable Metrics/MethodLength
115
+ if @template_name
86
116
  @parser.snapshot_content_by_name(options[:name])
87
- elsif options[:bwd]
117
+ elsif @move_backward
88
118
  @parser.snapshot_content_backward
89
- elsif options[:fwd]
119
+ elsif @move_forward
90
120
  @parser.snapshot_content_forward
91
- elsif options[:index]
121
+ elsif @index
92
122
  @parser.snapshot_content_by_index(options[:index])
93
123
  else
94
124
  @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
@@ -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.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.6
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-21 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