Sha256: 17cb4362b59500c403ae6f9bf5ea31cb08486c90f3dd934d3b166551711cd04e

Contents?: true

Size: 738 Bytes

Versions: 86

Compression:

Stored size: 738 Bytes

Contents

module Avo
  module Fields
    module Concerns
      module IsRequired
        extend ActiveSupport::Concern

        def is_required?
          if required.respond_to? :call
            Avo::Hosts::ResourceViewRecordHost.new(block: required, record: model, view: view, resource: resource).handle
          else
            required.nil? ? required_from_validators : required
          end
        end

        private

        def required_from_validators
          return false if model.nil?

          validators.any? do |validator|
            validator.is_a? ActiveModel::Validations::PresenceValidator
          end
        end

        def validators
          model.class.validators_on(id)
        end
      end
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
avo-2.53.0 lib/avo/fields/concerns/is_required.rb
avo-2.52.0 lib/avo/fields/concerns/is_required.rb
avo-2.49.0 lib/avo/fields/concerns/is_required.rb
avo-2.48.0 lib/avo/fields/concerns/is_required.rb
avo-2.47.0 lib/avo/fields/concerns/is_required.rb
avo-2.46.0 lib/avo/fields/concerns/is_required.rb
avo-2.45.0 lib/avo/fields/concerns/is_required.rb
avo-2.44.0 lib/avo/fields/concerns/is_required.rb
avo-2.43.0 lib/avo/fields/concerns/is_required.rb
avo-2.42.2 lib/avo/fields/concerns/is_required.rb
avo-2.42.1 lib/avo/fields/concerns/is_required.rb
avo-2.42.0 lib/avo/fields/concerns/is_required.rb
avo-2.41.0 lib/avo/fields/concerns/is_required.rb
avo-2.40.0 lib/avo/fields/concerns/is_required.rb
avo-2.39.0 lib/avo/fields/concerns/is_required.rb
avo-2.38.0 lib/avo/fields/concerns/is_required.rb
avo-2.37.2 lib/avo/fields/concerns/is_required.rb
avo-2.37.1 lib/avo/fields/concerns/is_required.rb
avo-2.37.0 lib/avo/fields/concerns/is_required.rb
avo-2.36.3 lib/avo/fields/concerns/is_required.rb