Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

DataPaths is a library to manage the paths to data/ directories within projects.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gemtest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .yardopts
Octocat-spinner-32 ChangeLog.md
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 data_paths.gemspec
Octocat-spinner-32 gemspec.yml
README.md

data_paths

Description

DataPaths is a library to manage the paths of directories containing static-content across multiple libraries.

For example, DataPaths can manage the data/ directories of multiple RubyGems, in much the same way RubyGems manages the paths of lib/ directories using $LOAD_PATH.

Features

  • Allows libraries to register static-content directories using the register_data_path class or instance method.
  • Allows libraries to unregister a single path using unregister_data_path or all paths registered by that library with unregister_data_paths.
  • Provides helper methods in {DataPaths::Finders} for searching through the registered static-content directories.
  • Does not use global variables.

Examples

Register a directory containing static-content:

require 'data_paths'

module MyLibrary
  include DataPaths

  # define the data dir(s)
  register_data_path File.join(File.dirname(__FILE__),'..','..','data')
end

List previously registered static-content directories:

# all data directories
DataPaths.paths
# => [...]

# the data directories registeed in MyLibrary
MyLibrary.data_paths
# => [...]

# list data directories registered in an object
lib = MyLibrary.new
lib.register_data_path File.join('path','to','data')

lib.data_paths
# => [...]

Using {DataPaths::Finders} to access content from within the static-content directories:

module MyLibrary
  class UsesContent

    include DataPaths::Finders

    def index
      find_data_file('index.html')
    end

    def file_dirs
      all_data_dirs('extra')
    end

  end
end

Install

$ gem install data_paths

Copyright

Copyright (c) 2011-2012 Hal Brodigan

See {file:LICENSE.txt} for license information.

Something went wrong with that request. Please try again.