Module: Trackman::Path::Resolver
- Included in:
- Rails32Resolver
- Defined in:
- lib/trackman/path/resolver.rb
Instance Method Summary collapse
- #file_exist?(path) ⇒ Boolean
- #parent_of(url) ⇒ Object
- #translate(url, parent_url) ⇒ Object
- #working_dir ⇒ Object
Instance Method Details
#file_exist?(path) ⇒ Boolean
20 21 22 |
# File 'lib/trackman/path/resolver.rb', line 20 def file_exist? path File.exists? path end |
#parent_of(url) ⇒ Object
27 28 29 |
# File 'lib/trackman/path/resolver.rb', line 27 def parent_of(url) (working_dir + url).parent end |
#translate(url, parent_url) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/trackman/path/resolver.rb', line 4 def translate url, parent_url raise "parent_url: #{parent_url} is required to be relative" if Pathname.new(parent_url).absolute? url = Pathname.new(url) unless url.is_a? Pathname parent_url = Pathname.new(parent_url) unless parent_url.is_a? Pathname if url.relative? parent = parent_of(parent_url) child = url else parent = working_dir + 'public/' child = Pathname.new(url.to_s[1..-1]) end relative_path = (parent + child).relative_path_from(working_dir).to_s file_exist?(relative_path) ? relative_path : nil end |
#working_dir ⇒ Object
23 24 25 |
# File 'lib/trackman/path/resolver.rb', line 23 def working_dir Pathname.new Dir.pwd end |