fast 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fast (0.1.2)
5
+ metafun (>= 0.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ metafun (0.2.0)
12
+ rspec (2.8.0)
13
+ rspec-core (~> 2.8.0)
14
+ rspec-expectations (~> 2.8.0)
15
+ rspec-mocks (~> 2.8.0)
16
+ rspec-core (2.8.0)
17
+ rspec-expectations (2.8.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.8.0)
20
+ zucker (12.1)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ fast!
27
+ rspec
28
+ zucker
@@ -1,18 +1,58 @@
1
1
  = Fast
2
2
 
3
- DSL for file handling focused in intuitivity and semantics.
3
+ Tired of having a hard time working with files? Take a look at Fast...
4
4
 
5
- Library is pure Ruby 1.8.7, no FileUtils nor other dependencies (except Metafun for DSL delegation)
5
+ require "fast"
6
+
7
+ lib_dir = dir! :lib
8
+
9
+ lib_dir["demo.txt"] = "I love creating files from a Hash-like API"
10
+
11
+ lib_dir.list # => ['demo.txt']
12
+
13
+ file! "lib/empty.txt"
14
+
15
+ lib_dir.files.each do |path|
16
+ puts path
17
+ end # => demo.txt
18
+ # empty.txt
19
+
20
+ lib_dir.destroy
21
+
22
+ dir? :lib # => false
23
+
24
+ ...and wait a few weeks because this is not stable yet ;)
25
+
26
+ Fast is a DSL for file and dir handling focused in intuitivity and semantics. Is pure Ruby (1.8.7+) with no dependencies, except for Metafun for the DSL.
6
27
 
7
28
  == Installation
8
29
 
9
30
  gem install fast
10
31
 
11
- Cucumber features still to do, but specs are stable (2011-12-11)
32
+ == Usage
33
+
34
+ Fast declares two sets of methods in its DSL:
35
+
36
+ === Dir methods
37
+
38
+ dir :lib # The same as => Fast::Dir.new "lib"
39
+ dir.delete! "demo" # The same as => Fast::Dir.new.delete! "demo"
40
+
41
+ dir! :new_dir # The same as => Fast::Dir.new.create! :new_dir
42
+ dir? :new_dir # The same as => Fast::Dir.new.exist? :new_dir
43
+
44
+ === File methods
45
+
46
+ file "demo.txt" # The same as => Fast::File.new "demo.txt"
47
+ file.copy "demo.txt", "new.txt" # The same as =>
48
+ # Fast::File.new.copy "demo.txt", "new.txt"
49
+
50
+ file! "demo.txt" # The same as => Fast::File.new.create! "demo.txt"
51
+ file? "demo.txt" # The same as => Fast::File.new.exist? "demo.txt"
12
52
 
13
53
  == Philosophy
14
54
 
15
- <tt>Fast</tt> embraces the more straightforward view of files as strings of data and directories as arrays of files/directories. Some reasons:
55
+ *Fast* embraces a more straightforward view of files as strings of data and directories as arrays of files/directories. Why?
16
56
 
17
57
  * It is more realistic in everyday usage
18
58
  * It makes them more object-like (and thus, more friendly to OOP)
@@ -22,8 +62,9 @@ Cucumber features still to do, but specs are stable (2011-12-11)
22
62
  <tt>Fast::Dir</tt> is a subclass of <tt>Array</tt>, usable as a hash, and <tt>Fast::File</tt> if a subclass of String.
23
63
 
24
64
  == Quick notes
65
+ * URGENT: Make fast depend of the last version of <tt>metafun</tt>
66
+ * Deliberate whether is a good idea to make Fast::Dir and Fast::File Multitons.
25
67
  * Read bytes as binary ASCII-8BIT always and then try to perform an heuristic conversion, if there is any reasonable way to do it. Otherwise, leave it to the user. Google: "ruby string encode utf-8 ascii" for some good readings.
26
- * Apply the SubSetter pattern for filtering instead of FileFilter and DirFilter ad described in http://xaviervia.com.ar/patterns/sub-setter
27
68
  * File lists as returned by Fast::Dir#list and Fast::Dir#dirs will be filtered after the list is retrieved by a set of filtering methods of the returned list, which should be an instance of Fast::Dir.
28
69
  * An instance of Fast::Dir should be possible to be created from a Array.
