tagen 0.2.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *~
2
2
  /.yardoc
3
+ /tags
data/README.md CHANGED
@@ -15,7 +15,7 @@ Ruby has an 'Open Class' feature, so we can extend any class by ourself.
15
15
 
16
16
  This library provides some usefull Ruby core extension. some comes from ActiveSupport. ActiveSupport is mainly target to Rails, but tagen is target to generic ruby development, and tagen is smaller. It is a colletion of most common core,extra extensions.
17
17
 
18
- This library comes with a path lib named {Pa} and a string format lib named {PyFormat}.
18
+ This library comes with a string format lib named {PyFormat}.
19
19
 
20
20
  Usage
21
21
  -----
@@ -41,31 +41,13 @@ Requirements
41
41
 
42
42
  tested: ruby1.9 linux
43
43
 
44
- An Introduction to Pa
45
- ---------------------
46
-
47
- require "tagen/core"
48
- pa = Pa('/home/foo')
49
- pa.exists? #=> false
50
- pa.dir #=> '/home'
51
- pa.base #=> 'foo'
52
- pa.join('a.ogg') #=> '/home/a.ogg'
53
- pa.join(a.ogg).exists? #=> true.
54
-
55
- Pa.exists?('/home/foo') # alternate way
56
-
57
- which rspec
58
-
59
- Pa('/home/foo').should be_exists
60
-
61
- more see API doc
62
44
 
63
45
  An Introduction to PyFormat
64
46
  ---------------------------
65
47
 
66
48
  require "tagen/core"
67
49
  "I like %{fruit} and %{sport}".format('apple', 'football')
68
- "I like %{fruit} and %{sport}".format(apple: 'apple', footbal: 'football')
50
+ "I like %{fruit} and %{sport}".format(fruit: 'apple', sport: 'football')
69
51
 
70
52
  "it costs %{howmatch:.2f} dollars".format(1.123) #=> "it costs 1.12 dollars"
71
53
 
@@ -74,6 +56,7 @@ more see API doc
74
56
 
75
57
  Documentation
76
58
  -------------
59
+
77
60
  * {file:docs/CoreExtensions.md CoreExtensions} A list of core extensions.
78
61
  * {file:docs/ExtraExtensions.md ExtraExtensions} A list of extra extensions.
79
62
  * {file:docs/Architecture.md Architecture} Source code architecture.
@@ -84,14 +67,21 @@ Install
84
67
 
85
68
  Contributing
86
69
  -------------
70
+
87
71
  * report bugs/featues to issue tracker.
88
72
  * fork it and pull a request.
89
73
  * improve documentation.
90
- * any ideas are welcome.
74
+ * feel free to post any ideas.
91
75
 
92
76
  Contributors
93
77
  ------------
94
78
 
79
+ WORD-III
80
+
81
+
95
82
  Copyright
96
83
  ---------
97
84
  Copyright © 2011 by Guten. this library released under MIT-License, See {file:LICENSE} for futher details.
85
+
86
+ asddf
87
+ asdf
data/Rakefile CHANGED
@@ -6,6 +6,14 @@ task :release do
6
6
  sh "rm *.gem"
7
7
  end
8
8
 
9
+ desc "install a gem"
10
+ task :install do
11
+ `rm *.gem &>/dev/null`
12
+ sh "gem build tagen.gemspec"
13
+ sh "gem install *.gem"
14
+ sh "rm *.gem"
15
+ end
16
+
9
17
  desc "autotest with watchr"
10
18
  task :test do
11
19
  sh "watchr tagen.watchr"
@@ -1,4 +1,3 @@
1
- require "rmagic"
2
1
  =begin
3
2
  * **gem**: rmagic
4
3
  =end
@@ -45,7 +45,9 @@ new(data={})
45
45
  data's key can be string or symbol, but internal store key is use symbol.
46
46
 
47
47
  data = { "a" => 1 }
48
+
48
49
  same as
50
+
49
51
  data = { :a => 1 }
50
52
 
51
53
  it is a deep convertion of Hash.
