GithubHelp home page GithubHelp logo

history_file's Introduction

HistoryFile

Behaves like a File class and does some convenience stuff around a HistoryFile::FileDelegator instance. It lets you version files by dates. A date prefix is added to the file name.

If you want to write a file to store data from yesterday, you could write:

> f = HistoryFile[1.day.ago].new("/tmp/foo.txt", "w")
=> #<File:/tmp/2012.11.02-foo.txt>

The returned HistoryFile::FileDelegator object supports all methods that File has, but adds a date prefix to those methods that revolve around a single file (reading, writing, etc.)

If a file for a given date is not available, HistoryFile falls back to the freshest file that is older than the given date.

> f = HistoryFile[3.days.ago].new("test.txt", "w")
=> #<File:./2012.11.12-test.txt>
> f.write("I am old")
=> 8
> f.close
=> nil
> HistoryFile[Date.today].read("test.txt")
=> "I am old"
> HistoryFile[10.days.ago].read("test.txt")
Errno::ENOENT: No such file or directory - ./2012.11.05-test.txt

It does this for every method where a prefix is added and when an Errno::ENOENT is thrown.

Methods that patch all arguments with a date prefix

You can pass an arbitrary amount of arguments to these methods, but all of them are file names. So we'll go ahead and prefix all of them:

  • delete
  • unlink
  • safe_unlink

Methods that patch nothing and just delegate to File

These are mostly methods that are either not HistoryFile specific (i.e. File.join to join components with the OS dependant path separator) or where one can't dumbly prefix filenames.

  • absolute_path
  • basename
  • catname
  • chmod
  • chown
  • compare
  • copy
  • directory?
  • dirname
  • expand_path
  • extname
  • fnmatch
  • fnmatch?
  • identical?
  • install
  • join
  • lchown
  • link
  • makedirs
  • move
  • path
  • realdirpath
  • realpath
  • rename
  • split
  • umask
  • utime

Methods that add a prefix to the filename

All methods not mentioned in the previous two sections

Methods that automatically create a sub directory

If you set HistoryFile.mode = :subdir and you call one of the following methods, Historyfile will create a sub directory for the given date if it does not exist already

  • new
  • open

Tests

We use simplecov and it reports 100% coverage. Build Status

history_file's People

Contributors

bauersman avatar jayniz avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jayniz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.