Module: Readorder::Paths

Extended by:
Paths
Included in:
Readorder, Paths
Defined in:
lib/readorder/paths.rb

Instance Method Summary collapse

Instance Method Details

#bin_path(*args) ⇒ Object



18
19
20
# File 'lib/readorder/paths.rb', line 18

def bin_path( *args )
  root_path( 'bin', *args )
end

#config_path(*args) ⇒ Object



45
46
47
# File 'lib/readorder/paths.rb', line 45

def config_path( *args )
  home_path( "config", *args )
end

#data_path(*args) ⇒ Object



49
50
51
# File 'lib/readorder/paths.rb', line 49

def data_path( *args )
  home_path( "data", *args )
end

#home_dirObject

The home dir is the home directory of the project while it is running by default, this the same as the root_dir. But if this value is set then it affects other paths



33
34
35
# File 'lib/readorder/paths.rb', line 33

def home_dir
  @home_dir ||= root_dir
end

#home_dir=(other) ⇒ Object



37
38
39
# File 'lib/readorder/paths.rb', line 37

def home_dir=( other )
  @home_dir = File.expand_path( other )
end

#home_path(sub, *args) ⇒ Object



41
42
43
# File 'lib/readorder/paths.rb', line 41

def home_path( sub, *args )
  sub_path( home_dir, sub, *args )
end

#lib_path(*args) ⇒ Object



22
23
24
# File 'lib/readorder/paths.rb', line 22

def lib_path( *args )
  root_path( "lib", *args )
end

#log_path(*args) ⇒ Object



53
54
55
# File 'lib/readorder/paths.rb', line 53

def log_path( *args )
  home_path( "log", *args )
end

#root_dirObject

The root directory of the project is considered to be the parent directory of the ‘lib’ directory.



6
7
8
9
10
11
12
# File 'lib/readorder/paths.rb', line 6

def root_dir
  @root_dir ||= (
    path_parts = ::File.expand_path(__FILE__).split(::File::SEPARATOR)
    lib_index  = path_parts.rindex("lib")
    path_parts[0...lib_index].join(::File::SEPARATOR) + ::File::SEPARATOR
  )
end

#root_path(sub, *args) ⇒ Object



14
15
16
# File 'lib/readorder/paths.rb', line 14

def root_path( sub, *args )
  sub_path( root_dir, sub, *args )
end

#spec_path(*args) ⇒ Object



26
27
28
# File 'lib/readorder/paths.rb', line 26

def spec_path( *args )
  root_path( "spec", *args )
end

#sub_path(parent, sub, *args) ⇒ Object



61
62
63
64
# File 'lib/readorder/paths.rb', line 61

def sub_path( parent, sub, *args )
  sp = ::File.join( parent, sub ) + File::SEPARATOR
  sp = ::File.join( sp, *args ) if args
end

#tmp_path(*args) ⇒ Object



57
58
59
# File 'lib/readorder/paths.rb', line 57

def tmp_path( *args )
  home_path( "tmp", *args )
end