file_finder 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a648a32d4db029ca80b4890db2c5ea359a81f0d8
4
+ data.tar.gz: 9c3c9d85961a548c967a85864eff8630807d332a
5
+ SHA512:
6
+ metadata.gz: d4944a0d654e6bab746cf1ecbbcaf6e368884c7fb406bee968a2a7af41603772b8ddcf9be982b37ce8878808762fbe1fb39a995fc468b2e0eb4b569826924059
7
+ data.tar.gz: 43849f3d2a740e51bde93727e295ea9f5adfdafe74c0c369453702d533a56283a9564f0d5a91e363f3a6e7fdac854fa8ae7d9fc2f4ceac5f9aebda1ba21aa6cf
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in file_finder.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Logan Hasson
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.
@@ -0,0 +1,93 @@
1
+ # FileFinder
2
+
3
+ Easily access files within your gems' directory structures. Why is this
4
+ cool? It takes some annoying jumping through hoops to access support files from
5
+ within a gem. If you try to `File.read('some/file.rb')`, you end up
6
+ accessing a file relative to where the gem is *run* from.
7
+
8
+ FileFinder gives you a simple helper method to get the absolute path to
9
+ support files.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your gemspec:
14
+
15
+ spec.add_runtime_dependency "file_finder"
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install file_finder
24
+
25
+ ## Usage
26
+
27
+ Call `apath_to` with a relative path to a file.
28
+
29
+ `apath_to('path/to/file.rb')`
30
+
31
+ For example, let's say I have this directory structure:
32
+
33
+ ```bash
34
+ ├── README.md
35
+ ├── Rakefile
36
+ ├── my_sweet_gem.gemspec
37
+ ├── lib
38
+ │   ├── my_sweet_gem
39
+ │   │   ├── some_class.rb
40
+ │   │   ├── another_class.rb
41
+ │   │   └── yet_another_class.rb
42
+ │   └── outer_file.rb
43
+ ├── templates
44
+ │   └── some_template.txt
45
+ └── spec
46
+ ```
47
+
48
+ If I want to read `templates/some_template.txt` from within
49
+ `lib/my_sweet_gem/some_class.rb`, I can do something like this:
50
+
51
+ ```ruby
52
+ File.read(apath_to('../../templates/some_template.txt'))
53
+ ```
54
+
55
+ ## Configuration
56
+
57
+ There's one downside to the default usage of FileFinder: the `apath_to`
58
+ method is defined on Kernel. It could have been defined on Object just
59
+ as easily, but that's six of one and half a dozen of the other. If this
60
+ would overwrite another method of the same name that you've written, or
61
+ you just perfer not polluting the global namespace, you can turn this
62
+ feature off with:
63
+
64
+ ```ruby
65
+ FileFinder.config do |c|
66
+ c.global_method = false
67
+ end
68
+ ```
69
+
70
+ If you've done this, you can get absolute paths with `FileFinder::File('path/to/file/here)`.
71
+
72
+ ## Known Issues
73
+
74
+ 1. If you happen to already have a method, `apath_to` defined on Kernel,
75
+ setting the `global_method` configuration option to `true` more than
76
+ once will forever overwrite the original method. The current solution to
77
+ this problem is the alternate setting the `global_method`
78
+ configuration option between `true` and `false` if you intend to change
79
+ it on the fly. Really, you should only be setting this option once.
80
+
81
+ ## Todo
82
+
83
+ 1. Write specs
84
+ 2. Solve known issue
85
+
86
+ ## Contributing
87
+
88
+ 1. Fork it ( https://github.com/loganhasson/file_finder/fork )
89
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
90
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
91
+ 4. Push to the branch (`git push origin my-new-feature`)
92
+ 5. Create a new Pull Request
93
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'file_finder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "file_finder"
8
+ spec.version = FileFinder::VERSION
9
+ spec.authors = ["Logan Hasson"]
10
+ spec.email = ["logan.hasson@gmail.com"]
11
+ spec.summary = "Utility for loading support files within gems."
12
+ spec.homepage = "http://github.com/loganhasson/file_finder.git"
13
+ spec.license = "MIT"
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.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'file_finder/version'
2
+ require 'file_finder/configuration'
3
+ require 'file_finder/finder'
4
+ require 'reset_kernel'
5
+
6
+ module FileFinder
7
+ class << self
8
+ attr_writer :configuration
9
+ end
10
+
11
+ def self.configuration
12
+ @configuration ||= FileFinder::Configuration.new
13
+ end
14
+
15
+ def self.config
16
+ yield configuration
17
+ end
18
+ end
19
+
@@ -0,0 +1,29 @@
1
+ require 'file_finder/finder'
2
+
3
+ module FileFinder
4
+ class Configuration
5
+
6
+ def global_method=(value)
7
+ if value == false || value == 'false'
8
+ unset_kernel_method
9
+ elsif value == true || value == 'true'
10
+ reset_kernel_method
11
+ else
12
+ raise FileFinder::InvalidConfigOptionError, "global_method= accepts either `true` or `false`"
13
+ end
14
+ end
15
+
16
+ def unset_kernel_method
17
+ load "#{FileFinder::File('../unset_kernel.rb')}"
18
+ end
19
+
20
+ def reset_kernel_method
21
+ load "#{FileFinder::File('../reset_kernel.rb')}"
22
+ end
23
+
24
+ end
25
+
26
+ InvalidConfigOptionError = Class.new(StandardError)
27
+
28
+ end
29
+
@@ -0,0 +1,28 @@
1
+ require 'pathname'
2
+
3
+ module FileFinder
4
+
5
+ def self.File(path)
6
+ FileFinder::Finder.get_absolute_path_to(path, Kernel.caller.first.match(/(.*):.*:.*/)[1])
7
+ end
8
+
9
+ class Finder
10
+ attr_reader :path, :configuration, :calling_file
11
+
12
+ def self.get_absolute_path_to(path, calling_file = __FILE__)
13
+ new(path, calling_file).absolute_path
14
+ end
15
+
16
+ def initialize(path, calling_file)
17
+ @path = path
18
+ @calling_file = calling_file
19
+ end
20
+
21
+ def absolute_path
22
+ Pathname.new(File.join(File.dirname(File.expand_path(calling_file)), path)).expand_path.to_s
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,3 @@
1
+ module FileFinder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'file_finder/finder.rb'
2
+
3
+ module Kernel
4
+ if self.respond_to?(:apath_to)
5
+ alias original_apath_to apath_to
6
+
7
+ class << self
8
+ alias original_apath_to apath_to
9
+ end
10
+ end
11
+
12
+ private
13
+ module_function def apath_to(path)
14
+ FileFinder::Finder.get_absolute_path_to(path, Kernel.caller.first.match(/(.*):.*:.*/)[1])
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Kernel
2
+ if self.respond_to?(:apath_to)
3
+ remove_method :apath_to
4
+
5
+ class << self
6
+ remove_method :apath_to
7
+ end
8
+
9
+ if self.respond_to?(:original_apath_to)
10
+ alias apath_to original_apath_to
11
+
12
+ class << self
13
+ alias apath_to original_apath_to
14
+ end
15
+ end
16
+ end
17
+ end
18
+
File without changes
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file_finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Logan Hasson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-23 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - logan.hasson@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - file_finder.gemspec
68
+ - lib/file_finder.rb
69
+ - lib/file_finder/configuration.rb
70
+ - lib/file_finder/finder.rb
71
+ - lib/file_finder/version.rb
72
+ - lib/reset_kernel.rb
73
+ - lib/unset_kernel.rb
74
+ - spec/.keep
75
+ homepage: http://github.com/loganhasson/file_finder.git
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Utility for loading support files within gems.
99
+ test_files:
100
+ - spec/.keep