imw 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.9
@@ -367,6 +367,15 @@ module IMW
367
367
  IMW.open(File.join(stripped_uri.to_s, *paths))
368
368
  end
369
369
 
370
+ # Open (and create if necessary) a subdirectory beneath this
371
+ # directory.
372
+ #
373
+ # @params [Array<String>] paths
374
+ # @return [IMW::Resource]
375
+ def subdir! *paths
376
+ IMW.dir!(File.join(stripped_uri.to_s, *paths))
377
+ end
378
+
370
379
  # Recursively walk down this directory
371
380
  def walk(options={}, &block)
372
381
  require 'find'
data/lib/imw.rb CHANGED
@@ -72,6 +72,29 @@ module IMW
72
72
  end
73
73
  end
74
74
 
75
+ # Open (and create if necessary) a directory at the given URI.
76
+ #
77
+ # Will automatically create directories recursively. Options will
78
+ # be passed to IMW.open and interpreted appropriately. If a block
79
+ # is passed, the directory will be created before the block is
80
+ # yielded to.
81
+ #
82
+ # @param [String, IMW::Resource] uri
83
+ # @param [Hash] options
84
+ # @return [IMW::Resource]
85
+ def self.dir! uri, options={}, &block
86
+ if block_given?
87
+ new_dir = open(uri, options.merge(:as => (options[:as] || []) + [Schemes::Local::LocalDirectory])) do |d|
88
+ new_dir.create
89
+ yield
90
+ end
91
+ else
92
+ new_dir = open(uri, options.merge(:as => (options[:as] || []) + [Schemes::Local::LocalDirectory]))
93
+ new_dir.create
94
+ end
95
+ new_dir
96
+ end
97
+
75
98
  # Works the same way as IMW.open except opens the resource for
76
99
  # writing.
77
100
  #
@@ -156,6 +156,13 @@ describe IMW::Schemes::Local::LocalDirectory do
156
156
  @dir.join("a", "b/c").to_s.should == File.join(@dir.path, 'a/b/c')
157
157
  end
158
158
 
159
+ it "can create a subdirectory" do
160
+ @dir.join("mallaco").exist?.should be_false
161
+ subdir = @dir.subdir!("mallaco")
162
+ subdir.exist?.should be_true
163
+ subdir.directory?.should be_true
164
+ end
165
+
159
166
  describe 'can package itself to' do
160
167
  ['tar', 'tar.bz2', 'tar.gz', 'zip', 'rar'].each do |extension|
161
168
  it "a #{extension} archive" do
data/spec/imw_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe IMW do
4
+
5
+ # FIXME
6
+
7
+ describe 'when opening files' do
8
+ end
9
+
10
+ describe 'when opening directories' do
11
+ end
12
+
13
+ end
14
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dhruv Bansal
@@ -171,6 +171,7 @@ files:
171
171
  - spec/imw/utils/has_uri_spec.rb
172
172
  - spec/imw/utils/paths_spec.rb
173
173
  - spec/imw/utils/shared_paths_spec.rb
174
+ - spec/imw_spec.rb
174
175
  - spec/rcov.opts
175
176
  - spec/spec_helper.rb
176
177
  - spec/support/custom_matchers.rb
@@ -249,6 +250,7 @@ test_files:
249
250
  - spec/imw/utils/paths_spec.rb
250
251
  - spec/imw/utils/dynamically_extendable_spec.rb
251
252
  - spec/imw/utils/shared_paths_spec.rb
253
+ - spec/imw_spec.rb
252
254
  - spec/spec_helper.rb
253
255
  - spec/support/without_regard_to_order_matcher.rb
254
256
  - spec/support/custom_matchers.rb