29
70
  * The path can be setted indirectly by any method of Fast::File instances, and the same works for Dir. This is fine because allows for very quick calls, but once an instance gets a path setted it should be fixed and raise an exception in case some other method call is trying to change it.
@@ -35,6 +76,6 @@ Cucumber features still to do, but specs are stable (2011-12-11)
35
76
 
36
77
  == License
37
78
 
38
- GPL License. Why else?
79
+ GPL License. Why other?
39
80
 
40
81
  @ Xavier Via
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.pattern = "./spec/**/*_spec.rb"
9
+ end
10
+
11
+ task :default => :spec
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "fast"
16
16
 
17
- s.add_dependency "metafun"
17
+ s.add_dependency "metafun", ">= 0.2.0"
18
18
 
19
19
  s.add_development_dependency "rspec"
20
20
  s.add_development_dependency "zucker"
@@ -1,9 +1,5 @@
1
1
  require "metafun/delegator"
2
2
 
3
- require "fast/file"
4
- require "fast/dir"
5
- require "fast/dir-filter"
6
- require "fast/file-filter"
7
3
  require "fast/fast"
8
4
 
9
5
  delegate Fast, :dir, :dir?, :dir!, :file, :file?, :file!
@@ -1,3 +1,5 @@
1
+ require "sub-setter/fast/dir" # This call should be automated in the sub-setter API somehow
2
+
1
3
  module Fast
2
4
  # Directory handling class
3
5
  class Dir < Array
@@ -90,10 +92,10 @@ module Fast
90
92
  end
91
93
  end
92
94
 
93
- alias :destroy :delete
94
- alias :del :delete
95
- alias :unlink :delete
96
- alias :remove :delete
95
+ alias :remove :delete
96
+ alias :destroy :delete
97
+ alias :del :delete
98
+ alias :unlink :delete
97
99
 
98
100
  # Like #delete, but raises no error if some directory is missing
99
101
  def delete! *args
@@ -116,7 +118,10 @@ module Fast
116
118
  end
117
119
  end
118
120
 
119
- alias :remove! :delete!
121
+ alias :remove! :delete!
122
+ alias :destroy! :delete!
123
+ alias :del! :delete!
124
+ alias :unlink! :delete!
120
125
 
121
126
  # Checks for existence. True if the directory exists, false otherwise
122
127
  def exist? path = nil
@@ -170,9 +175,9 @@ module Fast
170
175
  return "#{@path}"
171
176
  end
172
177
 
173
- # Sends self to a DirFilter filter
178
+ # Sends self to a SubSetter for Fast::Dir
174
179
  def filter
175
- DirFilter.new self
180
+ SubSetter::Fast::Dir.new self
176
181
  end
177
182
 
178
183
  alias :by :filter
@@ -205,6 +210,8 @@ module Fast
205
210
  do_rename_to target
206
211
  end
207
212
 
213
+ alias :move :rename
214
+
208
215
  # Renames this dir into the target path: overwrites the target dir
209
216
  # if it exists
210
217
  def rename! *args
@@ -219,6 +226,8 @@ module Fast
219
226
  do_rename_to target
220
227
  end
221
228
 
229
+ alias :move! :rename!
230
+
222
231
  # Merges the target dir into this
223
232
  def merge *args
224
233
  if args.length > 1
@@ -274,7 +283,15 @@ module Fast
274
283
  if name.is_a? Integer # I do not wish to disable Array behaviour
275
284
  super
276
285
  else
277
- return File.new.write "#{@path}/#{name}", content
286
+ if content.is_a? Hash
287
+ subdir = Dir.new.create! "#{@path}/#{name}"
288
+ content.each do |item_name, item_content|
289
+ subdir[item_name] = item_content
290
+ end
291
+ return subdir
292
+ else
293
+ return File.new.write "#{@path}/#{name}", content
294
+ end
278
295
  end
279
296
  end
280
297
 
@@ -1,3 +1,6 @@
1
+ require "fast/file"
2
+ require "fast/dir"
3
+
1
4
  module Fast
2
5
  # Returns a Dir with the file list already called (if a path is provided)
3
6
  def self.dir path = nil
@@ -1,3 +1,5 @@
1
+ require "sub-setter/fast/file" # This call should be automated in the sub-setter API somehow
2
+
1
3
  module Fast
2
4
  # File handling class.
3
5
  class File < String
@@ -67,9 +69,10 @@ module Fast
67
69
  end
