Sha256: 5767214cc39271179272631a83e66c90489b53fc7f1ff5e5e88c676e7cdf9398

Contents?: true

Size: 802 Bytes

Versions: 1

Compression:

Stored size: 802 Bytes

Contents

module Jaysus
  module Local
    def self.store_dir
      @store_dir ||= Pathname.new('.')
    end
    
    def self.store_dir=(dir)
      @store_dir = Pathname.new(dir)
    end
    
    def self.included(base)
      base.extend(ClassMethods)
    end
    
    def destroy
      super do
        store_file.delete
        self
      end
    end
    
    def save
      super do
        store_file.open('w') do |file|
          file.write(self.to_json)
        end
        self
      end
    end
    
    module ClassMethods
      def all
        records = []
        Dir[store_file_dir.join('*')].each do |id|
          records << find(id)
        end
        records
      end

      def find(id)
        super do
          store_file_dir.join("#{id}").read
        end
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jaysus-0.1.4 lib/jaysus/local.rb