fileverse 0.1.0 → 0.1.2
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 +48 -18
- data/lib/fileverse/errors.rb +7 -0
- data/lib/fileverse/files.rb +5 -1
- data/lib/fileverse/parser.rb +27 -7
- data/lib/fileverse/previewer.rb +2 -3
- 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: a14542329552682cfacbc80a77a520f6f67b8d879e68fc7ee901953039eddbaa
         | 
| 4 | 
            +
              data.tar.gz: 86d8f88902bf3dca295860636c073276322e0667524d0304a1db6e3de9c6527e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 64bfd38030920a3a5185ac8db6e82475392e32eb49e6a5d5b1a94c832aa914f9961a2e832f6b44608dfb71bf965e2ed8dd43cca56ebc6344089313fb4e87c1d1
         | 
| 7 | 
            +
              data.tar.gz: 104739b54efc776f2d71901cc9eac641104f4151165fe42288edd39de4641d99e4ea517177e975dff9c6f4d3025e9569f00fed29260c48e5311b2c6d635d66d6
         | 
    
        data/exe/fileverse
    CHANGED
    
    
    
        data/lib/fileverse/cli.rb
    CHANGED
    
    | @@ -7,36 +7,66 @@ module Fileverse | |
| 7 7 | 
             
              class CLI < Thor
         | 
| 8 8 | 
             
                desc "snap file content", "store current file content"
         | 
| 9 9 | 
             
                def snap(path)
         | 
| 10 | 
            -
                   | 
| 11 | 
            -
                  parser.parse
         | 
| 12 | 
            -
                  parser.add_snapshot(Files.read(path))
         | 
| 13 | 
            -
                  Files. | 
| 14 | 
            -
                  Files. | 
| 10 | 
            +
                  setup path
         | 
| 11 | 
            +
                  @parser.parse
         | 
| 12 | 
            +
                  @parser.add_snapshot(Files.read(@path))
         | 
| 13 | 
            +
                  Files.write_content(@path)
         | 
| 14 | 
            +
                  Files.write_content(@hidden_path, @parser.to_writable_lines)
         | 
| 15 15 | 
             
                end
         | 
| 16 16 | 
             
                map "s" => "snap"
         | 
| 17 17 |  | 
| 18 18 | 
             
                desc "restore content", "restore content in the current cursor"
         | 
| 19 19 | 
             
                def restore(path)
         | 
| 20 | 
            -
                   | 
| 21 | 
            -
                  parser.parse
         | 
| 22 | 
            -
                  Files. | 
| 23 | 
            -
                  parser.remove_cursor_snapshot
         | 
| 24 | 
            -
                  Files. | 
| 20 | 
            +
                  setup path
         | 
| 21 | 
            +
                  @parser.parse
         | 
| 22 | 
            +
                  Files.write_content(@path, @parser.cursor_content)
         | 
| 23 | 
            +
                  @parser.remove_cursor_snapshot
         | 
| 24 | 
            +
                  Files.write_content(@hidden_path, @parser.to_writable_lines)
         | 
| 25 25 | 
             
                end
         | 
| 26 26 | 
             
                map "r" => "restore"
         | 
| 27 27 |  | 
| 28 | 
            -
                 | 
| 29 | 
            -
                 | 
| 28 | 
            +
                desc "preview snapshot", "preview snapshot at different index or name"
         | 
| 29 | 
            +
                options bwd: :boolean, fwd: :boolean, index: :numeric, name: :string
         | 
| 30 | 
            +
                def preview(path)
         | 
| 31 | 
            +
                  setup path
         | 
| 32 | 
            +
                  @parser.parse
         | 
| 33 | 
            +
                  @previewer.parse
         | 
| 34 | 
            +
                  update_preview_content
         | 
| 35 | 
            +
                  Files.write_content(@path, @previewer.to_writable_lines)
         | 
| 36 | 
            +
                  Files.write_content(@hidden_path, @parser.to_writable_lines)
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
                map "p" => "preview"
         | 
| 30 39 |  | 
| 31 | 
            -
                 | 
| 32 | 
            -
                 | 
| 40 | 
            +
                desc "reset", "reset files. both the config and original"
         | 
| 41 | 
            +
                def reset(path)
         | 
| 42 | 
            +
                  setup path
         | 
| 43 | 
            +
                  @parser.parse
         | 
| 44 | 
            +
                  @previewer.parse
         | 
| 45 | 
            +
                  @previewer.preview_content = []
         | 
| 46 | 
            +
                  @parser.reset
         | 