68
70
  end
69
71
 
70
- alias :destroy :delete
71
- alias :unlink :delete
72
- alias :del :delete
72
+ alias :remove :delete
73
+ alias :destroy :delete
74
+ alias :del :delete
75
+ alias :unlink :delete
73
76
 
74
77
  # Deletes the file(s) if it exists, does nothing otherwise
75
78
  def delete! *args
@@ -86,6 +89,11 @@ module Fast
86
89
  end
87
90
  end
88
91
 
92
+ alias :remove! :delete!
93
+ alias :destroy! :delete!
94
+ alias :del! :delete!
95
+ alias :unlink! :delete!
96
+
89
97
  # Touches the file passed. Like bash `touch`, but creates
90
98
  # all required directories if they don't exist
91
99
  def touch *args
@@ -150,9 +158,9 @@ module Fast
150
158
  return_list
151
159
  end
152
160
 
153
- # Sends self to a FileFilter filter
161
+ # Sends self to a SubSetter for Fast::File
154
162
  def filter
155
- FileFilter.new self
163
+ SubSetter::Fast::File.new self
156
164
  end
157
165
 
158
166
  alias :by :filter
@@ -180,6 +188,8 @@ module Fast
180
188
  self.delete!
181
189
  return renamed
182
190
  end
191
+
192
+ alias :move :rename
183
193
 
184
194
  # Like #rename, but overwrites the new file if is exist
185
195
  def rename! *args
@@ -195,6 +205,8 @@ module Fast
195
205
  return renamed
196
206
  end
197
207
 
208
+ alias :move! :rename!
209
+
198
210
  # Returns the path to the current file
199
211
  def path
200
212
  @path if @path
@@ -1,3 +1,3 @@
1
1
  module Fast
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,35 @@
1
+ module SubSetter
2
+ module Fast
3
+ # Specific subsetter for Dir entries. Should inherit or invoke the SubSetter::Array
4
+ # Just a stub for the moment
5
+ class Dir
6
+ def initialize set
7
+ @set = set
8
+ end
9
+
10
+ def extension the_extension
11
+ return_me = ::Fast::Dir.new
12
+ @set.each do |entry|
13
+ return_me << entry if entry.end_with? the_extension
14
+ end
15
+ return_me
16
+ end
17
+
18
+ def strip_extension
19
+ return_me = ::Fast::Dir.new
20
+ @set.each do |entry|
21
+ return_me.push entry.gsub /\.(\w+?)$/, ""
22
+ end
23
+ return_me
24
+ end
25
+
26
+ def match regexp
27
+ return_me = ::Fast::Dir.new
28
+ @set.each do |entry|
29
+ return_me << entry if entry.match regexp
30
+ end
31
+ return_me
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ module SubSetter
2
+ module Fast
3
+ # Specific subsetter for File entries. Should inherit or invoke a Generic Filter
4
+ # Just a stub for the moment
5
+ class File
6
+ def initialize set
7
+ @set = set
8
+ end
9
+ end
10
+ end
11
+ end
@@ -2,6 +2,13 @@ require "fast"
2
2
  require "zucker/os"
3
3
 
4
4
  describe Fast::Dir do
5
+
6
+ context "a Fast::Dir is passed as argument where a path is accepted" do
7
+ it "should be accepted"
8
+
9
+ it "should I really think of a common denominator of Fast::Dir and Fast::File?"
10
+ end
11
+
5
12
  shared_examples_for "any dir list" do
6
13
  context "a block is passed as an argument" do
7
14
  it "should pass each entry as argument to the block" do
@@ -213,17 +220,13 @@ describe Fast::Dir do
213
220
  end
214
221
 
215
222
  shared_examples_for "any dir subsetter" do
216
- # This is a reminder: along with Serializer, the Subsette pattern
217
- # (and later, the Sorting one) should be implemented Fast
218
-
219
- # I guess filtering in Fast will be done in Fast::DirFilter
220
- it "should forward self to a filtering object" do
223
+ it "should forward self to a subsetter object" do
221
224
  Fast::Dir.new.should_not exist "demo"
222
225
  Fast::File.new.touch "demo/in/subdir.file"
223
226
 
224
227
  the_demo_dir = Fast::Dir.new :demo
225
228
 
226
- Fast::DirFilter.should_receive( :new ).with the_demo_dir
229
+ SubSetter::Fast::Dir.should_receive( :new ).with the_demo_dir
227
230
 
