Sha256: 8b3b8a7aea15e52fa751a9f3c41fa39aaf29cb65376eed6b085ceaa1b821b872

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require "sdbm"
require "securerandom"
require "date"
require 'csv'
require "ostruct"
require "fileutils"

require_relative "dddr/sdbm"
require_relative "dddr/sequel"
require_relative "dddr/version"

module Dddr
  ENTITIES = []

  def self.configuration
    @configuration ||= OpenStruct.new
  end

  class Serializer
    def initialize(engine)
      @engine = engine
    end

    def dump(obj)
      @engine.dump(obj)
    end

    def load(obj)
      @engine.load(obj)
    end
  end

  def self.configure
    configuration.env = ENV["DDDR_ENV"] || "development"
    configuration.data_dir = "/var/dddr"
    configuration.engine = :sdbm
    configuration.serializer = Marshal
    configuration.container = nil
    yield(configuration) if block_given?
  end

  class Error < StandardError; end

  module Entity
    def self.included(base)
      if Dddr.configuration.engine == :sdbm

        puts "Including #{base.name}"

        Dddr::ENTITIES << base

        include Dddr::Sdbm
        base.extend(Dddr::Sdbm::ClassMethods)
      end
      if Dddr.configuration.engine == :sequel
        include Dddr::Sequel
        base.extend(Dddr::Sdbm::ClassMethods)
      end
    end

    attr_accessor :uid, :created_at, :last_updated_at, :deleted, :deleted_at

    def new?
      created_at.nil?
    end
  end
end

Dddr.configure

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dddr-2.0.0 lib/dddr.rb