Module: ActiveFields::FieldConcern

Extended by:
ActiveSupport::Concern
Included in:
ActiveFields::Field::Base
Defined in:
app/models/concerns/active_fields/field_concern.rb

Overview

Model mix-in with a base logic for the active fields model

Instance Method Summary collapse

Instance Method Details

#available_customizable_typesObject

Returns customizable types that allow this field type.

NOTE:

  • The customizable model must be loaded to appear in this list. Relationships between customizable models and field types are established in the ‘has_active_fields` method, which is typically called within the customizable model. If eager loading is enabled, there should be no issues. However, if eager loading is disabled (common in development), the list will remain incomplete until all customizable models are loaded.

  • Code reloading may behave incorrectly at times. Restart your application if you make changes to the allowed types list in ‘has_active_fields`.



108
109
110
# File 'app/models/concerns/active_fields/field_concern.rb', line 108

def available_customizable_types
  ActiveFields.registry.customizable_types_for(type_name).to_a
end

#customizable_modelObject



81
82
83
# File 'app/models/concerns/active_fields/field_concern.rb', line 81

def customizable_model
  customizable_type.safe_constantize
end

#default_valueObject



89
90
91
# File 'app/models/concerns/active_fields/field_concern.rb', line 89

def default_value
  value_caster.deserialize(default_value_meta["const"])
end

#default_value=(v) ⇒ Object



85
86
87
# File 'app/models/concerns/active_fields/field_concern.rb', line 85

def default_value=(v)
  default_value_meta["const"] = value_caster.serialize(v)
end

#type_nameObject



93
94
95
# File 'app/models/concerns/active_fields/field_concern.rb', line 93

def type_name
  ActiveFields.config.fields.key(type)
end