228
231
  the_demo_dir.by
229
232
 
@@ -317,6 +320,16 @@ describe Fast::Dir do
317
320
  }.to raise_error
318
321
  end
319
322
  end
323
+
324
+ describe "#del!" do
325
+ before :each do @method = :del! end
326
+ it_behaves_like "any dir deletion"
327
+
328
+ it "should not fail even if the directory does not exist" do
329
+ Fast::Dir.new.should_not exist :demo
330
+ Fast::Dir.new.del! :demo
331
+ end
332
+ end
320
333
 
321
334
  describe "#destroy" do
322
335
  before :each do @method = :destroy end
@@ -327,6 +340,16 @@ describe Fast::Dir do
327
340
  }.to raise_error
328
341
  end
329
342
  end
343
+
344
+ describe "#destroy!" do
345
+ before :each do @method = :destroy! end
346
+ it_behaves_like "any dir deletion"
347
+
348
+ it "should not fail even if the directory does not exist" do
349
+ Fast::Dir.new.should_not exist :demo
350
+ Fast::Dir.new.destroy! :demo
351
+ end
352
+ end
330
353
 
331
354
  describe "#unlink" do
332
355
  before :each do @method = :unlink end
@@ -339,6 +362,16 @@ describe Fast::Dir do
339
362
  end
340
363
  end
341
364
 
365
+ describe "#unlink!" do
366
+ before :each do @method = :delete! end
367
+ it_behaves_like "any dir deletion"
368
+
369
+ it "should not fail even if the directory does not exist" do
370
+ Fast::Dir.new.should_not exist :demo
371
+ Fast::Dir.new.unlink! :demo
372
+ end
373
+ end
374
+
342
375
  describe "#remove" do
343
376
  before :each do @method = :remove end
344
377
  it_behaves_like "any dir deletion"
@@ -585,6 +618,40 @@ describe Fast::Dir do
585
618
  end
586
619
  end
587
620
 
621
+
622
+ describe "#move" do
623
+ before :all do @method = :move end
624
+ it_behaves_like "any dir renaming"
625
+
626
+ it "should fail if the new path represents an existing dir" do
627
+ Fast::Dir.new.should_not exist :demo
628
+ Fast::Dir.new.should_not exist :renamed
629
+ Fast::Dir.new.create! :demo
630
+ Fast::Dir.new.create! :renamed
631
+ expect { Fast::Dir.new.move :demo, :renamed
632
+ }.to raise_error ArgumentError, "The target directory 'renamed' already exists"
633
+ Fast::Dir.new.delete! :demo
634
+ Fast::Dir.new.delete! :renamed
635
+ end
636
+ end
637
+
638
+ describe "#move!" do
639
+ before :all do @method = :move! end
640
+ it_behaves_like "any dir renaming"
641
+
642
+ it "should overwrite the dir at the new path if it exists" do
643
+ Fast::Dir.new.should_not exist :demo
644
+ Fast::Dir.new.should_not exist :renamed
645
+ Fast::File.new.touch "demo/content.file"
646
+ Fast::File.new.touch "renamed/erase.me"
647
+
648
+ Fast::Dir.new.move! :demo, :renamed
649
+ Fast::File.new.should_not exist "renamed/erase.me"
650
+ Fast::File.new.should exist "renamed/content.file"
651
+ Fast::Dir.new.delete! :renamed
652
+ end
653
+ end
654
+
588
655
  shared_examples_for "any dir copy" do
589
656
  before :each do
590
657
  Fast::Dir.new.should_not exist :demo
@@ -728,6 +795,7 @@ describe Fast::Dir do
728
795
  Fast::File.new.touch "demo/file.txt"
729
796
 
730
797
  the_file = Fast::Dir.new(:demo)["file.txt"]
798
+ the_file.should be_a Fast::File
731
799
  the_file.path.should == "demo/file.txt"
732
800
  end
733
801
  end
@@ -740,7 +808,7 @@ describe Fast::Dir do
740
808
  end
741
809
  end
742
810
 
743
- context "an integet is sent" do
811
+ context "an integer is sent" do
744
812
  it "should behave like an array" do
745
813
  Fast::File.new.touch "demo/file.txt"
746
814
 
@@ -780,14 +848,52 @@ describe Fast::Dir do
780
848
  end
781
849
 
782
850
  context "the content is a hash" do
