Class: Operations::Form::Attribute

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/operations/form/attribute.rb

Overview

The main purpose is to infer attribute properties from the related model. We need it to automate form rendering for the legacy UI.

Instance Method Summary collapse

Instance Method Details

#model_attributeObject



22
23
24
25
26
# File 'lib/operations/form/attribute.rb', line 22

def model_attribute
  return @model_attribute if defined?(@model_attribute)

  @model_attribute = model_class && (model_name.to_s.split("#").second.presence || name.to_s)
end

#model_classObject



16
17
18
19
20
# File 'lib/operations/form/attribute.rb', line 16

def model_class
  return @model_class if defined?(@model_class)

  @model_class = model_name.is_a?(String) ? model_name.split("#").first.constantize : model_name
end

#model_human_name(options = {}) ⇒ Object



32
33
34
# File 'lib/operations/form/attribute.rb', line 32

def model_human_name(options = {})
  model_class.human_attribute_name(model_attribute, options) if model_name
end

#model_typeObject



28
29
30
# File 'lib/operations/form/attribute.rb', line 28

def model_type
  model_class.type_for_attribute(model_attribute) if model_name
end

#model_validatorsObject



36
37
38
# File 'lib/operations/form/attribute.rb', line 36

def model_validators
  model_name ? model_class.validators_on(model_attribute) : []
end