@@ -55,8 +57,15 @@ it is a deep convertion of Hash.
55
57
  o #=> <#OpenOption a: <#OpenOption b:1> >
56
58
  # so you can access b by o.a.b
57
59
 
60
+ inheritance
61
+ -----------
58
62
 
59
-
63
+ class Foo < OpenOption
64
+ def initialize data={}
65
+ super
66
+ @data[:x] = data[:x].to_i
67
+ end
68
+ end
60
69
 
61
70
  =end
62
71
  class OpenOption
@@ -59,7 +59,7 @@ module ClassMethods::Cmd
59
59
  # make a directory
60
60
  #
61
61
  # @overload mkdir(*paths, o={})
62
- # @param [String] *paths
62
+ # @param [String, Pa] *paths
63
63
  # @param [Hash] o option
64
64
  # @option o [Fixnum] :mode
65
65
  # @option o [Boolean] :force
@@ -71,7 +71,7 @@ module ClassMethods::Cmd
71
71
  #
72
72
  # @overload mkdir_f(*paths, o={})
73
73
  # @return [nil]
74
- def mkdir_f(*args) paths, o = args.extract_options; o[:force]=true; _mkdir(*paths, o) end
74
+ def mkdir_f(*args) paths, o = args.extract_options; o[:force]=true; _mkdir(paths, o) end
75
75
 
76
76
  def _mkdir(paths, o)
77
77
  o[:mode] ||= 0744
@@ -149,36 +149,56 @@ module ClassMethods::Cmd
149
149
  #
150
150
  # @param [String] *paths support globbing
151
151
  # @return [nil]
152
- def rm(*paths)
152
+ def rm *paths
153
+ paths, o = paths.extract_options
153
154
  glob(*paths) { |pa|
154
- next if not File.exists?(pa.p)
155
+ if File.directory?(pa.p)
156
+ if o[:force]; next else raise Errno::EISDIR, "is a directory -- #{pa.p}" end
157
+ end
158
+ next if pa.directory?
155
159
  File.delete(pa.p)
156
160
  }
157
161
  end
158
162
 
163
+ def rm_f *paths
164
+ paths, o = paths.extract_options
165
+ o[:force] = true
166
+ rm *paths, o
167
+ end
168
+
159
169
  # rm directory only. still remove if directory is not empty.
160
170
  #
161
171
  # @param [String] *paths support globbing
162
172
  # @return [nil]
163
173
  def rmdir *paths
174
+ paths, o = paths.extract_options
164
175
  glob(*paths) { |pa|
165
- raise Errno::ENOTDIR, "-- #{pa}" if not File.directory?(pa.p)
176
+ if not File.directory?(pa.p)
177
+ if o[:force]; next else raise Errno::ENOTDIR, "not a directory -- #{pa.p}" end
178
+ end
166
179
  _rmdir(pa)
167
180
  }
168
181
  end
169
182
 
183
+ def rmdir_f *paths
184
+ paths, o = paths.extract_options
185
+ o[:force] = true
186
+ rmdir *paths, o
187
+ end
188
+
170
189
  # rm recusive, rm both file and directory
171
190
  #
172
191
  # @see rm
173
192
  # @return [nil]
174
- def rm_r(*paths)
193
+ def rm_r *paths
175
194
  glob(*paths){ |pa|
176
- next if not File.exists?(pa.p)
177
195
  File.directory?(pa.p) ? _rmdir(pa) : File.delete(pa.p)
178
196
  }
179
197
  end
198
+ alias rm_rf rm_r
199
+
180
200
 
181
- # rm_r(path) if condition is true
201
+ # rm_if(path) if condition is true
182
202
  #
183
203
  # @example
184
204
  # Pa.rm_if '/tmp/**/*.rb' do |pa|
@@ -230,7 +250,7 @@ module ClassMethods::Cmd
230
250
  # @option o [Boolean] :mkdir mkdir(dest) if dest not exists.
231
251
  # @option o [Boolean] :verbose puts cmd when execute
232
252
  # @option o [Boolean] :folsymlink follow symlink
