Class: Alchemy::Node
- Inherits:
-
BaseRecord
- Object
- ActiveRecord::Base
- BaseRecord
- Alchemy::Node
- Defined in:
- app/models/alchemy/node.rb
Constant Summary collapse
- VALID_URL_REGEX =
/\A(\/|\D[a-z+\d.-]+:)/- SKIPPED_ATTRIBUTES_ON_COPY =
%w[id created_at updated_at creator_id updater_id lft rgt depth parent_id]
Constants included from SearchableResource
SearchableResource::SEARCHABLE_COLUMN_TYPES
Class Method Summary collapse
- .all_from_clipboard(clipboard) ⇒ Object
- .available_menu_names ⇒ Object
- .copy_and_paste(source, new_parent, new_name) ⇒ Object
-
.language_root_nodes ⇒ Object
Returns all root nodes for current language.
Instance Method Summary collapse
-
#name ⇒ Object
Returns the name.
- #to_partial_path ⇒ Object
-
#url ⇒ Object
Returns the url.
Methods included from ConfigMissing
Methods included from SearchableResource
#ransackable_associations, #ransackable_attributes, #ransackable_scopes, #ransortable_attributes
Class Method Details
.all_from_clipboard(clipboard) ⇒ Object
71 72 73 74 75 |
# File 'app/models/alchemy/node.rb', line 71 def all_from_clipboard(clipboard) return [] if clipboard.blank? where(id: clipboard.collect { |n| n["id"] }) end |
.available_menu_names ⇒ Object
67 68 69 |
# File 'app/models/alchemy/node.rb', line 67 def read_definitions_file end |
.copy_and_paste(source, new_parent, new_name) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/alchemy/node.rb', line 77 def copy_and_paste(source, new_parent, new_name) # Prevent pasting a node as a child of itself or any of its descendants return if new_parent && source.is_or_is_ancestor_of?(new_parent) attributes = source.attributes.except(*SKIPPED_ATTRIBUTES_ON_COPY).merge( name: new_name, parent: new_parent, language: new_parent&.language || source.language ) node = create!(attributes) # Copy all descendants source.children.each do |child| copy_and_paste(child, node, child.name) end node end |
Instance Method Details
#name ⇒ Object
Returns the name
Either the value is stored in the database or, if attached, the values comes from a page.
55 56 57 |
# File 'app/models/alchemy/node.rb', line 55 def name read_attribute(:name).presence || page&.name end |
#to_partial_path ⇒ Object
128 129 130 |
# File 'app/models/alchemy/node.rb', line 128 def to_partial_path "alchemy/menus/#{}/node" end |
#url ⇒ Object
Returns the url
Either the value is stored in the database, aka. an external url. Or, if attached, the values comes from a page.
124 125 126 |
# File 'app/models/alchemy/node.rb', line 124 def url page&.url_path || read_attribute(:url).presence end |