New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

relative

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relative

  • 1.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= relative

  • Project Page: http://rubyforge.org/projects/relative/

== DESCRIPTION: The relative library enhances Ruby's core and standard libraries to support naming, opening, and reading files relative to the Ruby file currently being interpreted (the contents of the __ FILE __ identifier). This functionality is especially useful in embedded Ruby (eruby, erb, erubis, etc.) where absolute paths or paths relative to the interpreter's current working directory are problematic (due to file system structures and working directories varying across platforms and web servers).

== FEATURES

  • The File.expand_path_relative_to_caller class method that expands paths relative to the calling file (analogous to File.expand_path, which expands paths relative to the interpreter's current working directory)
  • The Kernel#require_relative instance method that allows Ruby modules to be imported with paths relative to the calling file
  • The Pathname#expand_path_relative_to_caller instance method that returns a new Pathname object created by expanding the receiver Pathname relative to the calling file (analogous to Pathname.expand_path, which expands a Pathname relative to the interpreter's current working directory)
  • The PathRelativeToCaller class, instances of which are constructed with a path relative to the calling file and can be passed into all of the core and standard Ruby I/O methods (IO.read, File.open, etc). A PathRelativeToCaller instance expands the relative path with which it is initialized and evaluates to the absolute path in I/O methods; it makes the relative path accessible through an attribute accessor, however.

== PROBLEMS: None (known).

== SYNOPSIS: ======examples/example.rb: #!/usr/bin/env ruby require 'rubygems' require 'relative'

relative_path = "../Rakefile"

print("====================================================================\n") print("The absolute path of #{relative_path} (relative to #{FILE}):\n") print("#{File.expand_path_relative_to_caller(relative_path)}\n") print("====================================================================\n") print("The Pathname of #{relative_path} (relative to #{FILE}):\n") print("#{Pathname.new(relative_path).expand_path_relative_to_caller()}\n") print("====================================================================\n") print("The contents of #{relative_path} (relative to #{FILE}):\n") print("#{IO.read(PathRelativeToCaller.new(relative_path))}") print("====================================================================\n")

This example shows the use of File.expand_path_relative_to_caller to expand +../Rakefile+ relative to the path of the example script, +examples/example.rb+. It also illustrates how Pathname#expand_path_relative_to_caller can return an expansion of the receiver Pathname (+../Rakefile+) relative to +examples/example.rb+. Finally, it demonstrates that a PathRelativeToCaller object can be passed into ordinary File and IO methods, within which it will evaluate to an absolute expansion of +../Rakefile+ (the path with which it was initialized) relative to +examples/example.rb+ (the source file that constructed the PathRelativeToCaller instance).

== RECOMMENDATIONS: This gem works very well with the erbextensions gem (http://erbextensions.rubyforge.org). The erbextensions gem provides a method to include the expanded contents of one erb file within another erb file; it often is best to use a path relative to the containing erb file to refer to the erb file to be included.

== REQUIREMENTS: Hoe is required but only for running the tests.

== INSTALL: sudo gem install relative

== AUTHORS: === Designing Patterns

== SUPPORT: Please post questions, concerns, or requests for enhancement to the forums on the project page. Alternatively, direct contact information for Designing Patterns can be found on the project page for this gem.

== ENHANCEMENTS: Please feel free to contact us with any ideas; we will try our best to enhance the software and respond to user requests. Of course, we are more likely to work on a particular enhancement if we know that there are users who want it. Designing Patterns provides contracting and consulting services, so if there is an enhancement that must get done (and in a specified time frame), please inquire about retaining our services!

== LICENSE: The license text can be found in the +LICENSE+ file at the root of the distribution.

This package is licensed with an MIT license:

Copyright (c) 2008-2009 Designing Patterns

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

== SHARE AND ENJOY!

FAQs

Package last updated on 17 Jan 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc