Sha256: e95b1e8647585b08768be0f2ae55a1cb659747e1e0243df36d14cd3e36cc23a0

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

class NoneOrm
  include Blueprints::Extensions::Blueprintable

  class << self
    def add (record)
      @all ||= []
      @all << record
    end

    def destroy(record)
      @all.delete record
    end

    def count
      all.size
    end

    def all(options = {})
      Array(@all).clone.tap do |result|
        result.reject! do |record|
          options[:conditions].any? { |key, value| record.send(key) != value }
        end if options[:conditions]
      end
    end

    def first(options = {})
      all(options).first
    end

    def last(options = {})
      all(options).last
    end
  end

  def initialize #(params)
#    params.each { |param, value| instance_variable_set("@#{param}", value) }
    self.class.add(self)
  end

  def reload
    self
  end

  def destroy
    self.class.destroy(self)
  end

  def new_record?
    true
  end
end

class Fruit < NoneOrm
  attr_accessor :species, :average_diameter, :tree
end

class Tree < NoneOrm
  attr_accessor :name, :size, :fruits
end

RSpec.configure do |config|
  config.before do
    [Fruit, Tree].each do |klass|
      klass.instance_variables.each { |iv| klass.send(:remove_instance_variable, iv) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blueprints-1.0.1 spec/support/none/initializer.rb
blueprints-1.0.0 spec/support/none/initializer.rb