Class Scrivener
In: lib/scrivener/validations.rb
lib/scrivener.rb
Parent: Object

Methods

_accessors   attributes   new   slice  

Included Modules

Validations

Classes and Modules

Module Scrivener::Validations

Constants

VERSION = "1.1.0"

Public Class methods

Initialize with a hash of attributes and values. Extra attributes are discarded.

@example

  class EditPost < Scrivener
    attr_accessor :title
    attr_accessor :body

    def validate
      assert_present :title
      assert_present :body
    end
  end

  edit = EditPost.new(title: "Software Tools")

  edit.valid? #=> false

  edit.errors[:title] #=> []
  edit.errors[:body]  #=> [:not_present]

  edit.body = "Recommended reading..."

  edit.valid? #=> true

  # Now it's safe to initialize the model.
  post = Post.new(edit.attributes)
  post.save

Public Instance methods

Return hash of attributes and values.

[Validate]