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

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.



16
17
18
# File 'app/models/linked_rails/form/field_factory.rb', line 16

def field_options
  @field_options
end

#formObject

Returns the value of attribute form.



16
17
18
# File 'app/models/linked_rails/form/field_factory.rb', line 16

def form
  @form
end

#keyObject

Returns the value of attribute key.



16
17
18
# File 'app/models/linked_rails/form/field_factory.rb', line 16

def key
  @key
end

Instance Method Details

#condition_or_fieldObject



26
27
28
29
30
31
32
33
# File 'app/models/linked_rails/form/field_factory.rb', line 26

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