posix-fileutils 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDEyYjk2MmY4ZmY1OTdmYzc0MDcxOThlOTQ5NmU2ZDVhYmZjMTkyNw==
4
+ ZGNhYTYxYTAxYjE4YzUyMzgwZjk1NTM1MDg1Y2I3MGVmMmFlNjFmMA==
5
5
  data.tar.gz: !binary |-
6
- NjFiNTRjZGRiZWI3MzRlOWI5ZTE3MjM3OTkwMTNlN2E3MDJkYTg2NQ==
7
- !binary "U0hBNTEy":
6
+ MDk0ZDNiYTI2M2M2MjhhYWE1NDVlMGFjNjE1M2M1YWZjNmZjNGIyOQ==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2QzY2MwZDBmNTQwMjRjOGVkNDQ5MjQ5MTJjMzU4NmYxMzZlYTJlYTQ4NGQ5
10
- NTg3Yjc3MzZjNTIzMDBkYmJlZmY4N2RmNTM0OWFmN2IyYzJkYzE1YTc3Mzg5
11
- ZjgwZjhlNzEyZTZmYWE0MzA5M2U2Yjk1MDhkYjg2NDMzMjRhMmY=
9
+ Njg3NDc4YjY1NjUzMThlZjEzZWVmN2FkNzJkNjEwZDU2OTdmOTk1MDk0MWIx
10
+ ZTY4YzYyMDA5MThkMTEyNjJkNjZkM2U3NWNiM2I3ZWVlYzAwOTUyMDQxZmRi
11
+ NDg4NTAwNzljOGY4Y2Y0YTJkMWMzYTk0NGFjMTVkNDhhN2I5MDg=
12
12
  data.tar.gz: !binary |-
13
- OGY4ZTUyYzQyNWEwY2MyZjllYWZmNDZhZDAyZTg0OTUwMDY5Nzc0MTNlNmFk
14
- NzEzYmY3ODhlNTM2ZWY3Y2RjOGI5NzI4YjNjZmMwNTA2M2Y1ZTdmZDdmMTQy
15
- MjBiMjE0NWZjYjQ3NzMzZjk2MTRmYTBhNzVhNWY0NjNjZDQwOWM=
13
+ MGU5NzMxNTY3NjBjYjFkZmQ3NGEzM2E3MDM0YzM5YjU4ZDgwODc2NWUyYjdj
14
+ ZDY5NGUzMzFkYmQzNjg2MzhlMmY3NDM5MzNiMmM2MjA3MDQ5MTVhZjM0NDlh
15
+ ZjEzNTE5NDgwYzU4MjVjZWUxOGIxZDlmMTJkYjM0M2MzMTAxZGU=
@@ -0,0 +1,144 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+
4
+ class Object
5
+ def a?
6
+ Enumerable === self
7
+ end
8
+ end
9
+
10
+ module FileUtils
11
+ $fudeopt = []
12
+
13
+ class << self
14
+ def parse_cp_args src, dst, *opts
15
+ raise ArgumentError unless !dst.a?
16
+
17
+ dst = Pathname.new dst.to_s unless dst.kind_of? Pathname
18
+
19
+ if src.a?
20
+ return true if src.count == 0
21
+
22
+ raise ArgumentError unless dst.directory?
23
+
24
+ src.map! do |elem| Pathname.new elem.to_s unless elem.kind_of? Pathname end
25
+
26
+ class << src
27
+ def to_s
28
+ inject('') do |accu, elem| "#{accu}#{elem.to_s} " end.chomp ' '
29
+ end
30
+ end
31
+ else
32
+ src = Pathname.new src.to_s unless src.kind_of? Pathname
33
+ end
34
+
35
+ class << opts
36
+ attr_accessor :src
37
+ attr_accessor :dst
38
+
39
+ def to_s
40
+ opts_s = '-f '
41
+
42
+ [:T, :a, :v, :r].each do |opt|
43
+ opts_s << "-#{opt.to_s} " if index(opt) || $fudeopt.index(opt)
44
+ end
45
+
46
+ opts_s
47
+ end
48
+ end
49
+
50
+ opts.src, opts.dst = src, dst
51
+
52
+ [src, dst, opts]
53
+ end
54
+
55
+ def cp src, dst, *opts
56
+ src, dst, opts = parse_cp_args src, dst, *opts
57
+
58
+ opts << :r if src.a? ? src.inject(false) do |a,p| p.directory? | a end : src.directory?
59
+
60
+ Kernel.system "cp #{opts.to_s}#{src.to_s} #{dst.to_s}"
61
+ end
62
+
63
+ def mv src, dst, *opts
64
+ src, dst, opts = parse_cp_args src, dst, *opts
65
+
66
+ Kernel.system "mv #{opts.to_s}#{src.to_s} #{dst.to_s}"
67
+ end
68
+
69
+ def parse_list_args list, *opts
70
+ if list.a?
71
+ return true if list.count == 0
72
+
73
+ list.map! do |elem| Pathname.new elem.to_s unless elem.kind_of? Pathname end
74
+
75
+ class << list
76
+ def to_s
77
+ inject('') do |accu,elem| "#{accu}#{elem.to_s} " end.chomp ' '
78
+ end
79
+ end
80
+ else
81
+ list = Pathname.new list.to_s unless list.kind_of? Pathname
82
+ end
83
+
84
+ class << opts
85
+ attr_accessor :list
86
+ attr_accessor :flags
87
+
88
+ def to_s
89
+ opts_s = ''
90
+
91
+ @flags.each do |opt|
92
+ opts_s << "-#{opt.to_s} " if index(opt) || $fudeopt.index(opt)
93
+ end
94
+
95
+ opts_s
96
+ end
97
+ end
98
+
99
+ opts.list = list
100
+
101
+ [list, opts]
102
+ end
103
+
104
+ def rm list, *opts
105
+ list, opts = parse_list_args list, *opts
106
+ opts.flags = [:v, :f, :r]
107
+
108
+ opts << :r if list.a? ? list.inject(false) do |a,p| p.directory? | a end : list.directory?
109
+
110
+ Kernel.system "rm #{opts.to_s}#{list.to_s}"
111
+ end
112
+
113
+ def mkdir list, *opts
114
+ list, opts = parse_list_args list, *opts
115
+ opts.flags = [:v]
116
+
117
+ if opts.index :f
118
+ unless list.a?
119
+ return true if list.directory?
120
+ else
121
+ list.select! do |elem| !elem.directory? end
122
+ return true if list.empty?
123
+ end
124
+ end
125
+
126
+ Kernel.system "mkdir #{opts.to_s}#{list.to_s}"
127
+ end
128
+
129
+ def touch list, *opts
130
+ list, opts = parse_list_args list, *opts
131
+ opts.flags = [:v]
132
+
133
+ Kernel.system "touch #{opts.to_s}#{list.to_s}"
134
+ end
135
+
136
+ def pwd
137
+ Pathname.new(`pwd`.chomp)
138
+ end
139
+
140
+ end # class << self
141
+ end # module FileUtils
142
+
143
+ # vim: sw=2 sts=2 ts=8:
144
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posix-fileutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - A. Levenkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-31 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: FileUtils library
14
14
  email: artem@levenkov.org