783
- it "should create the subdir"
851
+ it "should create the subdir" do
852
+ the_dir = Fast::Dir.new :demo
853
+ the_dir[:subdir] = {}
854
+ Fast::Dir.new.should exist "demo/subdir"
855
+ end
856
+
857
+ it "should create files for each key pointing to a String" do
858
+ the_dir = Fast::Dir.new :demo
859
+ the_dir[:subdir] = {
860
+ "file.txt" => "The demo contents are awesome",
861
+ "other.data" => "10101010001100011" }
862
+ Fast::File.new.read( "demo/subdir/file.txt" ).should include "The demo contents are awesome"
863
+ Fast::File.new.read( "demo/subdir/other.data" ).should include "10101010001100011"
864
+ end
865
+
866
+ it "should created directories for each key pointing to a Hash" do
867
+ the_dir = Fast::Dir.new :demo
868
+ the_dir[:subdir] = {
869
+ :subsub => {},
870
+ :data => {}
871
+ }
872
+ Fast::Dir.new.should exist "demo/subdir/subsub"
873
+ Fast::Dir.new.should exist "demo/subdir/data"
874
+ end
784
875
 
785
- it "should create recursively the tree"
876
+ it "should create recursively the tree" do
877
+ the_dir = Fast::Dir.new :demo
878
+
879
+ the_dir[:subdir] = {
880
+
881
+ :subsub => {
882
+ :data => {},
883
+ "other.txt" => "More than this"
884
+ },
885
+
886
+ "demo.txt" => "Some file content"
887
+ }
888
+
889
+ Fast::Dir.new.should exist "demo/subdir/subsub/data"
890
+ Fast::File.new.read("demo/subdir/subsub/other.txt").should include "More than this"
891
+ Fast::File.new.read("demo/subdir/demo.txt").should include "Some file content"
892
+ end
786
893
  end
787
894
 
788
895
  after :each do
789
896
  Fast::Dir.new.delete! :demo
790
897
  end
791
898
  end
792
-
793
899
  end
@@ -6,6 +6,10 @@ require "zucker/os"
6
6
 
7
7
  describe Fast::File do
8
8
 
9
+ context "a Fast::File is passed as argument where a path is accepted" do
10
+ it "should be accepted"
11
+ end
12
+
9
13
  shared_examples_for "any file content appending" do
10
14
  it "should create the file if it does not exist" do
11
15
  ::File.should_not exist "demo.txt"
@@ -178,17 +182,66 @@ describe Fast::File do
178
182
  before :each do @method = :unlink end
179
183
  it_behaves_like "any file deletion"
180
184
  end
185
+
186
+ describe "#unlink!" do
187
+ before :each do @method = :unlink! end
188
+ it_behaves_like "any file deletion"
189
+
190
+ it "should not fail if the file does not exist" do
191
+ Fast::File.new.should_not exist "the_file.txt"
192
+ expect { Fast::File.new.unlink! "the_file.txt"
193
+ }.to_not raise_error
194
+ end
195
+ end
181
196
 
182
197
  describe "#del" do
183
198
  before :each do @method = :del end
184
199
  it_behaves_like "any file deletion"
185
200
  end
186
201
 
202
+ describe "#del!" do
203
+ before :each do @method = :del! end
204
+ it_behaves_like "any file deletion"
205
+
206
+ it "should not fail if the file does not exist" do
207
+ Fast::File.new.should_not exist "the_file.txt"
208
+ expect { Fast::File.new.del! "the_file.txt"
209
+ }.to_not raise_error
210
+ end
211
+ end
212
+
187
213
  describe "#destroy" do
188
214
  before :each do @method = :destroy end
189
215
  it_behaves_like "any file deletion"
190
216
  end
191
-
217
+
218
+ describe "#destroy!" do
219
+ before :each do @method = :destroy! end
220
+ it_behaves_like "any file deletion"
221
+
222
+ it "should not fail if the file does not exist" do
223
+ Fast::File.new.should_not exist "the_file.txt"
224
+ expect { Fast::File.new.destroy! "the_file.txt"
225
+ }.to_not raise_error
226
+ end
227
+ end
228
+
229
+ describe "#remove" do
230
+ before :each do @method = :remove end
231
+ it_behaves_like "any file deletion"
232
+ end
233
+
234
+ describe "#remove!" do
235
+ before :each do @method = :remove! end
236
+ it_behaves_like "any file deletion"
237
+
238
+ it "should not fail if the file does not exist" do
239
+ Fast::File.new.should_not exist "the_file.txt"
240
+ expect { Fast::File.new.remove! "the_file.txt"
241
+ }.to_not raise_error
242
+ end
243
+ end
244
+
192
245
  shared_examples_for "any file creation" do
