file_distribution 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- data.tar.gz: e7259171f747c761e79f4e04877438ceb32bcefc34bd7959439f881217b7f6a15e1c5b172926f7c0365b06d622880614b53fd00bd7b17298356df6734bcd0b84
4
- metadata.gz: d77dcd75cfb199ac1e1e6bf9b4f46389681fc853ab27076b5d0beeeb4cb443cdb666d0d61ebf72f177df39ff338c2ce7985a89419d7947f55b1c60534295a1d7
5
- SHA1:
6
- data.tar.gz: 800b6d7ecf62418a426111682e9a304284fc0e05
7
- metadata.gz: d5b5cb72d357425952bf40930e5b76f633593f02
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eaa94a19b025255aaf8b025cbafb52eea7ead248
4
+ data.tar.gz: 031ebb61ba60285c500dbc8f98d25ee1e44bbc63
5
+ SHA512:
6
+ metadata.gz: 9ad739b95a1fef51e32ff247c9b48c5b3fcf43ca29a697b61a0054e810184cf2aa03826e86e70e5174071a81d5e285dfa9f54e30941835833655bce91695ff00
7
+ data.tar.gz: 598187de802d1d9c14b0d60b783066a7e27203528aecaf12eb2ab07c3e493f888e94bc07350700e2841b532df0e654c7d70274691efe084606353a588fa972d5
data/Rakefile CHANGED
@@ -4,5 +4,5 @@ Rake::TestTask.new do |t|
4
4
  t.libs << 'test'
5
5
  end
6
6
 
7
- desc "Run tests"
8
- task :default => :test
7
+ desc 'Run tests'
8
+ task default: :test
@@ -20,11 +20,9 @@ class FileDistribution
20
20
  # Params:
21
21
  # - ext: file extension.
22
22
  def set_extension(ext)
23
- if ext.length > 0 && ext.chars.first != '.'
24
- @ext = '.' + ext
25
- else
26
- @ext = ext
27
- end
23
+ @ext = ext
24
+
25
+ @ext = sprintf('.%s', ext) if !ext.empty? && ext.chars.first != '.'
28
26
  end
29
27
 
30
28
  # Returns Destination path.
@@ -35,20 +33,20 @@ class FileDistribution
35
33
  # Params:
36
34
  # - id: database file ID etc.
37
35
  def hex_path(id)
38
- hex = "%x" % id
39
- hex = '0%s' % hex if hex.length % 2 != 0
40
- @path = File.join(@prefix,hex.scan(/../))
36
+ hex = sprintf('%x', id)
37
+ hex = sprintf('0%s', hex) if hex.length.odd?
38
+ @path = File.join(@prefix, hex.scan(/../))
41
39
  @path += @ext
42
40
  end
43
41
 
44
42
  # Params:
45
43
  # - path: source file path.
46
44
  #
47
- # Raises a SystemCallError if the file cannot be renamed.
45
+ # Raise a SystemCallError if the file cannot be renamed.
48
46
  def rename_from(path)
49
47
  dst_dir = File.dirname(@path)
50
- FileUtils.mkpath(dst_dir) unless File.exists?(dst_dir)
48
+ FileUtils.mkpath(dst_dir) unless File.exist?(dst_dir)
51
49
 
52
- File.rename(path,@path)
50
+ File.rename(path, @path)
53
51
  end
54
52
  end
@@ -7,81 +7,77 @@ require 'fileutils'
7
7
  require 'test/unit'
8
8
 
9
9
  class TestFileDistribution < Test::Unit::TestCase
10
-
10
+
11
11
  def setup
12
- if not File.exists?("/tmp/storage")
13
- FileUtils.mkdir("/tmp/storage")
14
- end
12
+ FileUtils.mkdir('/tmp/storage') unless File.exist?('/tmp/storage')
15
13
 
16
- @fd = FileDistribution.new("/tmp/storage//")
14
+ @fd = FileDistribution.new('/tmp/storage//')
17
15
  end
18
16
 
19
17
  def test_path
20
- assert_equal("/tmp/storage", @fd.get_path())
21
- end
18
+ assert_equal('/tmp/storage', @fd.get_path)
19
+ end
22
20
 
23
21
  def test_case1
24
- @fd.set_extension("tmp")
25
- @fd.set_extension(".dat")
22
+ @fd.set_extension('tmp')
23
+ @fd.set_extension('.dat')
26
24
  @fd.hex_path(102423)
27
- assert_equal("/tmp/storage/01/90/17.dat", @fd.get_path())
28
- end
25
+ assert_equal('/tmp/storage/01/90/17.dat', @fd.get_path)
26
+ end
29
27
 
30
28
  def test_case2
31
- @fd.set_extension("dat")
29
+ @fd.set_extension('dat')
32
30
  @fd.hex_path(256)
33
- assert_equal("/tmp/storage/01/00.dat", @fd.get_path())
31
+ assert_equal('/tmp/storage/01/00.dat', @fd.get_path)
34
32
  end
35
33
 
36
34
  # in most cases this is wrong way
37
35
  def test_case3
