tori 0.0.1 → 0.0.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/.gitignore +1 -0
- data/README.md +3 -26
- data/lib/tori/config.rb +2 -2
- data/lib/tori/define.rb +2 -2
- data/lib/tori/rails.rb +1 -18
- data/lib/tori/version.rb +1 -1
- data/lib/tori.rb +12 -1
- data/test/test_tori.rb +1 -1
- data/test/test_tori_config.rb +2 -2
- 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: f5563a0b24b7c620e8e0e020e2b4b8c3820dcf11
|
4
|
+
data.tar.gz: 16681e5518f0836d94459819c097ba7e774e8e38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f145b9389b2623ccf0b7f60999b819f123e69fd1b1d784c830449ab1df6a148ad36c5eb01fad6020abbe34df0303186a9a9289ab562bc46dbd0c68466350f67
|
7
|
+
data.tar.gz: 89a1c87b3b89c221d07695389c531083f0ebb61e2715b6444355a9f7c9e6af1885ecf7f528f7495554bda1bd2df23847d6b6f08f971a5a85e04fcc7f1218ee06
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Tori
|
2
2
|
===
|
3
3
|
|
4
|
+
"(\\( ⁰⊖⁰)/)"
|
5
|
+
|
4
6
|
Tori is a very very simple file uploader.
|
5
7
|
|
6
8
|
Tori dose nothing.
|
@@ -56,35 +58,10 @@ app/views/photos/new.html.slim
|
|
56
58
|
|
57
59
|
# default configure
|
58
60
|
|
59
|
-
|
60
|
-
# Tori using hash function for decide filename.
|
61
|
-
# Filename dependent on class name and `id` setting with `tori` method in class.
|
62
|
-
Tori.config.hash_method = Digest::MD5.method(:hexdigest)
|
63
|
-
|
64
|
-
# Rails
|
65
|
-
Tori.config.backend = Tori::Backend::FileSystem.new(Rails.root.join('tmp', 'tori'))
|
66
|
-
|
67
|
-
# Other
|
68
|
-
Tori.config.backend = Tori::Backend::FileSystem.new(Pathname("tmp/tori"))
|
69
|
-
```
|
61
|
+
[https://github.com/ksss/tori/blob/master/lib/tori.rb](https://github.com/ksss/tori/blob/master/lib/tori.rb)
|
70
62
|
|
71
63
|
You can change configure any time.
|
72
64
|
|
73
|
-
# Options
|
74
|
-
|
75
|
-
Change hash resource data.
|
76
|
-
|
77
|
-
```
|
78
|
-
class Photo < ActiveRecord::Base
|
79
|
-
tori :image, id: :filename
|
80
|
-
def filename
|
81
|
-
"abc"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
```
|
85
|
-
|
86
|
-
This class never upload two file.
|
87
|
-
|
88
65
|
# future TODO
|
89
66
|
|
90
67
|
- support background S3 Storage
|
data/lib/tori/config.rb
CHANGED
data/lib/tori/define.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Tori
|
2
2
|
module Define
|
3
|
-
def tori(name
|
3
|
+
def tori(name)
|
4
4
|
name_hash_get = "#{name}_hash".to_sym
|
5
5
|
name_ivar = "@#{name}".to_sym
|
6
6
|
name_hash_ivar = "@#{name}_hash".to_sym
|
@@ -14,7 +14,7 @@ module Tori
|
|
14
14
|
end
|
15
15
|
|
16
16
|
define_method(name_hash_get) do
|
17
|
-
Tori.config.
|
17
|
+
Tori.config.filename_callback.call(self)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/tori/rails.rb
CHANGED
@@ -1,23 +1,6 @@
|
|
1
1
|
require 'tori'
|
2
2
|
|
3
3
|
module Tori
|
4
|
-
class Engine < Rails::Engine
|
5
|
-
initializer "tori.setup", before: :load_environment_config do
|
6
|
-
# Default backend config
|
7
|
-
# You can change setting any time.
|
8
|
-
# Recommend to create config/initializer/tori.rb for setting.
|
9
|
-
|
10
|
-
# Configure for file store backend instance.
|
11
|
-
Tori.config.backend = Tori::Backend::FileSystem.new(Rails.root.join('tmp', 'tori'))
|
12
|
-
|
13
|
-
# Filename hashing method
|
14
|
-
# It's call when decide filename hash.
|
15
|
-
# `hash_method` must be have `call` method.
|
16
|
-
# default: `Digest::MD5.method(:hexdigest)``
|
17
|
-
# Tori.config.hash_method = Digest::MD5.method(:hexdigest)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
4
|
module ActiveRecord
|
22
5
|
include Define
|
23
6
|
|
@@ -28,7 +11,7 @@ module Tori
|
|
28
11
|
# class Photo < ActiveRecord::Base
|
29
12
|
# tori :image, id: :id
|
30
13
|
# end
|
31
|
-
def tori(name
|
14
|
+
def tori(name)
|
32
15
|
super
|
33
16
|
|
34
17
|
name_hash_get = "#{name}_hash".to_sym
|
data/lib/tori/version.rb
CHANGED
data/lib/tori.rb
CHANGED
@@ -10,8 +10,19 @@ module Tori
|
|
10
10
|
class << self
|
11
11
|
def config
|
12
12
|
@config ||= Config.new.tap do |config|
|
13
|
+
# Default backend config
|
14
|
+
# You can change setting any time.
|
15
|
+
# Recommend to create config/initializer/tori.rb for setting.
|
16
|
+
|
17
|
+
# Configure for file store backend instance.
|
13
18
|
config.backend = Tori::Backend::FileSystem.new(Pathname("tmp/tori"))
|
14
|
-
|
19
|
+
|
20
|
+
# Filename hashing method
|
21
|
+
# It's call when decide filename hash.
|
22
|
+
# `filename_callback` must be have `call` method.
|
23
|
+
config.filename_callback = ->(model) do
|
24
|
+
Digest::MD5.hexdigest "#{model.class.name}/#{model.id}"
|
25
|
+
end
|
15
26
|
end
|
16
27
|
end
|
17
28
|
end
|
data/test/test_tori.rb
CHANGED
@@ -7,6 +7,6 @@ class TestTori < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
test "config default" do
|
9
9
|
assert_instance_of Tori::Backend::FileSystem, Tori.config.backend
|
10
|
-
|
10
|
+
assert_instance_of Proc, Tori.config.filename_callback
|
11
11
|
end
|
12
12
|
end
|
data/test/test_tori_config.rb
CHANGED
@@ -6,7 +6,7 @@ class TestToriConfig < Test::Unit::TestCase
|
|
6
6
|
assert_instance_of Tori::Config, i
|
7
7
|
assert_respond_to i, :backend
|
8
8
|
assert_respond_to i, :backend=
|
9
|
-
assert_respond_to i, :
|
10
|
-
assert_respond_to i, :
|
9
|
+
assert_respond_to i, :filename_callback
|
10
|
+
assert_respond_to i, :filename_callback=
|
11
11
|
end
|
12
12
|
end
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|