basepath 0.2.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,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ basepath.gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Caio Chassot
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ Basepath
2
+ ========
3
+
4
+ Do you feel pain every time you have to dick around with relative paths?
5
+
6
+ $: << File.dirname(__FILE__) + "/lib"
7
+ require Pathname.new(__FILE__).dirname.join('../foo/bar').to_s
8
+
9
+ Oh, you don't. Ok then. You're done reading.
10
+
11
+
12
+ Usage
13
+ -----
14
+
15
+ Add an empty `.base` file to the root of your project.
16
+
17
+ When you `require 'basepath'`, it'll set `BASE_PATH` to a `Pathname` object
18
+ with the absolute path of the directory containing `.base`.
19
+
20
+
21
+ Bonus
22
+ -----
23
+
24
+ You can use the `.base` file to:
25
+
26
+ * add paths to `$LOAD_PATH`,
27
+ * add a default list of files to be required,
28
+ * initialize other `Pathname` constants.
29
+
30
+ Paths are specified relative to `BASE_PATH`.
31
+
32
+
33
+ Example
34
+ -------
35
+
36
+ A fully specified `.base` file:
37
+
38
+ [load_paths]
39
+ vendor/*/lib
40
+ lib
41
+
42
+ [requires]
43
+ yaml
44
+ active_support
45
+
46
+ [consts]
47
+ EXAMPLES_PATH = etc/examples
48
+
49
+
50
+ Copyright
51
+ ---------
52
+
53
+ Copyright © 2009 Caio Chassot. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "basepath"
8
+ gem.summary = %Q{Define you application base path for easy requires and general access to files.}
9
+ gem.description = %Q{By adding a .base file to your application base dir, helps you augment $LOAD_PATH, auto-require files, and set constants to important paths.}
10
+ gem.email = "dev@caiochassot.com"
11
+ gem.homepage = "http://github.com/kch/basepath"
12
+ gem.authors = ["Caio Chassot"]
13
+ gem.add_development_dependency "bacon", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.pattern = 'spec/**/*_spec.rb'
25
+ spec.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |spec|
31
+ spec.libs << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :spec => :check_dependencies
42
+
43
+ task :default => :spec
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "basepath #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
@@ -0,0 +1,34 @@
1
+ require 'pathname'
2
+
3
+ lambda do
4
+ return if Object.const_defined?("BASE_PATH")
5
+
6
+ # find and set base
7
+ first_path = (s = caller.last) ? s.sub(/:\d+$/, '') : __FILE__
8
+ cur_path = Pathname.new(first_path).dirname.realpath
9
+ dot_base = '.base'
10
+ got_base = lambda { cur_path.join(dot_base).exist? }
11
+ cur_path = cur_path.parent until cur_path == cur_path.parent or got_base[]
12
+ ::BASE_PATH = got_base[] ? cur_path : raise("Can't find #{dot_base} for BASE_PATH")
13
+
14
+ # read dot_base
15
+ base_conf = IO.read(::BASE_PATH.join(dot_base)).strip.gsub(/[ \t]/, '').gsub(/\n+/, "\n")\
16
+ .scan(/^\[(\w+)\]((?:\n[^\[].*)*)/)\
17
+ .inject(Hash.new('')) { |h, (k, s)| h[k.to_sym] = s.strip; h }
18
+
19
+ # set path consts
20
+ base_conf[:consts].scan(/([A-Z][A-Z0-9_]*)=(.+)/).each { |k, v| Object.const_set(k, ::BASE_PATH.join(v)) }
21
+
22
+ # set load_paths
23
+ load_paths = base_conf[:load_paths].split("\n").map { |s| Dir[::BASE_PATH.join(s).to_s] }.flatten
24
+ load_paths = load_paths.select { |s| File.directory? s }
25
+ $LOAD_PATH.unshift(*load_paths)
26
+
27
+ # requires
28
+ loaded = caller(0).map { |s| s[/\A(.+?)(?:\.rb)?:\d+(?::in `.*?')?\z/, 1] }.compact.uniq
29
+ base_conf[:requires].split("\n").each do |lib|
30
+ rx = /\b#{Regexp.escape(lib)}\z/
31
+ break if loaded.any? { |s| s =~ rx }
32
+ require lib
33
+ end
34
+ end.call
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Basepath" do
4
+ it "fails" do
5
+ should.flunk "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bacon'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'basepath'
7
+
8
+ Bacon.summary_on_exit
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basepath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Caio Chassot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 -02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bacon
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: By adding a .base file to your application base dir, helps you augment $LOAD_PATH, auto-require files, and set constants to important paths.
26
+ email: dev@caiochassot.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.md
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/basepath.rb
42
+ - spec/basepath_spec.rb
43
+ - spec/spec_helper.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/kch/basepath
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Define you application base path for easy requires and general access to files.
72
+ test_files:
73
+ - spec/basepath_spec.rb
74
+ - spec/spec_helper.rb