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

dire

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dire

  • 0.1.5
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Dire

Simple Pathname wrapper that provides convenient and safe interface for filesystem traversal.

Useful in situations where you need to accept parameters from external sources (like HTTP request) or read data from potentially unsafe directory structure (containing symbolic links).

Main Features:

  • simple interface,
  • easy to test,
  • restrict access to selected directory (paths, links),
  • content type recognition (binary, mime),
  • ignore pattern support.

Sample Usage:

Restrict access to directory:

root = Dire.root 'path/to/dir'
=> #<Dire::Dir>

Basic Dire::Dir methods:

dir = root.get 'path/to/subdir'
=> #<Dire::Dir>

dir.dirs
=> [#<Dire::Dir>, #<Dire::Dir>, ...]

dir.files
=> [#<Dire::File>, #<Dire::File>, ...]

root.list
=> [#<Dire::Dir>, #<Dire::File>, ...]

Basic Dire::File methods:

file = dir.get 'path/to/file.txt'
=> #<Dire::File>

# check data encoding
file.binary?
=> false

# get MimeMagic (mimemagic gem)
file.mime
=> #<MimeMagic>

# inverse of binary
file.text?
=> true

Common Dire::Node methods:

# associated Pathname (for IO use)
file.path
=> #<Pathname>

# alias of path
file.absolute_path
=> #<Pathname>

# relative as string
file.param
=> #<String>

# relative to root
file.relative_path
=> #<Pathname>

Ignore patterns:

Dire::IGNORE << 'globbing/pattern'

# raises Dire::Error::InvalidPath
dir.get 'path/matching/pattern'

For more information check lib and test.

Rails Usage:

Add dire gem.

Add route:

get 'controller_path(/:path_parameter)',
  as: 'route_name',
  to: 'controller_name#action_name',
  constraints: { path: /.+/ },
  format: false

Force HTML:

before_action :force_html, only: 'action_name'

def force_html
 request.format = :html
end

FAQs

Package last updated on 26 May 2023

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