Skip to content

tsalzer/richfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Richfile

A simple gem which adds some additional methods to File objects.

Install

gem install tsalzer-richfile --source http://gems.github.com

What is Richfile?

Richfile extends the Ruby built-in File instances with some sometimes useful attributes.

  • size attribute to cache the file size in a File object

  • OpenSSL digest attributes like md5 and sha1 (for all available digests)

Note that there is no built-in magic to keep the once-fetched attributes in sync with the effective attributes of the real files.

Usage

You simple require richfile:

require 'richfile'

Now, every new File object has a list of additional attributes. Whenever you access the attributes the first time, the data is pulled from the file system and cached in the File object.

If you need to refresh the data, either call refresh!, which updates every attribute you used before, or refresh_all!, which updates each of the cached attributes. When you are just interested in a single attribute, call the attribute with an added bang (like size!).

Building a new Gem

To create a new gem, you need to install the jeweler gem (see github.com/technicalpickles/jeweler/tree/master). If this is done, you can easily build a new gemspec with

rake gemspec
gem build richfile.gemspec

This would create a new richfile-x.y.z.gem, which can easily be installed via

gem install richfile-x.y.z.gem

License

The richfile gem comes to you under the MIT License. You should find the license text in the file MIT-LICENSE in the gem folder.

About

adds some useful attributes to Ruby File objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages