dcm 0.1.11 → 0.1.12
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/lib/cli.rb +5 -1
- data/lib/file_cache.rb +47 -0
- data/lib/version.rb +1 -1
- metadata +2 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 11e9d24e733e62e42b866c0fb8962ec3111228f273bf4864f15878e42dfdb90f
         | 
| 4 | 
            +
              data.tar.gz: 243c17924c3e8486b33dc48c667e478d29615d079207069064e3263d53844aa5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3bbf6481b825392ad56a76e03f2d32580d4c55cfa35076179eaa6b43b946b3499fdac08351549ad846420ce919b0aaf03225f63ba3f98f1f4fddd6b895031a78
         | 
| 7 | 
            +
              data.tar.gz: 4f7b4fb2e361eaedd33c0ab0f559fa654d31147238bd6f3f7d2904031a27f3c2658ff09ff5b486c2e60675bd7987948530af5bfa8043d4dfc80113676fa47cf3
         | 
    
        data/lib/cli.rb
    CHANGED
    
    | @@ -7,6 +7,7 @@ require "filesize" | |
| 7 7 | 
             
            require "json"
         | 
| 8 8 |  | 
| 9 9 | 
             
            require_relative "file_reader"
         | 
| 10 | 
            +
            require_relative "file_cache"
         | 
| 10 11 | 
             
            require_relative "codinginfo"
         | 
| 11 12 | 
             
            require_relative "tempfile_handler"
         | 
| 12 13 | 
             
            require_relative "diff_viewer"
         | 
| @@ -272,7 +273,10 @@ module Dcm | |
| 272 273 | 
             
                  if file.nil? || file == "-"
         | 
| 273 274 | 
             
                    file = TempfileHandler.create(STDIN.read, filename: ["stdin", ".dcm"])
         | 
| 274 275 | 
             
                  end
         | 
| 275 | 
            -
             | 
| 276 | 
            +
             | 
| 277 | 
            +
                  FileCache.get(file) do
         | 
| 278 | 
            +
                    Ecu::LabelList.from_dcm(FileReader.read(file))
         | 
| 279 | 
            +
                  end
         | 
| 276 280 | 
             
                rescue Ecu::DcmParserError => e
         | 
| 277 281 | 
             
                  STDERR.puts e.message
         | 
| 278 282 | 
             
                  STDERR.puts e.context
         | 
    
        data/lib/file_cache.rb
    ADDED
    
    | @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            require "tmpdir"
         | 
| 2 | 
            +
            require "digest"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class FileCache
         | 
| 5 | 
            +
              MAXDURATION = 60 * 10
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def self.get(filepath, &blk)
         | 
| 8 | 
            +
                new(filepath).cache!(&blk)
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              attr_reader :filepath
         | 
| 12 | 
            +
              def initialize(filepath)
         | 
| 13 | 
            +
                @filepath = filepath
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def cache!
         | 
| 17 | 
            +
                return read_cache if cached?
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                yield.tap { write_cache }
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              private
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def cached?
         | 
| 25 | 
            +
                exist? && up_to_date?
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def exist? = File.exist?(cachefilepath)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def up_to_date?
         | 
| 31 | 
            +
                return false unless exist?
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                (Time.now - File.mtime(cachefilepath)) < MAXDURATION
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              def read_cache
         | 
| 37 | 
            +
                Marshal.load(File.read(cachefilepath))
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              def write_cache(obj)
         | 
| 41 | 
            +
                File.write(cachefilepath, Marshal.dump(obj))
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def cachefilepath
         | 
| 45 | 
            +
                File.join(Dir.tmpdir, "dcm-#{Digest::MD5.hexdigest(filepath)}.dump")
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/lib/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dcm
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.12
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jonas Mueller
         | 
| @@ -177,6 +177,7 @@ files: | |
| 177 177 | 
             
            - lib/codinginfo.rb
         | 
| 178 178 | 
             
            - lib/core_ext.rb
         | 
| 179 179 | 
             
            - lib/diff_viewer.rb
         | 
| 180 | 
            +
            - lib/file_cache.rb
         | 
| 180 181 | 
             
            - lib/file_reader.rb
         | 
| 181 182 | 
             
            - lib/fuzzy_selector.rb
         | 
| 182 183 | 
             
            - lib/list_colorizer.rb
         |