tmp 1.0.1 → 1.1.0
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/README.md +18 -0
- data/VERSION +1 -1
- data/examples/test.rb +4 -0
- data/lib/tmp/config.rb +5 -2
- data/lib/tmp/function.rb +65 -30
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c9cdcb7143213d0cc2358bc0ad3af6787abe4786
         | 
| 4 | 
            +
              data.tar.gz: 8e5ae50398fb70f6232d27a47a33b6ee9c14a0dd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9501958ca1cf1821a6fb3a2d5bb770a30ab481898582b2736cf7b87737335f57264a9250e2b536c38414e0c4865495c8513747a77ef325934ac95c6b030bef43
         | 
| 7 | 
            +
              data.tar.gz: 22c254e9e7f6c108bfa2018e68bda37a99d8fcc92e3e64d2744ba26ec188faa06f6c5c0c90a73abc3b1abb52d3559d48c142c70eeae1c22a9ead68df5458a3f2
         | 
    
        data/README.md
    CHANGED
    
    | @@ -42,6 +42,24 @@ you can config the folder path for custom tmp folder use case if you dont want t | |
| 42 42 | 
             
                puts tmp.hello #> { hello: 'world'}
         | 
| 43 43 | 
             
            ```
         | 
| 44 44 |  | 
| 45 | 
            +
            ### Remove tmp objects
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            you can remove tmp objects by purge them
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            ```ruby
         | 
| 50 | 
            +
                require 'tmp'
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                tmp.hello = { hello: 'world'}
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                # now it's set
         | 
| 55 | 
            +
                puts tmp.hello #> { hello: 'world'}
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                TMP.purge!
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                # now it's nil
         | 
| 60 | 
            +
                puts tmp.hello #> nil
         | 