| 47 | 
            +
                  Files.write_content(@path, @previewer.to_writable_lines)
         | 
| 48 | 
            +
                  Files.write_content(@hidden_path, @parser.to_writable_lines)
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
                map "x" => "reset"
         | 
| 33 51 |  | 
| 34 52 | 
             
                private
         | 
| 35 53 |  | 
| 36 | 
            -
                def  | 
| 37 | 
            -
                   | 
| 38 | 
            -
                   | 
| 39 | 
            -
                   | 
| 54 | 
            +
                def setup(path)
         | 
| 55 | 
            +
                  @path = Files.expand_path(path)
         | 
| 56 | 
            +
                  @hidden_path = Files.expand_hidden_path(path)
         | 
| 57 | 
            +
                  @parser = Parser::Header.new(@hidden_path)
         | 
| 58 | 
            +
                  @previewer = Previewer.new(@path)
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def update_preview_content
         | 
| 62 | 
            +
                  if options[:bwd]
         | 
| 63 | 
            +
                    @parser.decrement_cursor
         | 
| 64 | 
            +
                  elsif options[:fwd]
         | 
| 65 | 
            +
                    @parser.increment_cursor
         | 
| 66 | 
            +
                  elsif options[:index]
         | 
| 67 | 
            +
                    @parser.cursor = options[:index]
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                  @previewer.preview_content = @parser.cursor_content
         | 
| 40 70 | 
             
                end
         | 
| 41 71 | 
             
              end
         | 
| 42 72 | 
             
            end
         | 
    
        data/lib/fileverse/errors.rb
    CHANGED
    
    | @@ -16,4 +16,11 @@ module Fileverse | |
| 16 16 | 
             
                  super("The configuration file is corrupt.#{section}")
         | 
| 17 17 | 
             
                end
         | 
| 18 18 | 
             
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              # Error for invalid cursor
         | 
| 21 | 
            +
              class InvalidCursorPointer < StandardError
         | 
| 22 | 
            +
                def initialize(section = nil)
         | 
| 23 | 
            +
                  super("Invalid cursor.#{section}")
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 19 26 | 
             
            end
         | 
    
        data/lib/fileverse/files.rb
    CHANGED
    
    | @@ -4,6 +4,10 @@ module Fileverse | |
| 4 4 | 
             
              module Files # rubocop:disable Style/Documentation
         | 
| 5 5 | 
             
                module_function
         | 
| 6 6 |  | 
| 7 | 
            +
                def expand_path(path)
         | 
| 8 | 
            +
                  File.expand_path path, Dir.pwd
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 7 11 | 
             
                def expand_hidden_path(path)
         | 
| 8 12 | 
             
                  path = File.join(File.dirname(path), ".verse.#{File.basename(path)}")
         | 
| 9 13 | 
             
                  File.expand_path path, Dir.pwd
         | 
| @@ -14,7 +18,7 @@ module Fileverse | |
| 14 18 | 
             
                  File.readlines(full_path)
         | 
| 15 19 | 
             
                end
         | 
| 16 20 |  | 
| 17 | 
            -
                def  | 
| 21 | 
            +
                def write_content(path, content = [])
         | 
| 18 22 | 
             
                  full_path = File.expand_path path, Dir.pwd
         | 
| 19 23 | 
             
                  File.open(full_path, "w") { |file| file.puts content }
         | 
| 20 24 | 
             
                end
         | 
    
        data/lib/fileverse/parser.rb
    CHANGED
    
    | @@ -82,7 +82,7 @@ module Fileverse | |
| 82 82 | 
             
                  end
         | 
| 83 83 |  | 
| 84 84 | 
             
                  def parse
         | 
| 85 | 
            -
                    return  | 
| 85 | 
            +
                    return unless File.exist?(@path) && !peek_line.nil?
         | 
| 86 86 |  | 
| 87 87 | 
             
                    verify_first_header
         | 
| 88 88 | 
             
                    parse_header_template_lines
         | 
| @@ -103,11 +103,11 @@ module Fileverse | |
| 103 103 | 
             
                    snapshot.content = content
         | 
| 104 104 | 
             
                    last_snapshot&.next_snapshot = snapshot
         | 
| 105 105 | 
             
                    @snapshots.push(snapshot)
         | 
| 106 | 
            -
                     | 
| 106 | 
            +
                    reset
         | 
| 107 107 | 
             
                  end
         | 
| 108 108 |  | 
| 109 109 | 
             
                  def cursor_content
         | 
| 110 | 
            -
                    @snapshots[@cursor]&.content
         | 
