multi_dir 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce861e1b857ef81a8a7b636fefca4baefe2a05bc
4
- data.tar.gz: e382dcb44de085b9ebcffedc2a4916aaf4949782
3
+ metadata.gz: 0a661f08fe1eebf8f311f6fffa0d225eef0c8a24
4
+ data.tar.gz: c07c917317858364e294a62f344ff15e60fd7374
5
5
  SHA512:
6
- metadata.gz: 8a82b06f595a738d2a4bd493536f76b1260fc72251ef8e8690b1f52dc8aec26553ac0856a02e62989f8382cad47fc7e3de54c94149edcbc1dc99c71a7a68578c
7
- data.tar.gz: 79eecdaa711d5edfeb68a15941e52f82719749c56c4777ebd159fcd2040057485f590d127c1a5186f37815a73b2c7107d55adc1736083627829589b5a2ecf4be
6
+ metadata.gz: fe67c221549fdda941a9d4ba22995e41144863c4bf693be865f81c943f779497995af203ff2d25fa1db3cca12ae8ebba15bb81b5a1a9851bc6444c83ec343323
7
+ data.tar.gz: f91ce4c2dfa26cd2fd42f9215c855f588b0b2ecc666cfa714f697a0fdb07c7319aee15a20a9242f858670673ec2480b7e4e8e5bbcd978c85ff1d7ee779465348
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ### 0.2.0
4
+
5
+ * Add Pathname#tempname
6
+
7
+ ### 0.1.0
8
+
9
+ * Add Pathname#glob and Pathname#[] patch
10
+ * Multiple configuration support
11
+ * Symbolic path resolving
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # MultiDir
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/multi_dir.png)](http://badge.fury.io/rb/multi_dir)
3
4
  [![Build Status](https://travis-ci.org/jgraichen/multi_dir.png?branch=master)](https://travis-ci.org/jgraichen/multi_dir)
5
+ [![Coverage Status](https://coveralls.io/repos/jgraichen/multi_dir/badge.png?branch=master)](https://coveralls.io/r/jgraichen/multi_dir?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/jgraichen/multi_dir.png)](https://codeclimate.com/github/jgraichen/multi_dir)
7
+ [![Dependency Status](https://gemnasium.com/jgraichen/multi_dir.png)](https://gemnasium.com/jgraichen/multi_dir)
4
8
 
5
9
  **MultiDir** allow libraries and frameworks to request paths in a semantic
6
10
  way. This allows administrators to define real paths in one global
@@ -10,7 +14,7 @@ No more `Rails.root.join *%w(tmp uploaded)` anymore. Give administrators the
10
14
  freedom to link the temp directory to `/tmp/myapp` or any other system
11
15
  specific place by just using `MultiDir.tmp.join 'uploaded'`.
12
16
 
13
- *Note: MultiDir as a library is still under development but the concept sounds nice.*
17
+ *Note:* ***MultiDir*** *as a library is still under development but the concept sounds nice.*
14
18
 
15
19
  ## Installation
16
20
 
@@ -30,7 +34,7 @@ Or install it yourself as:
30
34
 
31
35
  ### For All
32
36
 
33
- MultiDir allows to define any semantic path your app, library or framework may
37
+ **MultiDir** allows to define any semantic path your app, library or framework may
34
38
  need. By default the following paths are specified:
35
39
 
36
40
  ```
@@ -78,12 +82,13 @@ See the following examples:
78
82
  MultiDir.cache.join *%(pdfgen page5.pdf) # => "cache/pdfgen/page5.pdf"
79
83
 
80
84
  # Request a file with a temporary name
81
- MultiDir.tmp.temp_file ['basename', '.jpg'] # => "tmp/basename74hf4727f834.jpg"
85
+ MultiDir.tmp.tempname ['basename', '.jpg'] # => "tmp/basename20130519-11982-tzda0r.jpg"
82
86
 
83
87
  # Get list of files in a additional configurable directory
84
- MultiDir.cache[:uploads].glob '**/*.zip' # This allows admins to configure a special path for :uploads
85
- # that if not given will be placed in 'cache'.
86
- # => ["/media/uploads/a/virus.zip", "/media/uploads/attachments/ppt.zip"]
88
+ MultiDir.cache[:uploads].glob 'path/**', '*.zip' # This allows admins to
89
+ # configure a special path for :uploads
90
+ # that if not given will be placed in 'cache'.
91
+ # => ["/media/uploads/a/virus.zip", "/media/uploads/attachments/ppt.zip"]
87
92
  ```
88
93
 
89
94
  You can even define your own new top level *semantic path*:
@@ -5,8 +5,8 @@ module MultiDir
5
5
  #
6
6
  module PathnamePatch
7
7
 
8
- def glob(pattern)
9
- Dir.glob File.join(to_s, pattern)
8
+ def glob(*patterns)
9
+ Dir.glob File.join(to_s, *patterns)
10
10
  end
11
11
 
12
12
  def [](path)
@@ -16,6 +16,26 @@ module MultiDir
16
16
 
17
17
  join path.to_s
18
18
  end
19
+
20
+ def tempname(prefix_suffix, n = nil)
21
+ join mktmpname prefix_suffix, n
22
+ end
23
+
24
+ private
25
+ def mktmpname(prefix_suffix, n = nil)
26
+ case prefix_suffix
27
+ when Array
28
+ prefix = prefix_suffix[0].to_s
29
+ suffix = prefix_suffix[1].to_s
30
+ else
31
+ prefix = prefix_suffix.to_s
32
+ end
33
+ t = Time.now.strftime("%Y%m%d")
34
+ path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}"
35
+ path << "-#{n}" if n
36
+ path << suffix if suffix
37
+ path
38
+ end
19
39
  end
20
40
 
21
41
  ::Pathname.send :include, PathnamePatch
@@ -1,7 +1,7 @@
1
1
  module MultiDir
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiDir::PathnamePatch do
4
+ before { MultiDir::Paths.load_yaml 'spec/support/multi_dir.yml' }
5
+
6
+ describe '#[]' do
7
+ context 'with not configured semantic path' do
8
+ it 'should return joined path' do
9
+ expect( MultiDir.tmp[:not_configured_sym].to_s ).to be == '/tmp/myapp/not_configured_sym'
10
+ end
11
+ end
12
+
13
+ context 'with configured semantic path' do
14
+ it 'should return configured path' do
15
+ expect( MultiDir.tmp[:uploads].to_s ).to be == '/mnt/nfs/storage0/files'
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#glob' do
21
+ it 'should glob directory with joined pattern' do
22
+ Dir.should_receive(:glob).with('/tmp/myapp/path/**/*.rb').and_return(%w(a.rb b.rb))
23
+
24
+ expect( MultiDir.tmp.glob 'path', '**', '*.rb' ).to be == %w(a.rb b.rb)
25
+ end
26
+ end
27
+
28
+ describe '#tempname' do
29
+ it 'should create temp name on path' do
30
+ expect( MultiDir.tmp.tempname(%w(abc .jpg)).to_s ).to be =~ /\A\/tmp\/myapp\/abc\d+-\d+-\w+\.jpg\z/
31
+ end
32
+ end
33
+ end
@@ -52,7 +52,7 @@ describe MultiDir::Paths do
52
52
  end
53
53
  end
54
54
 
55
- describe '#resovle_root' do
55
+ describe '#resolve_root' do
56
56
  context 'with configure root path' do
57
57
  let(:config) { { :root => '/var/app/root' } }
58
58
 
@@ -1,9 +1,10 @@
1
- require 'multi_dir'
2
1
  require 'coveralls'
3
2
  Coveralls.wear! do
4
3
  add_filter 'spec'
5
4
  end
6
5
 
6
+ require 'multi_dir'
7
+
7
8
  Dir[File.expand_path('spec/support/**/*.rb')].each {|f| require f}
8
9
 
9
10
  RSpec.configure do |config|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_dir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-18 00:00:00.000000000 Z
11
+ date: 2013-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -90,6 +90,7 @@ extra_rdoc_files: []
90
90
  files:
91
91
  - .gitignore
92
92
  - .travis.yml
93
+ - CHANGELOG.md
93
94
  - Gemfile
94
95
  - LICENSE.txt
95
96
  - README.md
@@ -99,6 +100,7 @@ files:
99
100
  - lib/multi_dir/paths.rb
100
101
  - lib/multi_dir/version.rb
101
102
  - multi_dir.gemspec
103
+ - spec/multi_dir/pathname_patch_spec.rb
102
104
  - spec/multi_dir/paths_spec.rb
103
105
  - spec/multi_dir_spec.rb
104
106
  - spec/spec_helper.rb
@@ -130,6 +132,7 @@ specification_version: 4
130
132
  summary: Library for semantic path configuration to make developers and operators
131
133
  happy.
132
134
  test_files:
135
+ - spec/multi_dir/pathname_patch_spec.rb
133
136
  - spec/multi_dir/paths_spec.rb
134
137
  - spec/multi_dir_spec.rb
135
138
  - spec/spec_helper.rb