Sha256: 6d60f9a015e2838b71f21722a16350c5aaaabfba43a6dbd67cf4ea0d1e89d1f2

Contents?: true

Size: 704 Bytes

Versions: 6

Compression:

Stored size: 704 Bytes

Contents

class ModelStub
  def errors
    @errors ||= {}
  end

  def save
    self.class.before_validate.each{|block| instance_eval &block}

    if errors.empty?
      # save
      self.class.after_save.each{|block| instance_eval &block}
      true
    else
      false
    end
  end

  def destroy
    self.class.before_validate.each{|block| instance_eval &block}

    if errors.empty?
      # save
      self.class.after_destroy.each{|block| instance_eval &block}
      true
    else
      false
    end
  end

  class << self
    def before_validate
      @before_validate ||= []
    end

    def after_save
      @after_save ||= []
    end

    def after_destroy
      @after_destroy ||= []
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
file_model-0.0.6 spec/spec_helper/model_stub.rb
file_model-0.0.5 spec/spec_helper/model_stub.rb
file_model-0.0.4 spec/spec_helper/model_stub.rb
file_model-0.0.3 spec/spec_helper/model_stub.rb
file_model-0.0.2 spec/spec_helper/model_stub.rb
file_model-0.0.1 spec/spec_helper/model_stub.rb