233
- # @option o [Boolean] :overwrite overwrite dest file if dest is a file
253
+ # @option o [Boolean] :force force dest file if dest is a file
234
254
  # @option o [Boolean] :special special copy, when cp a directory, only mkdir, not cp the directory's content, usefull in Pa.each_r
235
255
  # @return [nil]
236
256
  # @overload cp(src_s, dest, o)
@@ -261,14 +281,17 @@ module ClassMethods::Cmd
261
281
  end
262
282
  end
263
283
 
284
+ def cp_f src_s, dest, o={}, &blk
285
+ o[:force] = true
286
+ cp src_s, dest, o, &blk
287
+ end
264
288
 
265
289
  # I'm recursive
266
290
  #
267
291
  # @param [String] src
268
292
  # @param [String] dest
269
293
  def _copy(src, dest, o={})
270
- raise Errno::EEXIST, "dest exists -- #{dest}" if File.exists?(dest) and (not o[:overwrite])
271
-
294
+ raise Errno::EEXIST, "dest exists -- #{dest}" if File.exists?(dest) and (not o[:force])
272
295
 
273
296
  case type=File.ftype(src)
274
297
 
@@ -318,7 +341,7 @@ module ClassMethods::Cmd
318
341
  # @param [Hash] o option
319
342
  # @option o [Boolean] :verbose
320
343
  # @option o [Boolean] :mkdir
321
- # @option o [Boolean] :overwrite
344
+ # @option o [Boolean] :fore
322
345
  # @return [nil]
323
346
  def mv(src_s, dest, o={}, &blk)
324
347
  srcs = glob(*Array.wrap(src_s)).map{|v| get(v)}
@@ -345,6 +368,11 @@ module ClassMethods::Cmd
345
368
  end
346
369
  end
347
370
 
371
+ def mv_f src_s, dest, o={}, &blk
372
+ o[:force] = true
373
+ mv src_s, dest, o, &blk
374
+ end
375
+
348
376
  # I'm recusive
349
377
  #
350
378
  # _move "file", "dir/file"
@@ -352,9 +380,9 @@ module ClassMethods::Cmd
352
380
  # @param [String] src
353
381
  # @param [String] dest
354
382
  def _move(src, dest, o)
355
- raise Errno::EEXIST, "dest exists -- #{dest}" if File.exists?(dest) and (not o[:overwrite])
383
+ raise Errno::EEXIST, "dest exists -- #{dest}" if File.exists?(dest) and (not o[:force])
356
384
 
357
- # overwrite. mv "dir", "dira" and 'dira' exists and is a directory.
385
+ # :force. mv "dir", "dira" and 'dira' exists and is a directory.
358
386
  if File.exists?(dest) and File.directory?(dest)
