path_mapper 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +0 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +103 -0
- data/lib/path_mapper.rb +63 -107
- data/lib/path_mapper/helper/debug.rb +20 -0
- data/lib/path_mapper/helper/logger.rb +21 -0
- data/lib/path_mapper/helper/storage.rb +36 -0
- data/lib/path_mapper/helpers.rb +22 -0
- data/lib/path_mapper/node/base.rb +32 -0
- data/lib/path_mapper/node/base/file.rb +132 -0
- data/lib/path_mapper/node/base/grep.rb +19 -0
- data/lib/path_mapper/node/base/representation.rb +73 -0
- data/lib/path_mapper/node/dir.rb +31 -0
- data/lib/path_mapper/node/dir/erb.rb +25 -0
- data/lib/path_mapper/node/dir/file.rb +41 -0
- data/lib/path_mapper/node/dir/grep.rb +38 -0
- data/lib/path_mapper/node/dir/inheritance.rb +10 -0
- data/lib/path_mapper/node/dir/inheritance/base.rb +54 -0
- data/lib/path_mapper/node/dir/inheritance/grep.rb +22 -0
- data/lib/path_mapper/node/dir/representation.rb +18 -0
- data/lib/path_mapper/node/file.rb +15 -0
- data/lib/path_mapper/node/file/erb.rb +27 -0
- data/lib/path_mapper/node/file/file.rb +60 -0
- data/lib/path_mapper/node/file/representation.rb +37 -0
- data/lib/path_mapper/node/null.rb +20 -0
- data/lib/path_mapper/node/null/file.rb +46 -0
- data/lib/path_mapper/node/null/representation.rb +23 -0
- data/lib/path_mapper/patch/pathname.rb +13 -0
- data/lib/path_mapper/reloader.rb +26 -0
- data/lib/path_mapper/version.rb +1 -1
- data/path_mapper.gemspec +4 -1
- data/spec/spec_helper.rb +4 -0
- metadata +84 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDc4YjkyZDNlMDAxOGE5MzExOTRlZjk0MjBiMTdmNmE3OWViN2VkMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjVmZmFlMDA5NTVlZjhkYWNhYzBmZGM4YzdkMmFlYzFhNTE4ODAxZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDkyMGExNTk4MTI1M2I4OTBlNTlhMjM5ZTA2ZjdkZTQzZTdmMGVkZWY4ZGQ5
|
10
|
+
NzNkYzJhNzBiMDU0NTBhNDA5NWQzYzVmZDAwYzgyY2I5NzgxYWY5YjU1ZTUy
|
11
|
+
NjQ4M2M3MWQxMGM3MThmN2M1MzUyZDZjYzdmYWZmNTg3YjdkYzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjM2NmVmMmE3M2MyOTE0NzdhZWZkMDczMDE5MjI0YjQxY2NkZGUzYjE0NDQ1
|
14
|
+
OTA3MGRiOThlYTIwZTQwYzI5MmY2MWIxOGM0ODliMTU2NDY4OTk3NjhhNGQ2
|
15
|
+
MjlmODQwNGM5OTkzNDYwMGY4NjhlMTgzOThhZTk5ZmQxNjIwN2E=
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/flant/net_status.git
|
3
|
+
revision: 5a91caf2daaa74985699ede3bc5a9f8ac60a71d8
|
4
|
+
specs:
|
5
|
+
net_status (0.0.2)
|
6
|
+
i18n (~> 0.7)
|
7
|
+
|
8
|
+
PATH
|
9
|
+
remote: .
|
10
|
+
specs:
|
11
|
+
path_mapper (0.0.3)
|
12
|
+
diffy (~> 3.1)
|
13
|
+
|
14
|
+
GEM
|
15
|
+
remote: https://rubygems.org/
|
16
|
+
specs:
|
17
|
+
addressable (2.4.0)
|
18
|
+
backports (3.6.8)
|
19
|
+
codeclimate-test-reporter (0.5.0)
|
20
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
21
|
+
coderay (1.1.1)
|
22
|
+
diff-lcs (1.2.5)
|
23
|
+
diffy (3.1.0)
|
24
|
+
docile (1.1.5)
|
25
|
+
ethon (0.8.1)
|
26
|
+
ffi (>= 1.3.0)
|
27
|
+
faraday (0.9.2)
|
28
|
+
multipart-post (>= 1.2, < 3)
|
29
|
+
faraday_middleware (0.10.0)
|
30
|
+
faraday (>= 0.7.4, < 0.10)
|
31
|
+
ffi (1.9.10)
|
32
|
+
gh (0.14.0)
|
33
|
+
addressable
|
34
|
+
backports
|
35
|
+
faraday (~> 0.8)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
net-http-persistent (>= 2.7)
|
38
|
+
net-http-pipeline
|
39
|
+
highline (1.7.8)
|
40
|
+
i18n (0.7.0)
|
41
|
+
json (1.8.3)
|
42
|
+
launchy (2.4.3)
|
43
|
+
addressable (~> 2.3)
|
44
|
+
method_source (0.8.2)
|
45
|
+
multi_json (1.11.2)
|
46
|
+
multipart-post (2.0.0)
|
47
|
+
net-http-persistent (2.9.4)
|
48
|
+
net-http-pipeline (1.0.1)
|
49
|
+
pry (0.10.3)
|
50
|
+
coderay (~> 1.1.0)
|
51
|
+
method_source (~> 0.8.1)
|
52
|
+
slop (~> 3.4)
|
53
|
+
pusher-client (0.6.2)
|
54
|
+
json
|
55
|
+
websocket (~> 1.0)
|
56
|
+
rake (10.5.0)
|
57
|
+
rspec (3.4.0)
|
58
|
+
rspec-core (~> 3.4.0)
|
59
|
+
rspec-expectations (~> 3.4.0)
|
60
|
+
rspec-mocks (~> 3.4.0)
|
61
|
+
rspec-core (3.4.4)
|
62
|
+
rspec-support (~> 3.4.0)
|
63
|
+
rspec-expectations (3.4.0)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.4.0)
|
66
|
+
rspec-mocks (3.4.1)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.4.0)
|
69
|
+
rspec-support (3.4.1)
|
70
|
+
simplecov (0.11.2)
|
71
|
+
docile (~> 1.1.0)
|
72
|
+
json (~> 1.8)
|
73
|
+
simplecov-html (~> 0.10.0)
|
74
|
+
simplecov-html (0.10.0)
|
75
|
+
slop (3.6.0)
|
76
|
+
travis (1.8.2)
|
77
|
+
backports
|
78
|
+
faraday (~> 0.9)
|
79
|
+
faraday_middleware (~> 0.9, >= 0.9.1)
|
80
|
+
gh (~> 0.13)
|
81
|
+
highline (~> 1.6)
|
82
|
+
launchy (~> 2.1)
|
83
|
+
pusher-client (~> 0.4)
|
84
|
+
typhoeus (~> 0.6, >= 0.6.8)
|
85
|
+
typhoeus (0.8.0)
|
86
|
+
ethon (>= 0.8.0)
|
87
|
+
websocket (1.2.3)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
ruby
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
bundler (~> 1.7)
|
94
|
+
codeclimate-test-reporter (>= 0.5.0, < 1.0)
|
95
|
+
net_status!
|
96
|
+
path_mapper!
|
97
|
+
pry (>= 0.10.3, < 1.0)
|
98
|
+
rake (~> 10.0)
|
99
|
+
rspec (~> 3.4, >= 3.4.0)
|
100
|
+
travis (~> 1.8, >= 1.8.2)
|
101
|
+
|
102
|
+
BUNDLED WITH
|
103
|
+
1.11.2
|
data/lib/path_mapper.rb
CHANGED
@@ -1,127 +1,83 @@
|
|
1
1
|
require 'path_mapper/version'
|
2
2
|
|
3
|
+
require 'net_status'
|
4
|
+
|
5
|
+
require 'erb'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'pathname'
|
8
|
+
require 'digest/md5'
|
9
|
+
require 'diffy'
|
10
|
+
|
11
|
+
require 'path_mapper/helper/debug'
|
12
|
+
require 'path_mapper/helper/logger'
|
13
|
+
require 'path_mapper/helper/storage'
|
14
|
+
require 'path_mapper/helpers'
|
15
|
+
|
16
|
+
require 'path_mapper/node/base/file'
|
17
|
+
require 'path_mapper/node/base/grep'
|
18
|
+
require 'path_mapper/node/base/representation'
|
19
|
+
require 'path_mapper/node/dir/inheritance/base'
|
20
|
+
require 'path_mapper/node/dir/inheritance/grep'
|
21
|
+
require 'path_mapper/node/dir/inheritance'
|
22
|
+
require 'path_mapper/node/dir/erb'
|
23
|
+
require 'path_mapper/node/dir/file'
|
24
|
+
require 'path_mapper/node/dir/grep'
|
25
|
+
require 'path_mapper/node/dir/representation'
|
26
|
+
require 'path_mapper/node/file/erb'
|
27
|
+
require 'path_mapper/node/file/file'
|
28
|
+
require 'path_mapper/node/file/representation'
|
29
|
+
require 'path_mapper/node/null/file'
|
30
|
+
require 'path_mapper/node/null/representation'
|
31
|
+
require 'path_mapper/node/base'
|
32
|
+
require 'path_mapper/node/dir'
|
33
|
+
require 'path_mapper/node/file'
|
34
|
+
require 'path_mapper/node/null'
|
35
|
+
|
36
|
+
require 'path_mapper/reloader'
|
37
|
+
|
3
38
|
module PathMapper
|
4
|
-
|
39
|
+
extend Helpers
|
40
|
+
|
41
|
+
def self.new(path, **kwargs)
|
42
|
+
path = Pathname(path) unless path.is_a? Pathname
|
43
|
+
|
5
44
|
if File.exists? path
|
6
45
|
if File.directory? path
|
7
|
-
|
46
|
+
self.with_dry_run {|dry_run| self.storage_tree(path) if !self.storage.key?(path) and dry_run }
|
47
|
+
return DirNode.new(path, **kwargs)
|
8
48
|
elsif !File.read(path).strip.empty?
|
9
|
-
|
49
|
+
self.with_dry_run {|dry_run| self.storage_file_tree(path) if !self.storage.key?(path) and dry_run }
|
50
|
+
return FileNode.new(path, **kwargs)
|
10
51
|
end
|
11
52
|
end
|
12
|
-
NullNode.new(path)
|
13
|
-
end
|
14
|
-
|
15
|
-
module BaseNode
|
16
|
-
attr_reader :_path
|
17
|
-
attr_reader :_name
|
18
|
-
|
19
|
-
def initialize(path)
|
20
|
-
@_path = path
|
21
|
-
@_name = get_file_name(path)
|
22
|
-
end
|
23
|
-
|
24
|
-
def _grep(reg, recursive=false)
|
25
|
-
path = "#{@_path}#{'/**' if recursive}/*"
|
26
|
-
files = Dir[path].select {|f| f =~ reg }
|
27
|
-
FilesIterator.new(files)
|
28
|
-
end
|
29
|
-
|
30
|
-
def _grep_dirs(recursive=false)
|
31
|
-
self._grep(/.*/).select {|n| n.is_a? DirNode }
|
32
|
-
end
|
33
|
-
|
34
|
-
def _grep_files(recursive=false)
|
35
|
-
self._grep(/.*/).select {|n| n.is_a? FileNode }
|
36
|
-
end
|
37
|
-
|
38
|
-
def get_file_name(name)
|
39
|
-
name.scan(/[^\/]+/).last
|
40
|
-
end
|
41
53
|
|
42
|
-
|
43
|
-
|
54
|
+
self.with_dry_run do |dry_run|
|
55
|
+
if self.storage.key? path and !self.deleted_files.include? path
|
56
|
+
if self.storage[path].nil?
|
57
|
+
return DirNode.new(path, **kwargs)
|
58
|
+
elsif !self.storage[path].strip.empty?
|
59
|
+
return FileNode.new(path, **kwargs)
|
60
|
+
end
|
61
|
+
end if dry_run
|
44
62
|
end
|
45
63
|
|
46
|
-
|
47
|
-
self.to_s
|
48
|
-
end
|
49
|
-
|
50
|
-
alias_method :to_str, :to_s
|
64
|
+
NullNode.new(path, **kwargs)
|
51
65
|
end
|
52
66
|
|
53
67
|
class DirNode
|
54
|
-
include
|
55
|
-
|
56
|
-
|
57
|
-
self.f(m, **kwargs)
|
58
|
-
end
|
59
|
-
|
60
|
-
def f(m, **kwargs)
|
61
|
-
obj = PathMapper.new(File.join(@_path, m.to_s))
|
62
|
-
(obj.empty? and kwargs.key? :default) ? kwargs[:default] : obj
|
63
|
-
end
|
68
|
+
include Node::Dir
|
69
|
+
include Node::Dir::Erb
|
70
|
+
include Reloader
|
64
71
|
end
|
65
72
|
|
66
73
|
class FileNode
|
67
|
-
include
|
68
|
-
|
69
|
-
|
70
|
-
(@content ||= self.to_s).send(m, *args, &block)
|
71
|
-
end
|
72
|
-
|
73
|
-
def _grep(reg, recursive=false)
|
74
|
-
[]
|
75
|
-
end
|
76
|
-
|
77
|
-
def to_s
|
78
|
-
File.read(@_path).strip
|
79
|
-
end
|
74
|
+
include Node::File
|
75
|
+
include Node::File::Erb
|
76
|
+
include Reloader
|
80
77
|
end
|
81
78
|
|
82
|
-
class NullNode
|
83
|
-
include
|
84
|
-
|
85
|
-
def method_missing(m, *args, **kwargs, &block)
|
86
|
-
if nil.respond_to? m
|
87
|
-
nil.send m, *args, &block
|
88
|
-
else
|
89
|
-
self.f(m, **kwargs)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def f(m, **kwargs)
|
94
|
-
kwargs.key?(:default) ? kwargs[:default] : NullNode.new([@_path, m.to_s].join(::File::SEPARATOR))
|
95
|
-
end
|
96
|
-
|
97
|
-
def _grep(reg, recursive=false)
|
98
|
-
[]
|
99
|
-
end
|
100
|
-
|
101
|
-
def nil?
|
102
|
-
true
|
103
|
-
end
|
104
|
-
|
105
|
-
def empty
|
106
|
-
true
|
107
|
-
end
|
108
|
-
|
109
|
-
def any?
|
110
|
-
false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
class FilesIterator
|
115
|
-
include Enumerable
|
116
|
-
|
117
|
-
def initialize(files)
|
118
|
-
@files = files
|
119
|
-
end
|
120
|
-
|
121
|
-
def each
|
122
|
-
@files.each do |f|
|
123
|
-
yield PathMapper.new(f)
|
124
|
-
end
|
125
|
-
end
|
79
|
+
class NullNode
|
80
|
+
include Node::Null
|
81
|
+
include Reloader
|
126
82
|
end
|
127
|
-
end
|
83
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PathMapper
|
2
|
+
module Helper
|
3
|
+
module Debug
|
4
|
+
def dry_run
|
5
|
+
Thread.current[:dry_run]
|
6
|
+
end
|
7
|
+
|
8
|
+
def dry_run=(state)
|
9
|
+
Thread.current[:dry_run] = state
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_dry_run
|
13
|
+
old = self.dry_run
|
14
|
+
yield old
|
15
|
+
ensure
|
16
|
+
self.dry_run = old
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PathMapper
|
2
|
+
module Helper
|
3
|
+
module Logger
|
4
|
+
def logger
|
5
|
+
Thread.current[:logger]
|
6
|
+
end
|
7
|
+
|
8
|
+
def logger=(state)
|
9
|
+
Thread.current[:logger] = state
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_logger(logger: nil)
|
13
|
+
old = self.logger
|
14
|
+
self.logger = nil if logger.is_a? FalseClass
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
self.logger = old
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module PathMapper
|
2
|
+
module Helper
|
3
|
+
module Storage
|
4
|
+
def storage
|
5
|
+
Thread.current[:dry_storage] ||= {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def deleted_files
|
9
|
+
self.storage[:deleted_files] ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def storage_tree(pathname)
|
13
|
+
path = pathname
|
14
|
+
while path.to_s != '/'
|
15
|
+
self.storage[path] = nil
|
16
|
+
path = path.parent
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def storage_file_tree(pathname)
|
21
|
+
self.storage[pathname] = File.read(pathname)
|
22
|
+
storage_tree(pathname.parent)
|
23
|
+
end
|
24
|
+
|
25
|
+
def storage_file_delete(pathname)
|
26
|
+
self.deleted_files << pathname
|
27
|
+
self.storage.delete(pathname)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_storage_branch(pathname)
|
31
|
+
self.storage_file_delete(pathname)
|
32
|
+
self.storage.select {|k,v| k.to_s.start_with? pathname.to_s }.each {|k,v| self.storage_file_delete(k) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PathMapper
|
2
|
+
module Helpers
|
3
|
+
include Helper::Debug
|
4
|
+
include Helper::Logger
|
5
|
+
include Helper::Storage
|
6
|
+
|
7
|
+
def kwargs(args)
|
8
|
+
case args.last
|
9
|
+
when Hash then args.pop
|
10
|
+
else {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_line_separator(arg)
|
15
|
+
if arg.is_a? Array
|
16
|
+
with_line_separator(arg.join("\n"))
|
17
|
+
else
|
18
|
+
"#{arg}\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module PathMapper
|
2
|
+
module Node
|
3
|
+
module Base
|
4
|
+
include Grep
|
5
|
+
include File
|
6
|
+
include Representation
|
7
|
+
include Helpers
|
8
|
+
|
9
|
+
attr_reader :path
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
def initialize(path, **kwargs)
|
13
|
+
@path = Pathname.new(path)
|
14
|
+
@name = @path.basename.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def parent
|
18
|
+
self._create_node(@path.parent)
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def _create_node(path)
|
24
|
+
PathMapper.new(path, self._general_options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def _general_options
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|