path_mapper 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzFhOGI1ZTA4M2M2ZWE4MGUxYjFhNjNiYjRiNmJkN2Y3OTEzZDU4MQ==
5
+ data.tar.gz: !binary |-
6
+ MWZhZWRlYzIzMmRjNWYwMjU2OGI3MmEwNjUzNmNmZmZmZmQ3M2Q1NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDY2MzZlZGNiZjNkOGEzMTNjMzI4ODBhNzI4YzNhOGE0ZGNhNWIxNThkMTY5
10
+ NjIzMWJjMmNkZDNkZGQzMTNkZGIxYTg0MTM0OTRhY2ZkZGI2NjdiNWUyZTI0
11
+ NTViNzdhNGE3NWY3YTc5YjMyZGM3MjJmMTZkYzM1YzA4MmQ1OWM=
12
+ data.tar.gz: !binary |-
13
+ YWZkYTc1MmMwZmNmMGM0MzliNThmMmNiZDVmM2QyMWE2ZWQxMGQ3YzZiYWMz
14
+ MDcyYjZmNjkxOGE2NzNlOTY4NmQ1YTk4YzBkZTNkMGMyN2U3ODJhNGM3ZjFh
15
+ YmU0ZGJkODVlNjBhMzk1ZTI0NDVlMTVjN2E4OTVkMmVlMDhmODA=
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ .idea
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ deploy:
5
+ provider: rubygems
6
+ api_key:
7
+ secure: MFKQmuIxmBH49OpDUPjcoDKdjsgNlOLQu8v0wST4aezUAGH6U09+dKgb8e78rBeItAvnjbIecW0SzreHTtUkdEZISFlPWjuzKtmeJ5OalCxHD3HEKpLGQFI3EJUOAD+bu/4u1GX7OcA3I4iqcRUMiRbkKlVNQjV0QkQxlZQv+AQjKbhUXYJ7GxGps17axH8r0QfUy6oOn0vY+SXiZKnutoyQoHN3JWYVHjy+1Uy6A05RkWgc4ZQEt8PcCix0SrEuibD52sVU+lJ/QBr+j0yeEVk12lUNrMZIeIiIBhJdu4qkxJFmMqWpNZHcMkU0EwrjroqXUbOVOnfyJH1PQ/1Ga/SLsHrc3A+zCESjBdzqTbfh4Kg7Z/nIiTw/UAe6mO1scd2JWPCrTE/i4ZR9sfJLV4Wi/P5/kllYVTgqCDYy9Obgyxv+vhDHPsNa6hMbDW3W3lWe660zmVMYv+zB9vzh3sYleA5Kx2iICJzy04krdhLXD2YErQzGiR+F5f6H6ZtZyX9B28Ab3Af4vvLqNYwtGE1BH+5nP4undXGmDnH5PkNj0UHeNb4KADJncNGhk3DtSuOxBhg52y6i/s1T4qW0+WaXJjGqOZhpEXyMyh+M5rUnFZ5MmdOLeFPqzw8rhzl7IgR5cFVbwfpAHYMp64QBkjWiNI/QiXtIcX9iGJbVcRs=
8
+ gem: path_mapper
9
+ on:
10
+ tags: true
11
+ repo: flant/path_mapper
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Alexey Igrychev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # PathMapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'path_mapper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install path_mapper
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/path_mapper/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,127 @@
1
+ require 'path_mapper/version'
2
+
3
+ module PathMapper
4
+ def self.new(path)
5
+ if File.exists? path
6
+ if File.directory? path
7
+ return DirNode.new(path)
8
+ elsif !File.read(path).strip.empty?
9
+ return FileNode.new(path)
10
+ end
11
+ 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
+
42
+ def to_s
43
+ @_path
44
+ end
45
+
46
+ def inspect
47
+ self.to_s
48
+ end
49
+
50
+ alias_method :to_str, :to_s
51
+ end
52
+
53
+ class DirNode
54
+ include BaseNode
55
+
56
+ def method_missing(m, *args, **kwargs, &block)
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
64
+ end
65
+
66
+ class FileNode
67
+ include BaseNode
68
+
69
+ def method_missing(m, *args, &block)
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
80
+ end
81
+
82
+ class NullNode < BasicObject
83
+ include BaseNode
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
126
+ end
127
+ end
@@ -0,0 +1,3 @@
1
+ module PathMapper
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'path_mapper/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "path_mapper"
7
+ spec.version = PathMapper::VERSION
8
+ spec.authors = ["Alexey Igrychev"]
9
+ spec.email = ["alexey.igrychev@flant.ru"]
10
+ spec.summary = "Map filesystem to ruby objects read-only."
11
+ spec.description = spec.description
12
+ spec.license = "MIT"
13
+ spec.homepage = "https://github.com/flant/path_mapper"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
23
+ spec.add_development_dependency 'travis', '~> 1.8', '>= 1.8.2'
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe PathMapper do
4
+ it 'has a version number' do
5
+ expect(PathMapper::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+
3
+ Bundler.setup
4
+
5
+ require 'path_mapper'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: path_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexey Igrychev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 3.4.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: '3.4'
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 3.4.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: travis
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '1.8'
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 1.8.2
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.8'
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 1.8.2
81
+ description: ''
82
+ email:
83
+ - alexey.igrychev@flant.ru
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - .rspec
90
+ - .travis.yml
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/path_mapper.rb
96
+ - lib/path_mapper/version.rb
97
+ - path_mapper.gemspec
98
+ - spec/path_mapper_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: https://github.com/flant/path_mapper
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Map filesystem to ruby objects read-only.
124
+ test_files:
125
+ - spec/path_mapper_spec.rb
126
+ - spec/spec_helper.rb