| 61 | 
            +
            ```
         | 
| 62 | 
            +
             | 
| 45 63 | 
             
            ### TODO
         | 
| 46 64 |  | 
| 47 65 | 
             
            * make ssl encryption for the tmp files opt able
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            1.0 | 
| 1 | 
            +
            1.1.0
         | 
    
        data/examples/test.rb
    CHANGED
    
    
    
        data/lib/tmp/config.rb
    CHANGED
    
    | @@ -3,7 +3,6 @@ module TMP | |
| 3 3 | 
             
              module Config
         | 
| 4 4 | 
             
                class << self
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 7 6 | 
             
                  def default_folder_path
         | 
| 8 7 | 
             
                    File.join( Dir.tmpdir, ( Dir.pwd.split(File::Separator).last.to_s  ) )
         | 
| 9 8 | 
             
                  end
         | 
| @@ -25,7 +24,11 @@ module TMP | |
| 25 24 |  | 
| 26 25 | 
             
                  end
         | 
| 27 26 |  | 
| 28 | 
            -
             | 
| 29 27 | 
             
                end
         | 
| 30 28 | 
             
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              def self.folder_path obj
         | 
| 31 | 
            +
                self::Config.folder_path(obj)
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 31 34 | 
             
            end
         | 
    
        data/lib/tmp/function.rb
    CHANGED
    
    | @@ -1,63 +1,98 @@ | |
| 1 1 | 
             
            #encoding: UTF-8
         | 
| 2 2 | 
             
            module TMP
         | 
| 3 | 
            -
              class << self
         | 
| 4 3 |  | 
| 5 | 
            -
             | 
| 4 | 
            +
              module Support
         | 
| 6 5 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
                  ::TMP::Config.folder_path
         | 
| 6 | 
            +
                class << self
         | 
| 9 7 |  | 
| 10 | 
            -
             | 
| 8 | 
            +
                  def tmp_folder_path
         | 
| 9 | 
            +
                    ::TMP::Config.folder_path
         | 
| 10 | 
            +
                  end
         | 
| 11 11 |  | 
| 12 | 
            -
             | 
| 12 | 
            +
                  alias :folder_path :tmp_folder_path
         | 
| 13 13 |  | 
| 14 | 
            -
             | 
| 14 | 
            +
                  def tmp_folder_init
         | 
| 15 15 |  | 
| 16 | 
            -
             | 
| 16 | 
            +
                    begin
         | 
| 17 17 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 18 | 
            +
                      Dir.mkdir tmp_folder_path
         | 
| 19 | 
            +
                      return true
         | 
| 20 20 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 21 | 
            +
                    rescue Errno::EEXIST
         | 
| 22 | 
            +
                      return false
         | 
| 23 | 
            +
                    end
         | 
| 24 24 |  | 
| 25 | 
            -
             | 
| 25 | 
            +
                  end
         | 
| 26 26 |  | 
| 27 | 
            -
             | 
| 27 | 
            +
                  def read_buffer path
         | 
| 28 28 |  | 
| 29 | 
            -
             | 
| 29 | 
            +
                    comm_line= File.open(path,"r")
         | 
| 30 30 |  | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 31 | 
            +
                    read_buffer = ::Thread.new do
         | 
| 32 | 
            +
                      while !comm_line.eof?
         | 
| 33 | 
            +
                        @value = ::Marshal.load( comm_line )
         | 
| 34 | 
            +
                      end
         | 
| 34 35 | 
             
                    end
         | 
| 36 | 
            +
             | 
| 35 37 | 
             
                  end
         | 
| 36 38 |  | 
| 37 | 
            -
             | 
| 39 | 
            +
                  def write variable_name, data_object
         | 
| 38 40 |  | 
| 39 | 
            -
             | 
| 41 | 
            +
                    tmp_folder_init
         | 
| 40 42 |  | 
| 41 | 
            -
             | 
| 43 | 
            +
                    File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file|
         | 
| 44 | 
            +
                      return file.write ::Marshal.dump(data_object)
         | 
| 45 | 
            +
                    end
         | 
| 42 46 |  | 
| 43 | 
            -
                  File.open( File.join(tmp_folder_path,variable_name.to_s) ,"w") do |file|
         | 
| 44 | 
            -
                    return file.write ::Marshal.dump(data_object)
         | 
| 45 47 | 
             
                  end
         | 
| 46 48 |  | 
| 47 | 
            -
             | 
| 49 | 
            +
                  def read variable_name
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                    unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
         | 
| 52 | 
            +
                      return nil
         | 
| 53 | 
            +
                    end
         | 
| 48 54 |  | 
| 49 | 
            -
             | 
| 55 | 
            +
                    File.open( File.join(tmp_folder_path,variable_name.to_s) ,"r") do |file|
         | 
| 56 | 
            +
                      return ::Marshal.load file.read
         | 
| 57 | 
            +
                    end
         | 
| 50 58 |  | 
| 51 | 
            -
                  unless File.exist?(File.join(tmp_folder_path,variable_name.to_s))
         | 
| 52 | 
            -
                    return nil
         | 
| 53 59 | 
             
                  end
         | 
| 54 60 |  | 
| 55 | 
            -
                   | 
| 56 | 
            -
             | 
| 61 | 
            +
                  def purge_files
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    Dir.glob( File.join( tmp_folder_path,'**','*' ) ).each do |file_path|
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                      begin
         | 
| 66 | 
            +
                        File.delete file_path
         | 
| 67 | 
            +
                      rescue Errno::ENOENT
         | 
| 68 | 
            +
                      end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    end
         | 
| 71 | 
            +
             | 
| 57 72 | 
             
                  end
         | 
| 58 73 |  | 
| 74 | 
            +
             | 
| 75 | 
            +
             | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              class << self
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                def write(*args)
         | 
| 82 | 
            +
                  self::Support.write(*args)
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                def read(*args)
         | 
| 86 | 
            +
                  self::Support.read(*args)
         | 
| 59 87 | 
             
                end
         | 
| 60 88 |  | 
| 89 | 
            +
                def purge!
         | 
| 90 | 
            +
                  self::Support.purge_files
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                alias :purge :purge!
         | 
| 94 | 
            +
             | 
| 61 95 | 
             
              end
         | 
| 62 96 |  | 
| 97 | 
            +
             | 
| 63 98 | 
             
            end
         |