path_to 0.1.0
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 +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/README.md +70 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/path_to.rb +30 -0
- data/lib/path_to/version.rb +3 -0
- data/path_to.gemspec +30 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3330b2c1dce0e43f746757ddeda495bc5615d77d
|
4
|
+
data.tar.gz: f26768a3ed24ea45324e89c1500359fda30a69f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1cc11a6f585e674a19fcd7a70b0fbd9a7e5b187fbb951e720b66e458f7ed8c24e47443566325eecf3ce8fee2d4144355404abcd0ba20bcc2db421c7ace84785a
|
7
|
+
data.tar.gz: b7e67fb3c4549e6218f64774faac665888c6506961b1a1ee933cc153c8c5eebcc00291e3d8c7511097fd4e26b192e31b42af5ea85ced5abaf4ebf23c69f553a0
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Gemfile.lock
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Path To
|
2
|
+
|
3
|
+
A simple class to handle conditional logic of looking for a file in multiple
|
4
|
+
paths.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'path_to'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install path_to
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Not unlike a `$PATH` environment variables, a `PathTo` instance contains one
|
25
|
+
or more locations to look for a file, and will return the first file it finds.
|
26
|
+
|
27
|
+
**Example:**
|
28
|
+
|
29
|
+
Suppose you have some files in the following directory structure:
|
30
|
+
|
31
|
+
```
|
32
|
+
├── default_files
|
33
|
+
│ └── alpha
|
34
|
+
│ └── bravo
|
35
|
+
├── specific_files
|
36
|
+
│ └── alpha
|
37
|
+
```
|
38
|
+
|
39
|
+
Then you can use `path_to` to add `specific_files` and `default_files` to the
|
40
|
+
locations to look for your files.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'path_to'
|
44
|
+
p = PathTo.new('specific_files', 'default_files')
|
45
|
+
p.path_to 'alpha'
|
46
|
+
# => 'specific_files/alpha'
|
47
|
+
p.path_to 'bravo'
|
48
|
+
# => 'default_files/bravo'
|
49
|
+
```
|
50
|
+
|
51
|
+
And there is a shortcut for returning `File` objects.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
p.file('alpha')
|
55
|
+
# => #<File:specific_files/alpha>
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/[my-github-username]/path_to/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "path_to"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/path_to.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "path_to/version"
|
2
|
+
|
3
|
+
class PathTo
|
4
|
+
|
5
|
+
attr_accessor :paths
|
6
|
+
|
7
|
+
def initialize(*paths)
|
8
|
+
@paths = Array(paths)
|
9
|
+
end
|
10
|
+
|
11
|
+
def path_to(filename)
|
12
|
+
paths.each do |path|
|
13
|
+
fullpath = File.join(path, filename)
|
14
|
+
if File.exists?(fullpath)
|
15
|
+
return fullpath
|
16
|
+
end
|
17
|
+
end
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
# Plural version of path_to
|
22
|
+
def paths_to(filenames=[])
|
23
|
+
Array(filenames).map{ |filename| path_to(filename) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def file(filename, opts={})
|
27
|
+
mode, perm, opt = opts[:mode], opts[:perm], opts[:opt]
|
28
|
+
File.new(path_to(filename), mode, perm, opt)
|
29
|
+
end
|
30
|
+
end
|
data/path_to.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'path_to/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "path_to"
|
8
|
+
spec.version = PathTo::VERSION
|
9
|
+
spec.authors = ["Andrew Myers"]
|
10
|
+
spec.email = ["afredmyers@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple class to handle conditional logic of looking for a file in multiple paths.}
|
13
|
+
spec.homepage = "https://github.com/afred/path_to"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: path_to
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Myers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-25 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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
|
+
description:
|
42
|
+
email:
|
43
|
+
- afredmyers@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- Gemfile
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/path_to.rb
|
57
|
+
- lib/path_to/version.rb
|
58
|
+
- path_to.gemspec
|
59
|
+
homepage: https://github.com/afred/path_to
|
60
|
+
licenses: []
|
61
|
+
metadata:
|
62
|
+
allowed_push_host: https://rubygems.org
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Simple class to handle conditional logic of looking for a file in multiple
|
83
|
+
paths.
|
84
|
+
test_files: []
|