tori 0.2.0 → 0.3.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/lib/tori/backend/filesystem.rb +6 -4
- data/lib/tori/backend/s3.rb +9 -0
- data/lib/tori/file.rb +8 -5
- data/lib/tori/version.rb +1 -1
- data/test/test_tori_backend_filesystem.rb +7 -0
- data/test/test_tori_file.rb +19 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7f9e73b59d43f6d816af38e163263f8ad366b29f
         | 
| 4 | 
            +
              data.tar.gz: 61c1bfa6790ebf0b8f5e9ee6aa967c2a56d4150f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 62cf0872b2c0798d92a223c45badb6a7665bbddf923af5b42ef3e24588a081632b4e26805cbfde96092899c3fb8ea4730288a6e28fb68dccfd66c4d7c90f17e9
         | 
| 7 | 
            +
              data.tar.gz: c95fe43b976782cc20085f1ef00a562bd3b3eba620d6c13ecc66c6c19909dcbb1680f4962f4b1444dbbb0d26e930aae77211ce3944be51ff97e84d2f1142392b
         | 
| @@ -10,17 +10,19 @@ module Tori | |
| 10 10 | 
             
                  def write(filename, resource, opts = nil)
         | 
| 11 11 | 
             
                    case resource
         | 
| 12 12 | 
             
                    when String
         | 