38
- @fd.set_extension("")
36
+ @fd.set_extension('')
39
37
  @fd.hex_path(256)
40
- assert_equal("/tmp/storage/01/00", @fd.get_path())
41
- end
38
+ assert_equal('/tmp/storage/01/00', @fd.get_path)
39
+ end
42
40
 
43
41
  def test_case4
44
42
  @fd.hex_path(1)
45
- assert_equal("/tmp/storage/01.dat", @fd.get_path())
46
- end
43
+ assert_equal('/tmp/storage/01.dat', @fd.get_path)
44
+ end
47
45
 
48
46
  def test_case5
49
47
  f = File.open('/tmp/storage/test.txt', 'w')
50
- f.close()
48
+ f.close
51
49
 
52
- assert_equal(true, File.exists?("/tmp/storage/test.txt"))
50
+ assert_equal(true, File.exist?('/tmp/storage/test.txt'))
53
51
 
54
- @fd.set_extension(".dat")
52
+ @fd.set_extension('.dat')
55
53
  @fd.hex_path(256)
56
54
 
57
- @fd.rename_from("/tmp/storage/test.txt")
58
- assert_equal(true, File.exists?("/tmp/storage/01/00.dat"))
59
- end
55
+ @fd.rename_from('/tmp/storage/test.txt')
56
+ assert_equal(true, File.exist?('/tmp/storage/01/00.dat'))
57
+ end
60
58
 
61
59
  def test_case6
62
60
  f = File.open('/tmp/storage/test1.txt', 'w')
63
- f.close()
61
+ f.close
64
62
 
65
63
  f = File.open('/tmp/storage/test2.txt', 'w')
66
- f.close()
64
+ f.close
67
65
 
68
- assert_equal(true, File.exists?("/tmp/storage/test1.txt"))
69
- assert_equal(true, File.exists?("/tmp/storage/test2.txt"))
66
+ assert_equal(true, File.exist?('/tmp/storage/test1.txt'))
67
+ assert_equal(true, File.exist?('/tmp/storage/test2.txt'))
70
68
 
71
- @fd.set_extension(".dat")
69
+ @fd.set_extension('.dat')
72
70
 
73
71
  @fd.hex_path(1)
74
- @fd.rename_from("/tmp/storage/test1.txt")
75
- assert_equal(true, File.exists?("/tmp/storage/01.dat"))
76
-
72
+ @fd.rename_from('/tmp/storage/test1.txt')
73
+ assert_equal(true, File.exist?('/tmp/storage/01.dat'))
74
+
77
75
  @fd.hex_path(256)
78
- @fd.rename_from("/tmp/storage/test2.txt")
79
- assert_equal(true, File.exists?("/tmp/storage/01/00.dat"))
80
- end
76
+ @fd.rename_from('/tmp/storage/test2.txt')
77
+ assert_equal(true, File.exist?('/tmp/storage/01/00.dat'))
78
+ end
81
79
 
82
80
  def teardown
83
- if File.exists?("/tmp/storage")
84
- FileUtils.rm_r("/tmp/storage")
85
- end
81
+ FileUtils.rm_r('/tmp/storage') unless File.exist?('/tmp/storage')
86
82
  end
87
- end
83
+ end
metadata CHANGED
@@ -1,65 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: file_distribution
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Adam Kubica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2015-04-13 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
19
20
  - - ">="
20
- - !ruby/object:Gem::Version
21
+ - !ruby/object:Gem::Version
21
22
  version: 10.0.0
22
23
  type: :development
23
- version_requirements: *id001
24
- description: Simple library that allows organize distribution of files within hex based tree.
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '10.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 10.0.0
33
+ description: Simple library that allows organize distribution of files within hex
34
+ based tree.
25
35
  email: caffecoder@kaizen-step.com
26
36
  executables: []
27
-
28
37
  extensions: []
29
-
30
38
  extra_rdoc_files: []
31
-
32
- files:
33
- - Rakefile
39
+ files:
34
40
  - LICENSE
41
+ - Rakefile
35
42
  - lib/file_distribution.rb
36
43
  - test/test_file_distribution.rb
37
44
  homepage: http://github.org/caffecoder/fdist-ruby
38
- licenses:
45
+ licenses:
39
46
  - MIT
40
47
  metadata: {}
41
-
42
48
  post_install_message:
43
- rdoc_options: []
44
-
45
- require_paths:
49
+ rdoc_options:
50
+ - "--charset=UTF-8"
51
+ require_paths:
46
52
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
48
- requirements:
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
49
55
  - - ">="
50
- - !ruby/object:Gem::Version
51
- version: 1.8.7
52
- required_rubygems_version: !ruby/object:Gem::Requirement
53
- requirements:
56
+ - !ruby/object:Gem::Version
57
+ version: 2.2.1
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
54
60
  - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
57
63
  requirements: []
58
-
59
64
  rubyforge_project:
60
- rubygems_version: 2.0.15
65
+ rubygems_version: 2.5.1
61
66
  signing_key:
62
67
  specification_version: 4
63
68
  summary: Simple file distribution library.
64
- test_files:
69
+ test_files:
65
70
  - test/test_file_distribution.rb