193
246
  context "in current folder" do
194
247
  it "should create the file if it does not exist" do
@@ -471,16 +524,10 @@ describe Fast::File do
471
524
  end
472
525
 
473
526
  shared_examples_for "any file subsetter" do
474
- # This should follow more precisely the SubSetter pattern as specified
475
- # on http://xaviervia.com.ar/patterns/sub-setter
476
- #
477
- # This is a reminder: along with Serializer, the Subsetter pattern
478
- # (and later, the Sorting one) should be implemented Fast
479
- #
480
- # Fast::FileFilter will be deprecated soon
527
+ # SubSetter as described in http://xaviervia.com.ar/patterns/sub-setter
481
528
  it "should forward self to a filtering object" do
482
529
  the_demo_file = Fast::File.new :demo
483
- Fast::FileFilter.should_receive( :new ).with the_demo_file
530
+ SubSetter::Fast::File.should_receive( :new ).with the_demo_file
484
531
  the_demo_file.by
485
532
  end
486
533
  end
@@ -600,6 +647,43 @@ describe Fast::File do
600
647
  end
601
648
  end
602
649
 
650
+ describe "#move" do
651
+ before :all do @method = :move end
652
+ it_behaves_like "any file renaming"
653
+
654
+ it "should fail if a file named as the new name exists" do
655
+ Fast::File.new.should_not exist "demo.file"
656
+ Fast::File.new.should_not exist "renamed.file"
657
+ Fast::File.new.touch "renamed.file"
658
+ Fast::File.new.write "demo.file", "Demo content bores me"
659
+
660
+ expect { Fast::File.new.move "demo.file", "renamed.file"
661
+ }.to raise_error ArgumentError, "The file 'renamed.file' already exists"
662
+
663
+ Fast::File.new.delete! "demo.file"
664
+ Fast::File.new.delete! "renamed.file"
665
+ end
666
+ end
667
+
668
+ describe "#move!" do
669
+ before :all do @method = :move! end
670
+ it_behaves_like "any file renaming"
671
+
672
+ it "should overwrite the new file if it exists" do
673
+ Fast::File.new.should_not exist "demo.file"
674
+ Fast::File.new.should_not exist "renamed.file"
675
+ Fast::File.new.touch "renamed.file"
676
+ Fast::File.new.write "demo.file", "Demo content bores me"
677
+
678
+ Fast::File.new.move! "demo.file", "renamed.file"
679
+
680
+ Fast::File.new.should_not exist "demo.file"
681
+ Fast::File.new.read( "renamed.file" ).should == "Demo content bores me"
682
+
683
+ Fast::File.new.delete! "renamed.file"
684
+ end
685
+ end
686
+
603
687
  describe "#merge" do
604
688
  before :each do
605
689
  Fast::File.new.should_not exist "demo.txt"
@@ -1,12 +1,12 @@
1
1
  require "fast"
2
2
  require "zucker/os"
3
3
 
4
- describe Fast::DirFilter do
4
+ describe SubSetter::Fast::Dir do
5
5
  describe "#extension" do
6
6
  context "when given a list of file names and a extension" do
7
7
  it "should return a Dir of the files with the given extension" do
8
8
  list = ["file.txt", "data.txt", "thumbs.db", "data.txt.jpg"]
9
- final_list = Fast::DirFilter.new( list ).extension "txt"
9
+ final_list = SubSetter::Fast::Dir.new( list ).extension "txt"
10
10
  final_list.should be_a Fast::Dir
11
11
  final_list.should include "file.txt"
12
12
  final_list.should include "data.txt"
@@ -19,7 +19,7 @@ describe Fast::DirFilter do
19
19
  describe "#strip_extension" do
20
20
  it "should return a Dir with the files names without extension" do
21
21
  list = ["file.txt", "data.txt", "thumbs.db", "data.txt.jpg", "noext"]
22
- final_list = Fast::DirFilter.new( list ).strip_extension
22
+ final_list = SubSetter::Fast::Dir.new( list ).strip_extension
23
23
  final_list.should be_a Fast::Dir
