public
Description: A file store for arbitrary objects, all easy-peasy.
Homepage: http://github.com/crnixon/active_files
Clone URL: git://github.com/crnixon/active_files.git
name age message
file .gitignore Sat Jun 07 18:10:26 -0700 2008 doc formatting fix [crnixon]
file History.txt Fri Jun 06 13:52:48 -0700 2008 first commit [crnixon]
file Manifest.txt Sat Jun 07 18:04:54 -0700 2008 updated to my newest gem layout [crnixon]
file README.rdoc Sat Jun 07 18:10:26 -0700 2008 doc formatting fix [crnixon]
file Rakefile Sat Jun 07 18:04:54 -0700 2008 updated to my newest gem layout [crnixon]
directory lib/ Wed Jun 11 20:07:36 -0700 2008 :order option can be passed to find - based on ... [crnixon]
directory tasks/ Sat Jun 07 18:04:54 -0700 2008 updated to my newest gem layout [crnixon]
directory test/ Sat Jun 07 18:04:54 -0700 2008 updated to my newest gem layout [crnixon]
README.rdoc

ActiveFiles

by Clinton R. Nixon

URL: http://github.com/crnixon/active_files

Description

This library attempts to implement an ActiveRecord-like interface to a directory structure of flat files containing serialized objects, probably in YAML.

Features/problems

  • Serializes any object
  • No validations yet

Requirements

To run tests, you need the spect and Shoulda gems.

Synopsis

    ActiveFiles.base_dir = '/tmp/af'

    class Person < Hash
      include ActiveFiles::Record
      add_file_id_to_initialize
    end

    class Wingdom
      include ActiveFiles::Record

      attr_reader :feathers, :color

      def initialize(id, feathers, color)
        self.file_id = id
        @feathers = feathers
        @color = color
      end

      def to_activefile
        { :plumoj => @feathers.to_s.split(//).reverse,
          :koloro => [@color, @color, @color].join('\/') }.to_yaml.reverse
      end

      def self.from_activefile(yaml, file_id)
        hash = YAML::load(yaml.reverse)
        feathers = hash[:plumoj].reverse.inject("") { |s, c| s << c }.to_i
        color = hash[:koloro].split('\/')[1]
        Wingdom.new(file_id, feathers, color)
      end
    end

    herbert = Person.new('herbert')
    herbert['address'] = '103 Choctaw Dr'
    herbert['birthday'] = Date.parse('2/4/1979')
    herbert.save

    also_herbert = Person.find("herbert")
    also_herbert = Person.find(:first, "herb*")
    herbs = Person.find("herb*")
    herbs = Person.find(:all, "herb*")

License

(ISC License)

Copyright © 2008 Clinton R. Nixon of Viget Labs

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.