Class: EmbeddableModelConfig

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/embeddable_model_config.rb

Constant Summary collapse

IGNORED_ATTRIBUTES =
%w[id created_at updated_at].freeze
BOOLEAN_ATTRIBUTES =
%w[tree_based?
always_display_tag_indicator?
embeddable_applet?
embeddable_image?
requires_rendering?].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_embeddable_modelsObject



26
27
28
# File 'app/models/embeddable_model_config.rb', line 26

def self.all_embeddable_models
  all.map(&:embeddable_model)
end

.attributesObject



20
21
22
23
24
# File 'app/models/embeddable_model_config.rb', line 20

def self.attributes
  @attributes ||= (attribute_names -
                   IGNORED_ATTRIBUTES +
                   BOOLEAN_ATTRIBUTES).map(&:to_sym)
end

.ckeditor_allowed_content_rulesObject



14
15
16
17
18
# File 'app/models/embeddable_model_config.rb', line 14

def self.ckeditor_allowed_content_rules
  ckeditor_config.map do |selector, content|
    [selector, content]
  end.to_h
end

.ckeditor_configObject



10
11
12
# File 'app/models/embeddable_model_config.rb', line 10

def self.ckeditor_config
  pluck :embeddable_tag_selector, :ckeditor_allowed_content
end

.embeddable_applet_modelsObject



34
35
36
# File 'app/models/embeddable_model_config.rb', line 34

def self.embeddable_applet_models
  where(embeddable_applet: true).map(&:embeddable_model)
end

.embeddable_image_modelsObject



30
31
32
# File 'app/models/embeddable_model_config.rb', line 30

def self.embeddable_image_models
  where(embeddable_image: true).map(&:embeddable_model)
end

.embeddable_tree_based_modelsObject



38
39
40
# File 'app/models/embeddable_model_config.rb', line 38

def self.embeddable_tree_based_models
  where(tree_based: true).map(&:embeddable_model)
end

.for_model(embeddable_model) ⇒ Object



42
43
44
# File 'app/models/embeddable_model_config.rb', line 42

def self.for_model(embeddable_model)
  find_by! embeddable_model_name: embeddable_model.model_name.name
end

Instance Method Details

#embeddable_modelObject



46
47
48
# File 'app/models/embeddable_model_config.rb', line 46

def embeddable_model
  embeddable_model_name.constantize
end

#styled_indicator_selector(tree_node: nil) ⇒ Object



50
51
52
53
54
# File 'app/models/embeddable_model_config.rb', line 50

def styled_indicator_selector(tree_node: nil)
  return embeddable_tag_name unless tree_based? && tree_node.present?

  "#{embeddable_tag_name}[data-tree-ref-id=\"#{tree_node.ref_id}\"]".html_safe
end