24
24
  final_list.should include "file"
25
25
  final_list.should include "data"
@@ -28,18 +28,12 @@ describe Fast::DirFilter do
28
28
  final_list.should include "noext"
29
29
  end
30
30
  end
31
-
32
- # VERY IMPORTANT: DirFilter should extend a class ListFilter
33
- # #match implementation (along with a short list of other things) should
34
- # be done in ListFilter, not in DirFilter
35
- #
36
- # The SubSetter pattern is still not defined nor implemented: I'll start by
37
- # finishing Fast and after that I'll dig deeper into SubSetting
31
+
38
32
  describe "#match" do
39
33
  context "when given a list of strings and a regexp" do
40
34
  it "should return a Dir containing the strings that match the expression" do
41
35
  list = %w{is_a_file think_of_me not_my_file filesystem see_file_you}
42
- final_list = Fast::DirFilter.new( list ).match /file/
36
+ final_list = SubSetter::Fast::Dir.new( list ).match /file/
43
37
  final_list.should be_a Fast::Dir
44
38
  final_list.should include "is_a_file"
45
39
  final_list.should include "not_my_file"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-14 00:00:00.000000000 Z
12
+ date: 2012-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metafun
16
- requirement: &76535500 !ruby/object:Gem::Requirement
16
+ requirement: &76004770 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76535500
24
+ version_requirements: *76004770
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &76534920 !ruby/object:Gem::Requirement
27
+ requirement: &76004410 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *76534920
35
+ version_requirements: *76004410
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: zucker
38
- requirement: &76534240 !ruby/object:Gem::Requirement
38
+ requirement: &76004040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *76534240
46
+ version_requirements: *76004040
47
47
  description: DSL for file system interaction
48
48
  email:
49
49
  - xavierviacanel@gmail.com
@@ -52,21 +52,23 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
  files:
54
54
  - .gitignore
55
+ - .rvmrc
55
56
  - Gemfile
57
+ - Gemfile.lock
56
58
  - README.rdoc
57
59
  - Rakefile
58
60
  - fast.gemspec
59
61
  - lib/fast.rb
60
- - lib/fast/dir-filter.rb
61
62
  - lib/fast/dir.rb
62
63
  - lib/fast/fast.rb
63
- - lib/fast/file-filter.rb
64
64
  - lib/fast/file.rb
65
65
  - lib/fast/version.rb
66
- - spec/fast/dir-filter_spec.rb
66
+ - lib/sub-setter/fast/dir.rb
67
+ - lib/sub-setter/fast/file.rb
67
68
  - spec/fast/dir_spec.rb
68
69
  - spec/fast/fast_spec.rb
69
70
  - spec/fast/file_spec.rb
71
+ - spec/sub-setter/fast/dir_spec.rb
70
72
  homepage: ''
71
73
  licenses: []
72
74
  post_install_message:
@@ -87,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
89
  version: '0'
88
90
  requirements: []
89
91
  rubyforge_project: fast
90
- rubygems_version: 1.8.10
92
+ rubygems_version: 1.8.15
91
93
  signing_key:
92
94
  specification_version: 3
93
95
  summary: DSL for file system interaction
@@ -1,33 +0,0 @@
1
- module Fast
2
- # Specific filter for Dir entries. Should inherit or invoke a Generic Filter
3
- # Just a stub for the moment
4
- class DirFilter
5
- def initialize set
6
- @set = set
7
- end
8
-
9
- def extension the_extension
10
- return_me = Dir.new
11
- @set.each do |entry|
12
- return_me << entry if entry.end_with? the_extension
13
- end
14
- return_me
15
- end
16
-
17
- def strip_extension
18
- return_me = Dir.new
19
- @set.each do |entry|
20
- return_me.push entry.gsub /\.(\w+?)$/, ""
21
- end
22
- return_me
23
- end
24
-
25
- def match regexp
26
- return_me = Dir.new
27
- @set.each do |entry|
28
- return_me << entry if entry.match regexp
29
- end
30
- return_me
31
- end
32
- end
33
- end
@@ -1,9 +0,0 @@
1
- module Fast
2
- # Specific filter for File entries. Should inherit or invoke a Generic Filter
3
- # Just a stub for the moment
4
- class FileFilter
5
- def initialize set
6
- @set = set
7
- end
8
- end
9
- end