@@ -16,8 +16,7 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - fileutils.rb
20
- - fileutils-test.rb
19
+ - lib/posix-fileutils/fileutils.rb
21
20
  homepage: http://rubygems.org/gems/posix-fileutils
22
21
  licenses:
23
22
  - MIT
@@ -38,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
37
  version: '0'
39
38
  requirements: []
40
39
  rubyforge_project:
41
- rubygems_version: 2.0.3
40
+ rubygems_version: 2.2.2
42
41
  signing_key:
43
42
  specification_version: 4
44
43
  summary: FileUtils library
data/fileutils-test.rb DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require './fileutils.rb'
4
-
5
- p FileUtils.ls '.'
6
-
7
- # vim: sw=2 sts=2 ts=8:
8
-
data/fileutils.rb DELETED
@@ -1,82 +0,0 @@
1
- module FileUtils
2
- def self.ls *args
3
- list = args[0]
4
- opts = args[1]
5
-
6
- if list.class == Array
7
- class << list
8
- def to_s
9
- join ' '
10
- end
11
- end
12
- end
13
-
14
- res = `ls #{opts.to_s} #{list.to_s}`.split "\n"
15
-
16
- return res if list.class != Array
17
-
18
- delim = list.map do |i| i << ':' end
19
-
20
- indexes = delim.map do |i| i = res.index i end
21
-
22
- indexes.sort!
23
-
24
- indexes = indexes.drop 1 if indexes[0].zero?
25
-
26
- indexes << -1
27
-
28
- li = 0
29
-
30
- res_map = {}
31
-
32
- indexes.each do |i|
33
- path = res[li][0..res[li].length-2]
34
-
35
- res_map[path] = res[li+1..i-1]
36
- res_map[path].delete_at -1 if res_map[path][-1].length.zero?
37
- li = i
38
- end
39
-
40
- return res_map
41
- end
42
-
43
- def self.cp dst, src, opt
44
- if dst.class == Array
45
- raise ArgumentError if dst.count != 1
46
-
47
- class << src
48
- def to_s
49
- join ' '
50
- end
51
- end
52
- end
53
-
54
- if src.class == Array
55
- raise ArgumentError if dst.count == 0
56
- end
57
-
58
- `cp #{src.to_s} #{dst.to_s}`
59
- end
60
-
61
- def self.mv dst, src, opt
62
- end
63
-
64
- def self.rm files, opt
65
- end
66
-
67
- def self.rmdir files, opt
68
- end
69
-
70
- def self.ln dst, src, opt
71
- end
72
-
73
- def self.unlink files, opt
74
- end
75
-
76
- def self.touch files, opt
77
- end
78
-
79
- end
80
-
81
- # vim: sw=2 sts=2 ts=8:
82
-