Class: OpenLoam::FieldDefinition

Inherits:
TenantRecord
  • Object
show all
Defined in:
app/models/open_loam/field_definition.rb

Overview

Runtime declaration of a migration-free field on a tenant-scoped entity — "entity_type Equipment gets a field called serial_number of type string, writable by managers only." Tenant-scoped like everything else: a field defined in one tenant is invisible to another's records of the same entity_type, and definitions are the ONLY way values in an entity's custom_fields json column get read/written (see OpenLoam::CustomFields).

Constant Summary collapse

FIELD_TYPES =
%w[string text integer decimal boolean date datetime dictionary].freeze

Instance Method Summary collapse

Instance Method Details

#dictionary_key ⇒ Object

The config json holds type-specific settings. For a "dictionary" field it carries the key of the OpenLoam::Dictionary whose entries populate the select.



29
30
31
# File 'app/models/open_loam/field_definition.rb', line 29

def dictionary_key
  config.is_a?(Hash) ? config["dictionary"] : nil
end

#dictionary_key=(value) ⇒ Object



33
34
35
36
# File 'app/models/open_loam/field_definition.rb', line 33

def dictionary_key=(value)
  base = config.is_a?(Hash) ? config : {}
  self.config = base.merge("dictionary" => value.to_s.strip.presence)
end

#readable_by?(role) ⇒ Boolean

Field-level READ gate for the runtime field, mirroring writable_roles: an empty readable_roles means any member may read it; otherwise only the listed roles. Used by OpenLoam::CustomFieldIndex (so a filter can't be an oracle on a restricted field) and OpenLoam::Policy#custom_field_readable?.

Returns:

  • (Boolean)


22
23
24
25
# File 'app/models/open_loam/field_definition.rb', line 22

def readable_by?(role)
  roles = readable_roles
  roles.blank? || (role.present? && roles.map(&:to_sym).include?(role.to_sym))
end