A simple gem which adds some additional methods to File objects.
gem install tsalzer-richfile --source http://gems.github.com
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
andsha1
(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.
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!
).
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
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.