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
50 51 52 53 54 |
# File 'app/models/alchemy/node.rb', line 50 def all_from_clipboard(clipboard) return [] if clipboard.blank? where(id: clipboard.collect { |n| n["id"] }) end |
.available_menu_names ⇒ Object
46 47 48 |
# File 'app/models/alchemy/node.rb', line 46 def read_definitions_file end |
.copy_and_paste(source, new_parent, new_name) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/alchemy/node.rb', line 56 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 |
.language_root_nodes ⇒ Object
Returns all root nodes for current language
40 41 42 43 44 |
# File 'app/models/alchemy/node.rb', line 40 def language_root_nodes raise "No language found" if Current.language.nil? roots.where(language_id: Current.language.id) 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.
34 35 36 |
# File 'app/models/alchemy/node.rb', line 34 def name read_attribute(:name).presence || page&.name end |
#to_partial_path ⇒ Object
107 108 109 |
# File 'app/models/alchemy/node.rb', line 107 def to_partial_path "alchemy/menus/#{menu_type}/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.
103 104 105 |
# File 'app/models/alchemy/node.rb', line 103 def url page&.url_path || read_attribute(:url).presence end |