Class: LinkedRails::Form::FieldFactory

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/linked_rails/form/field_factory.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

DATABASE_ERRORS =
[
  'PG::ConnectionBad'.safe_constantize,
  ActiveRecord::StatementInvalid,
  ActiveRecord::ConnectionNotEstablished
].compact.freeze
MAX_STR_LEN =
255
VALIDATOR_SELECTORS =
[
  [:min_length, ActiveModel::Validations::LengthValidator, :minimum],
  [:max_length, ActiveModel::Validations::LengthValidator, :maximum],
  [:pattern, ActiveModel::Validations::FormatValidator, :with],
  [:presence, ActiveModel::Validations::PresenceValidator, nil],
  [:sh_in, ActiveModel::Validations::InclusionValidator, :in]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#field_optionsObject

Returns the value of attribute field_options.



21
22
23
# File 'app/models/linked_rails/form/field_factory.rb', line 21

def field_options
  @field_options
end

#formObject

Returns the value of attribute form.



21
22
23
# File 'app/models/linked_rails/form/field_factory.rb', line 21

def form
  @form
end

#keyObject

Returns the value of attribute key.



21
22
23
# File 'app/models/linked_rails/form/field_factory.rb', line 21

def key
  @key
end

Instance Method Details

#condition_or_fieldObject



32
33
34
35
36
37
38
39
40
41
# File 'app/models/linked_rails/form/field_factory.rb', line 32

def condition_or_field
  return field if abstract_form

  @condition_or_field ||= model_policy!.condition_for(
    key,
    field,
    property: field_options[:if] || [],
    sh_not: field_options[:unless] || []
  )
end