Class: AppRoot
- Inherits:
-
Object
- Object
- AppRoot
- Defined in:
- lib/app_root.rb,
lib/app_root/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
Class Method Summary collapse
- .called_from ⇒ Object
- .find_root_with_flag(flag, root_path) ⇒ Object
- .find_with_flag(flag) ⇒ Object (also: path)
Class Attribute Details
.default_path ⇒ Object
15 16 17 |
# File 'lib/app_root.rb', line 15 def default_path @default_path || Dir.pwd end |
Class Method Details
.called_from ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/app_root.rb', line 5 def called_from File.dirname( caller_locations.map do |l| l.absolute_path || l.path end.detect do |l| l !~ %r{lib/ruby/gems|app_root[\w.-]*/lib} end ) end |
.find_root_with_flag(flag, root_path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/app_root.rb', line 19 def find_root_with_flag(flag, root_path) while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}") parent = File.dirname(root_path) root_path = parent != root_path && parent end root = if File.exist?("#{root_path}/#{flag}") root_path else default_path end Pathname.new(File.realpath(root)) end |
.find_with_flag(flag) ⇒ Object Also known as: path
35 36 37 |
# File 'lib/app_root.rb', line 35 def find_with_flag(flag) find_root_with_flag(flag, called_from) end |