Sha256: eaa4545f93453978be6aab5abe2bb660f4ef5038a94e09f5990575b34d61c623

Contents?: true

Size: 514 Bytes

Versions: 4

Compression:

Stored size: 514 Bytes

Contents

module Hybag
  class Validator
    include ActiveModel::Validations
    validate :bag_valid
    validate :require_persisted
    attr_reader :bag

    def initialize(bag)
      @bag = bag
    end

    def validate!
      unless self.valid?
        raise Hybag::InvalidBaggable.new(bag)
      end
    end

    def bag_valid
      errors.add(:bag, "is not valid for bagging.") unless bag.baggable?
    end

    def require_persisted
      errors.add(:bag, "is not persisted.") unless bag.persisted?
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hybag-0.2.0 lib/hybag/validator.rb
hybag-0.1.1 lib/hybag/validator.rb
hybag-0.1.0 lib/hybag/validator.rb
hybag-0.0.11 lib/hybag/validator.rb