Class: Airview::FieldDefinition
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Airview::FieldDefinition
- Defined in:
- app/models/airview/field_definition.rb
Instance Method Summary collapse
Instance Method Details
#default_visible? ⇒ Boolean
18 19 20 |
# File 'app/models/airview/field_definition.rb', line 18 def default_visible? .fetch("default_visible", true) end |
#schema_backed? ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/airview/field_definition.rb', line 41 def schema_backed? model_class = resource_definition.model_class case field_type.to_sym when :belongs_to belongs_to_schema_backed?(model_class) when :has_many association = model_class.reflect_on_association(name.to_sym) association&.macro == :has_many when :attachment (model_class).include?(name.to_s) else model_class.column_names.include?(name.to_s) end rescue ActiveRecord::StatementInvalid, NameError false end |
#stale? ⇒ Boolean
22 23 24 |
# File 'app/models/airview/field_definition.rb', line 22 def stale? !schema_backed? end |
#stale_reason ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/airview/field_definition.rb', line 26 def stale_reason return nil if schema_backed? case field_type.to_sym when :belongs_to "Missing belongs_to association or foreign key" when :has_many "Missing has_many association" when :attachment "Missing attachment" else "Missing column" end end |