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.

Notes:

  • 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`.



101
102
103
# File 'app/models/concerns/active_fields/field_concern.rb', line 101

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

#customizable_modelObject



74
75
76
# File 'app/models/concerns/active_fields/field_concern.rb', line 74

def customizable_model
  customizable_type.safe_constantize
end

#default_valueObject



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

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

#default_value=(v) ⇒ Object



78
79
80
# File 'app/models/concerns/active_fields/field_concern.rb', line 78

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

#type_nameObject



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

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