progressions-basepath 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -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.
data/README.md ADDED
@@ -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.
data/Rakefile ADDED
@@ -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 = "progressions-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/progressions/basepath"
12
+ gem.authors = ["Caio Chassot", "Jeff Coleman"]
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.3.0
data/lib/basepath.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'pathname'
2
+
3
+ module Basepath
4
+ extend self
5
+
6
+ def mine(file = false)
7
+ path_to_first_caller = (s = caller.last) ? s.sub(/:\d+(?::in `.*?')?$/, '') : __FILE__
8
+ path = Pathname.new(path_to_first_caller).realpath
9
+ file ? path : path.dirname
10
+ end
11
+
12
+ # used when settings consts and load_path
13
+ def const_expand!(s)
14
+ (s.sub!(RX_CONSTS, '') ? Object.const_get($1) : ::BASE_PATH).join(s);
15
+ end
16
+ end
17
+
18
+ lambda do
19
+ return if Object.const_defined?("BASE_PATH")
20
+
21
+ # find and set base
22
+ # first_path = (s = caller.last) ? s.sub(/:\d+(?::in `.*?')?$/, '') : __FILE__
23
+ # cur_path = Pathname.new(first_path).dirname.realpath
24
+ cur_path = Pathname.new(File.expand_path("./")).realpath
25
+ dot_base = '.base'
26
+ got_base = lambda { cur_path.join(dot_base).exist? }
27
+ cur_path = cur_path.parent until cur_path == cur_path.parent or got_base[]
28
+ ::BASE_PATH = got_base[] ? cur_path : raise("Can't find #{dot_base} for BASE_PATH")
29
+
30
+ # read dot_base
31
+ base_conf = IO.read(::BASE_PATH.join(dot_base)).strip.gsub(/[ \t]/, '').gsub(/\n+/, "\n")\
32
+ .scan(/^\[(\w+)\]((?:\n[^\[].*)*)/)\
33
+ .inject(Hash.new('')) { |h, (k, s)| h[k.to_sym] = s.strip; h }
34
+
35
+ # set path consts
36
+ consts = base_conf[:consts].scan(/([A-Z][A-Z0-9_]*)=(.+)/).inject({}) { |h, (k, v)| h[k] = v; h }
37
+ RX_CONSTS = /^(#{consts.keys.map(&Regexp.method(:escape)).join('|')})(?:\/|$)/
38
+ consts.each { |k, v| Object.const_set(k, Basepath.const_expand!(v)) }
39
+
40
+ # set load_paths
41
+ load_paths = base_conf[:load_paths].split("\n").map { |s|
42
+ Dir[Basepath.const_expand!(s).to_s] }.flatten.select { |s|
43
+ File.directory? s }
44
+ $LOAD_PATH.unshift(*load_paths)
45
+
46
+ # requires
47
+ loaded = caller(0).map { |s| s[/\A(.+?)(?:\.rb)?:\d+(?::in `.*?')?\z/, 1] }.compact.uniq
48
+ base_conf[:requires].split("\n").each do |lib|
49
+ rx = /\b#{Regexp.escape(lib)}\z/
50
+ break if loaded.any? { |s| s =~ rx }
51
+ require lib
52
+ end
53
+ end.call
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{progressions-basepath}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Caio Chassot", "Jeff Coleman"]
12
+ s.date = %q{2010-01-10}
13
+ s.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.}
14
+ s.email = %q{dev@caiochassot.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/basepath.rb",
27
+ "progressions-basepath.gemspec",
28
+ "spec/basepath_spec.rb",
29
+ "spec/spec_helper.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/progressions/basepath}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Define you application base path for easy requires and general access to files.}
36
+ s.test_files = [
37
+ "spec/basepath_spec.rb",
38
+ "spec/spec_helper.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<bacon>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<bacon>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<bacon>, [">= 0"])
52
+ end
53
+ end
54
+
@@ -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,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: progressions-basepath
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Caio Chassot
8
+ - Jeff Coleman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-01-10 00:00:00 -06:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bacon
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ 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.
27
+ email: dev@caiochassot.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.md
35
+ files:
36
+ - .document
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/basepath.rb
43
+ - progressions-basepath.gemspec
44
+ - spec/basepath_spec.rb
45
+ - spec/spec_helper.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/progressions/basepath
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.5
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Define you application base path for easy requires and general access to files.
74
+ test_files:
75
+ - spec/basepath_spec.rb
76
+ - spec/spec_helper.rb