Sha256: 062d920afe64e9a71140f92ec1acaa266d4febd7b20a84cb47abee55daa00fe8

Contents?: true

Size: 539 Bytes

Versions: 9

Compression:

Stored size: 539 Bytes

Contents

module PhModel
  module Concerns
    # Validates factories.
    module ValidatedFactory
      extend ActiveSupport::Concern

      included do |model|
        class << model
          private :new
        end
      end

      # Validates factories.
      module ClassMethods
        def build(*args)
          new(*args).tap do |model|
            unless model.valid?
              raise ValidationFailed, "#{name} is invalid: #{model.errors.full_messages.join("\n")}"
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ph_model-1.2.0 lib/ph_model/concerns/validated_factory.rb
ph_model-1.1.3 lib/ph_model/concerns/validated_factory.rb
ph_model-1.1.2 lib/ph_model/concerns/validated_factory.rb
ph_model-1.1.1 lib/ph_model/concerns/validated_factory.rb
ph_model-1.1.0 lib/ph_model/concerns/validated_factory.rb
ph_model-1.0.2 lib/ph_model/concerns/validated_factory.rb
ph_model-1.0.1 lib/ph_model/concerns/validated_factory.rb
ph_model-1.0.0 lib/ph_model/concerns/validated_factory.rb
ph_model-0.0.1 lib/ph_model/concerns/validated_factory.rb