Module: Ore::Paths

Includes:
Naming
Included in:
Project, RubyGems
Defined in:
lib/ore/paths.rb

Overview

A mixin for Project which provides methods for working with paths.

Instance Method Summary collapse

Methods included from Naming

#module_of, #modules_of, #names_in, #namespace_dirs_of, #namespace_of, #namespace_path_of, #underscore

Instance Method Details

#bin_dirPathname

The bin/ directory of the project.

Returns:

  • (Pathname)

    The path to the bin/ directory.



29
30
31
# File 'lib/ore/paths.rb', line 29

def bin_dir
  @root.join(@@lib_dir)
end

#directory?(path) ⇒ Boolean

Determines if a directory exists within the project.

Parameters:

  • path (String)

    The path of the directory, relative to the project.

Returns:

  • (Boolean)

    Specifies whether the directory exists in the project.



85
86
87
# File 'lib/ore/paths.rb', line 85

def directory?(path)
  @root.join(path).directory?
end

#each_path(paths) {|path| ... } ⇒ Object

Iterates over the paths.

@ since 0.1.3

Parameters:

  • paths (Array<String>, String)

    The paths or path glob pattern to iterate over.

Yields:

  • (path)

    The given block will be passed each individual path.

Yield Parameters:

  • path (String)

    An individual path.



160
161
162
163
164
165
166
167
# File 'lib/ore/paths.rb', line 160

def each_path(paths,&block)
  case paths
  when Array
    paths.each(&block)
  else
    glob(paths,&block)
  end
end

#file?(path) ⇒ Boolean

Determines if a file exists within the project.

Parameters:

  • path (String)

    The path of the file, relative to the project.

Returns:

  • (Boolean)

    Specifies whether the file exists in the project.



98
99
100
# File 'lib/ore/paths.rb', line 98

def file?(path)
  @project_files.include?(path)
end

#glob(pattern) {|path| ... } ⇒ Object

Finds paths within the project that match a glob pattern.

Parameters:

  • pattern (String)

    The glob pattern.

Yields:

  • (path)

    The given block will be passed matching paths.

Yield Parameters:

  • path (String)

    A path relative to the root directory of the project.



136
137
138
139
140
141
142
143
144
# File 'lib/ore/paths.rb', line 136

def glob(pattern)
  within do
    Dir.glob(pattern) do |path|
      if (@project_files.include?(path) || File.directory?(path))
        yield path
      end
    end
  end
end

#lib_dirPathname

The lib/ directory of the project.

Returns:

  • (Pathname)

    The path to the lib/ directory.



39
40
41
# File 'lib/ore/paths.rb', line 39

def lib_dir
  @root.join(@@lib_dir)
end

#lib_directory?(path) ⇒ Boolean

Determines if a directory exists within the lib/ directory of the project.

Returns:

  • (Boolean)

    Specifies that the directory exists within the lib/ directory.



109
110
111
# File 'lib/ore/paths.rb', line 109

def lib_directory?(path)
  directory?(File.join(@@lib_dir,path))
end

#lib_file?(path) ⇒ Boolean

Determines if a file exists within the lib/ directory of the project.

Returns:

  • (Boolean)

    Specifies that the file exists within the lib/ directory.



120
121
122
# File 'lib/ore/paths.rb', line 120

def lib_file?(path)
  file?(File.join(@@lib_dir,path))
end

#lib_path(*names) ⇒ Pathname

Builds a path relative to the lib/ directory.

Parameters:

  • names (Array)

    The directory names of the path.

Returns:

  • (Pathname)

    The new path.



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

def lib_path(*names)
  path(@@lib_dir,*names)
end

#path(*names) ⇒ Pathname

Builds a path relative to the project.

Parameters:

  • names (Array)

    The directory names of the path.

Returns:

  • (Pathname)

    The new path.



19
20
21
# File 'lib/ore/paths.rb', line 19

def path(*names)
  @root.join(*names)
end

#pkg_dirPathname

The pkg/ directory of the project.

Returns:

  • (Pathname)

    The path to the pkg/ directory.



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

def pkg_dir
  @root.join(@@pkg_dir)
end

#pkg_fileString

Builds a relative path into the pkg/ directory for the .gem file.

Returns:

  • (String)

    The path of a .gem file for the project.



72
73
74
# File 'lib/ore/paths.rb', line 72

def pkg_file
  File.join(@@pkg_dir,"#{@name}-#{@version}.gem")
end