File: paths.rb

package info (click to toggle)
ruby-hitimes 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 388 kB
  • sloc: ruby: 1,196; ansic: 418; java: 265; makefile: 15
file content (53 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#--
# Copyright (c) 2008 Jeremy Hinegardner
# All rights reserved.  See LICENSE and/or COPYING for details.
#++
#
module Hitimes
  #
  # Access to various paths inside the project programatically
  #
  module Paths
    #   
    # :call-seq:
    #    Hitimes::Paths.root_dir -> String
    #
    # Returns The full expanded path of the parent directory of +lib+
    # going up the path from the current file.  A trailing File::SEPARATOR 
    # is guaranteed.
    #   
    def self.root_dir
      @root_dir ||=(
        path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR)
        lib_index  = path_parts.rindex("lib")
        @root_dir = path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR
      )
    end 

    # 
    # :call-seq:
    #   Hitimes::Paths.lib_path( *args ) -> String
    #
    # Returns The full expanded path of the +lib+ directory below
    # _root_dir_.  All parameters passed in are joined onto the 
    # result. A trailing File::SEPARATOR is guaranteed if 
    # _args_ are *not* present.
    #   
    def self.lib_path(*args)
      self.sub_path("lib", *args)
    end 

    #
    # :call-seq:
    #   Hitimes::Paths.sub_path( sub, *args ) -> String
    #
    # Returns the full expanded path of the +sub+ directory below _root_dir.  All
    # _arg_ parameters passed in are joined onto the result.  A trailing
    # File::SEPARATOR is guaranteed if _args_ are *not* present.
    #
    def self.sub_path(sub,*args)
      sp = ::File.join(root_dir, sub) + File::SEPARATOR
      sp = ::File.join(sp, *args) if args
    end
  end
end