| 110 | 
            +
                    @snapshots[@cursor]&.content || []
         | 
| 111 111 | 
             
                  end
         | 
| 112 112 |  | 
| 113 113 | 
             
                  def remove_cursor_snapshot
         | 
| @@ -117,22 +117,42 @@ module Fileverse | |
| 117 117 | 
             
                    snapshot_before = @snapshots[@cursor - 1]
         | 
| 118 118 | 
             
                    snapshot_before.next_snapshot = snapshot.next_snapshot if snapshot_before
         | 
| 119 119 | 
             
                    @snapshots = @snapshots[0, @cursor].concat(@snapshots[@cursor + 1..])
         | 
| 120 | 
            +
                    reset
         | 
| 120 121 | 
             
                  end
         | 
| 121 122 |  | 
| 122 123 | 
             
                  def to_writable_lines
         | 
| 123 124 | 
             
                    [*head_lines, *template_lines, *snapshot_lines]
         | 
| 124 125 | 
             
                  end
         | 
| 125 126 |  | 
| 126 | 
            -
                   | 
| 127 | 
            +
                  def increment_cursor
         | 
| 128 | 
            +
                    raise InvalidCursorPointer if @cursor + 1 >= @snapshots.length
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                    @cursor += 1
         | 
| 131 | 
            +
                  end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                  def decrement_cursor
         | 
| 134 | 
            +
                    raise InvalidCursorPointer if (@cursor - 1).negative?
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                    @cursor -= 1
         | 
| 137 | 
            +
                  end
         | 
| 127 138 |  | 
| 128 | 
            -
                  def  | 
| 139 | 
            +
                  def cursor=(value)
         | 
| 140 | 
            +
                    raise InvalidCursorPointer if value.negative? || value > @snapshots.length
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                    @cursor = value
         | 
| 143 | 
            +
                  end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                  def reset
         | 
| 129 146 | 
             
                    @cursor = @snapshots.length - 1
         | 
| 147 | 
            +
                    @snapshots[0]&.update_start @snapshots.length + 2
         | 
| 130 148 | 
             
                  end
         | 
| 131 149 |  | 
| 150 | 
            +
                  private
         | 
| 151 | 
            +
             | 
| 132 152 | 
             
                  def verify_first_header
         | 
| 133 153 | 
             
                    first_line = next_line
         | 
| 134 | 
            -
                    /\A<\#{6}(?<cursor | 
| 135 | 
            -
                    raise CorruptFormat unless cursor
         | 
| 154 | 
            +
                    /\A<\#{6}(?<cursor>-?\d+)\z/ =~ first_line
         | 
| 155 | 
            +
                    raise CorruptFormat, " Error parsing header" unless cursor
         | 
| 136 156 |  | 
| 137 157 | 
             
                    @cursor = cursor.to_i
         | 
| 138 158 | 
             
                  end
         | 
    
        data/lib/fileverse/previewer.rb
    CHANGED
    
    | @@ -19,8 +19,7 @@ module Fileverse | |
| 19 19 |  | 
| 20 20 | 
             
                def parse
         | 
| 21 21 | 
             
                  content = File.read @path
         | 
| 22 | 
            -
                   | 
| 23 | 
            -
                  match = /(#{PREVIEW_HEAD})?(?(1)(.*)(#{PREVIEW_FOOTER})(.*)|(.*))/m =~ content
         | 
| 22 | 
            +
                  match = /(#{PREVIEW_HEAD})?(?(1)(.*)(#{PREVIEW_FOOTER}\n?)(.*)|(.*))/m =~ content
         | 
| 24 23 | 
             
                  raise CorruptFormat, " Error: Parsing preview content" if match.nil?
         | 
| 25 24 |  | 
| 26 25 | 
             
                  @preview_content = $LAST_MATCH_INFO[2]&.split("\n") || []
         | 
| @@ -36,7 +35,7 @@ module Fileverse | |
| 36 35 | 
             
                def writable_preview_section
         | 
| 37 36 | 
             
                  return @preview_content if @preview_content.empty?
         | 
| 38 37 |  | 
| 39 | 
            -
                  [PREVIEW_HEAD, *@preview_content, PREVIEW_FOOTER]
         | 
| 38 | 
            +
                  [PREVIEW_HEAD, "", *@preview_content, "", PREVIEW_FOOTER]
         | 
| 40 39 | 
             
                end
         | 
| 41 40 | 
             
              end
         | 
| 42 41 | 
             
            end
         | 
    
        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.2
         | 
| 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-02 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: thor
         |