| 13 | 
            -
                      ::File.open(path(filename), ' | 
| 13 | 
            +
                      ::File.open(path(filename), 'wb'){ |f| f.write resource }
         | 
| 14 14 | 
             
                    when Pathname
         | 
| 15 15 | 
             
                      # see also https://bugs.ruby-lang.org/issues/11199
         | 
| 16 16 | 
             
                      ::File.open(resource) { |src|
         | 
| 17 17 | 
             
                        FileUtils.mkdir_p path(filename).dirname
         | 
| 18 | 
            -
                        ::File.open(path(filename), ' | 
| 18 | 
            +
                        ::File.open(path(filename), 'wb'){ |dst|
         | 
| 19 19 | 
             
                          ::IO.copy_stream src, dst
         | 
| 20 20 | 
             
                        }
         | 
| 21 21 | 
             
                      }
         | 
| 22 22 | 
             
                    else
         | 
| 23 | 
            -
                      :: | 
| 23 | 
            +
                      ::File.open(path(filename), 'wb') do |dst|
         | 
| 24 | 
            +
                        ::IO.copy_stream resource, dst
         | 
| 25 | 
            +
                      end
         | 
| 24 26 | 
             
                    end
         | 
| 25 27 | 
             
                  end
         | 
| 26 28 |  | 
| @@ -34,7 +36,7 @@ module Tori | |
| 34 36 | 
             
                  alias exists? exist?
         | 
| 35 37 |  | 
| 36 38 | 
             
                  def read(filename)
         | 
| 37 | 
            -
                    ::File.read | 
| 39 | 
            +
                    ::File.read(path(filename), mode: 'rb')
         | 
| 38 40 | 
             
                  end
         | 
| 39 41 |  | 
| 40 42 | 
             
                  def path(filename)
         | 
    
        data/lib/tori/backend/s3.rb
    CHANGED
    
    | @@ -14,6 +14,15 @@ module Tori | |
| 14 14 | 
             
                  #
         | 
| 15 15 | 
             
                  # example:
         | 
| 16 16 | 
             
                  #   Tori.config.backend = Tori::Backend::S3.new(bucket: 'tori_bucket')
         | 
| 17 | 
            +
                  #   # or
         | 
| 18 | 
            +
                  #   Tori.config.backend = Tori::Backend::S3.new(
         | 
| 19 | 
            +
                  #     bucket: 'tori_bucket',
         | 
| 20 | 
            +
                  #     client: Aws::S3::Client.new(
         | 
| 21 | 
            +
                  #       access_key_id: 'your_access_key',
         | 
| 22 | 
            +
                  #       secret_access_key: 'your_secret_access_key',
         | 
| 23 | 
            +
                  #       region: 'your-region-1'
         | 
| 24 | 
            +
                  #     )
         | 
| 25 | 
            +
                  #   )
         | 
| 17 26 | 
             
                  def initialize(bucket:, client: nil)
         | 
| 18 27 | 
             
                    @bucket = bucket
         | 
| 19 28 | 
             
                    if client
         | 
    
        data/lib/tori/file.rb
    CHANGED
    
    | @@ -2,7 +2,12 @@ module Tori | |
| 2 2 | 
             
              class File
         | 
| 3 3 | 
             
                def initialize(model, from: nil, &block)
         | 
| 4 4 | 
             
                  @model = model
         | 
| 5 | 
            -
                   | 
| 5 | 
            +
                  if from.respond_to?(:read) and from.respond_to?(:rewind)
         | 
| 6 | 
            +
                    from.rewind
         | 
| 7 | 
            +
                    @from = from.read
         | 
| 8 | 
            +
                  else
         | 
| 9 | 
            +
                    @from = from
         | 
| 10 | 
            +
                  end
         | 
| 6 11 | 
             
                  @filename_callback = block
         | 
| 7 12 | 
             
                end
         | 
| 8 13 |  | 
| @@ -16,13 +21,11 @@ module Tori | |
| 16 21 | 
             
                alias to_s name
         | 
| 17 22 |  | 
| 18 23 | 
             
                def from?
         | 
| 19 | 
            -
                  !@from.nil? | 
| 24 | 
            +
                  !@from.nil?
         | 
| 20 25 | 
             
                end
         | 
| 21 26 |  | 
| 22 27 | 
             
                def write(opts = nil)
         | 
| 23 | 
            -
                   | 
| 24 | 
            -
                  path = Pathname.new(path) if path.kind_of?(String)
         | 
| 25 | 
            -
                  Tori.config.backend.write name, path, opts
         | 
| 28 | 
            +
                  Tori.config.backend.write name, @from, opts
         | 
| 26 29 | 
             
                end
         | 
| 27 30 |  | 
| 28 31 | 
             
                def delete
         | 
    
        data/lib/tori/version.rb
    CHANGED
    
    
| @@ -24,6 +24,9 @@ class TestToriBackendFileSystem < Test::Unit::TestCase | |
| 24 24 | 
             
              test "#read" do
         | 
| 25 25 | 
             
                assert { "text" == @filesystem.read("testfile") }
         | 
| 26 26 | 
             
                assert_raise(Errno::ENOENT){ @filesystem.read("nothing_file") }
         | 
| 27 | 
            +
                bin = (0..0xFF).to_a.pack("c*")
         | 
| 28 | 
            +
                File.open(@filesystem.root.join("binfile"), 'wb'){ |f| f.write bin }
         | 
| 29 | 
            +
                assert { bin == @filesystem.read("binfile") }
         | 
| 27 30 | 
             
              end
         | 
| 28 31 |  | 
| 29 32 | 
             
              test "#path" do
         | 
| @@ -42,6 +45,10 @@ class TestToriBackendFileSystem < Test::Unit::TestCase | |
| 42 45 | 
             
                @filesystem.write("copyfile", "string")
         | 
| 43 46 | 
             
                assert { "string" == @filesystem.read("copyfile") }
         | 
| 44 47 |  | 
| 48 | 
            +
                bin = (0..0xFF).to_a.pack("c*")
         | 
| 49 | 
            +
                @filesystem.write("binfile", bin)
         | 
| 50 | 
            +
                assert { bin == @filesystem.read("binfile") }
         | 
| 51 | 
            +
             | 
| 45 52 | 
             
                @filesystem.write(Pathname.new("copyfile"), @filesystem.path("testfile"))
         | 
| 46 53 | 
             
                assert { "text" == @filesystem.read("copyfile") }
         | 
| 47 54 |  | 
    
        data/test/test_tori_file.rb
    CHANGED
    
    | @@ -15,7 +15,10 @@ class TestToriFile < Test::Unit::TestCase | |
| 15 15 | 
             
              end
         | 
| 16 16 |  | 
| 17 17 | 
             
              class From
         | 
| 18 | 
            -
                def  | 
| 18 | 
            +
                def rewind
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def read
         | 
| 19 22 | 
             
                  __FILE__
         | 
| 20 23 | 
             
                end
         | 
| 21 24 | 
             
              end
         | 
| @@ -47,6 +50,21 @@ class TestToriFile < Test::Unit::TestCase | |
| 47 50 | 
             
                assert { true == File.exist?("test/tmp/copy") }
         | 
| 48 51 | 
             
              end
         | 
| 49 52 |  | 
| 53 | 
            +
              test "write with closed file" do
         | 
| 54 | 
            +
                tori_file = nil
         | 
| 55 | 
            +
                path = nil
         | 
| 56 | 
            +
                Tempfile.create("tempfile") do |f|
         | 
| 57 | 
            +
                  path = f.path
         | 
| 58 | 
            +
                  f.write("should be match ;)")
         | 
| 59 | 
            +
                  tori_file = Tori::File.new("tempfile", from: f)
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
                tori_file.write
         | 
| 62 | 
            +
                assert { true == File.exist?("test/tmp/tempfile") }
         | 
| 63 | 
            +
                assert { false == File.exist?(path) }
         | 
| 64 | 
            +
                assert { "should be match ;)" == File.read("test/tmp/tempfile") }
         | 
| 65 | 
            +
                assert { "should be match ;)" == tori_file.read }
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 50 68 | 
             
              test "#method_missing" do
         | 
| 51 69 | 
             
                assert { true == Tori::File.new(nil).respond_to?(:read) }
         | 
| 52 70 | 
             
                assert_raise(NameError) { Tori::File.new(nil).undefined }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: tori
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - ksss
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-09- | 
| 11 | 
            +
            date: 2015-09-23 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: aws-sdk-core
         |