Class: Releaf::Content::Node::ParentValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/releaf/content/node/parent_validator.rb

Overview

Validator to test if node is valid, when created under given parrent node

validator needs :for and :under options, both can be either array of classes or single class.

:for option specifies for which nodes validation should be applied

:under option specifies under which nodes given node can be added

Examples:


class Node < ActiveRecord::Base
  includes Releaf::Content::Node
  validates_with Releaf::Content::Node::ParentValidator, for: [Text, Book], under: Store
end

Instance Method Summary collapse

Instance Method Details

#validate(node) ⇒ Object



21
22
23
24
25
# File 'app/validators/releaf/content/node/parent_validator.rb', line 21

def validate node
  @node = node
  node.errors.add(:content_type, 'invalid parent node') unless node_parent_valid?
  remove_instance_variable(:@node)
end