Sha256: fffc639ca37e3293dbaafe87b69ad1aa802393c52b42f142f6bd560a229668e1

Contents?: true

Size: 511 Bytes

Versions: 10

Compression:

Stored size: 511 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 "Invalid Object for bagging"
      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

10 entries across 10 versions & 1 rubygems

Version Path
hybag-0.0.10 lib/hybag/validator.rb
hybag-0.0.9 lib/hybag/validator.rb
hybag-0.0.8 lib/hybag/validator.rb
hybag-0.0.7 lib/hybag/validator.rb
hybag-0.0.6 lib/hybag/validator.rb
hybag-0.0.5 lib/hybag/validator.rb
hybag-0.0.4 lib/hybag/validator.rb
hybag-0.0.3 lib/hybag/validator.rb
hybag-0.0.2 lib/hybag/validator.rb
hybag-0.0.1 lib/hybag/validator.rb