Sha256: 106c3dce4f1ce5474f21d7f9356cefae713035bbcfe3f0ff33d94e5519a68050

Contents?: true

Size: 630 Bytes

Versions: 43

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

require_relative 'validator_builder'

module MyConcern
  extend ActiveSupport::Concern

  class_methods do
    def validate(*fields, expected_class)
      builder = ::ValidationBuilder.new(self, expected: expected_class)

      validatable_fields.concat(fields)
      builder.add_accessors(fields)

      fields.each do |field|
        builder.add_validation(field)
      end

      builder.build
    end

    def validatable_fields
      @validatable_fields ||= []
    end
  end

  def valid?
    self.class.validatable_fields.all? do |field|
      public_send("#{field}_valid?")
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/support/models/my_concern.rb
sinclair-2.1.0 spec/support/models/my_concern.rb
sinclair-2.0.1 spec/support/models/my_concern.rb
sinclair-2.0.0 spec/support/models/my_concern.rb
sinclair-1.16.3 spec/support/models/my_concern.rb
sinclair-1.16.2 spec/support/models/my_concern.rb
sinclair-1.16.1 spec/support/models/my_concern.rb
sinclair-1.16.0 spec/support/models/my_concern.rb
sinclair-1.15.0 spec/support/models/my_concern.rb
sinclair-1.14.2 spec/support/models/my_concern.rb
sinclair-1.14.1 spec/support/models/my_concern.rb
sinclair-1.14.0 spec/support/models/my_concern.rb
sinclair-1.13.0 spec/support/models/my_concern.rb
sinclair-1.12.1 spec/support/models/my_concern.rb
sinclair-1.12.0 spec/support/models/my_concern.rb
sinclair-1.11.0 spec/support/models/my_concern.rb
sinclair-1.10.0 spec/support/models/my_concern.rb
sinclair-1.9.0 spec/support/models/my_concern.rb
sinclair-1.8.0 spec/support/models/my_concern.rb
sinclair-1.7.0 spec/support/models/my_concern.rb