359
387
  ls(src) { |pa|
360
388
  dest1 = File.join(dest, File.basename(pa.p))
@@ -364,7 +392,7 @@ module ClassMethods::Cmd
364
392
 
365
393
  else
366
394
  begin
367
- Pa.rm_r dest if o[:overwrite] and File.exists?(dest)
395
+ Pa.rm_r dest if o[:force] and File.exists?(dest)
368
396
  puts "rename #{src} #{dest}" if o[:verbose]
369
397
  File.rename(src, dest)
370
398
  rescue Errno::EXDEV # cross-device
@@ -159,7 +159,7 @@ module ClassMethods::Dir
159
159
  #
160
160
  # @return [Array<String>]
161
161
  def ls_r(*args)
162
- each_r(*args).with_object([]){|pa,m| m<<pa.b}
162
+ each_r(*args).with_object([]){|pa,m| m<<pa.base}
163
163
  end
164
164
 
165
165
  end
@@ -245,6 +245,8 @@ module Path
245
245
  alias d dir
246
246
  alias b base
247
247
  alias n name
248
+ alias fname base
249
+ alias fn fname
248
250
  alias e ext
249
251
  alias fe fext
250
252
 
@@ -50,6 +50,12 @@ describe Pa do
50
50
  end
51
51
  end
52
52
 
53
+ describe "#rm_f" do
54
+ it "remove file force" do
55
+ lambda{Pa.rm_f("dir")}.should_not raise_error(Errno::EISDIR)
56
+ end
57
+ end
58
+
53
59
  describe "#rmdir" do
54
60
  it "remove directory" do
55
61
  Pa.rmdir "dir"
@@ -58,6 +64,12 @@ describe Pa do
58
64
  end
59
65
  end
60
66
 
67
+ describe "#rmdir_f" do
68
+ it "remove directory force" do
69
+ lambda{Pa.rmdir_r("a")}.should_not raise_error(Errno::ENOTDIR)
70
+ end
71
+ end
72
+
61
73
  describe "#rm_r" do
62
74
  it "remove both file and directory" do
63
75
  Pa.rm "a"
@@ -67,6 +79,8 @@ describe Pa do
67
79
  end
68
80
  end
69
81
 
82
+
83
+
70
84
  describe "#rm_if" do
71
85
  it "remove if condition" do
72
86
  Pa.rm_if "." do |pa|
@@ -152,14 +166,14 @@ describe Pa do
152
166
  end
153
167
  end
154
168
 
155
- context "with :overwrite" do
169
+ context "with :force" do
156
170
  it "_copy" do
157
171
  File.open("destdir/overwrite","w"){|f|f.write("")}
158
172
  lambda{Pa.cp "a", "destdir/overwrite"}.should raise_error(Errno::EEXIST)
159
173
  end
160
174
 
161
- it "_copy with :overwrite" do
162
- lambda{Pa.cp "a", "destdir/overwrite", overwrite:true}.should_not raise_error(Errno::EEXIST)
175
+ it "_copy with :force" do
176
+ lambda{Pa.cp "a", "destdir/overwrite", force:true}.should_not raise_error(Errno::EEXIST)
163
177
  end
164
178
  end
165
179
 
@@ -192,7 +206,7 @@ describe Pa do
192
206
  File.exists?("dird/ab").should be_true
193
207
  end
194
208
  end
195
-
209
+
196
210
  describe "#_move" do
197
211
  # a
198
212
  # dir/ b
@@ -211,17 +225,18 @@ describe Pa do
211
225
  File.exists?("a").should be_false
212
226
  end
213
227
 
214
- context "with :overwrite" do
228
+ context "with :force" do
215
229
  it "mv a dir/b" do
216
230
  lambda{Pa._move "a", "dir/b", {}}.should raise_error Errno::EEXIST
217
231
  end
218
232
 
219
- it "mv a dir/b :overwrite" do
233
+ it "mv a dir/b :force" do
220
234
  ino = File.stat('a').ino
221
- Pa._move "a", "dir/b", overwrite:true
235
+ Pa._move "a", "dir/b", force:true
222
236
  File.stat("dir/b").ino.should == ino
223
237
  end
224
238
  end
239
+
225
240
  end
226
241
 
227
242
  describe "#mv" do
data/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Tagen
2
2
  module VERSION
3
- MAJOR = 0
4
- MINOR = 2
5
- PATCH = 5
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
 
7
7
  IS = [MAJOR, MINOR, PATCH].join(".")
8
8
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: tagen
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 2
8
- - 5
9
- version: 0.2.5
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guten
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-26 00:00:00 +08:00
17
+ date: 2011-06-07 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -65,6 +65,7 @@ files:
65
65
  - docs/Architecture.md
66
66
  - docs/CoreExtensions.md
67
67
  - docs/ExtraExtensions.md
68
+ - lib/tagen/RMagick.rb
68
69
  - lib/tagen/audioinfo.rb
69
70
  - lib/tagen/cairo.rb
70
71
  - lib/tagen/core.rb
@@ -94,7 +95,6 @@ files:
94
95
  - lib/tagen/erb.rb
95
96
  - lib/tagen/gdk_pixbuf2.rb
96
97
  - lib/tagen/gtk2.rb
97
- - lib/tagen/magick.rb
98
98
  - lib/tagen/ncurses.rb
99
99
  - lib/tagen/net/http.rb
100
100
  - lib/tagen/pathname.rb