Sha256: a1b730be838ff062f5c237d36b0665c814f2e285710a7fe194361c78a17811dd

Contents?: true

Size: 802 Bytes

Versions: 8

Compression:

Stored size: 802 Bytes

Contents

# frozen_string_literal: true
module C
  class MenuItem < ApplicationRecord
    has_closure_tree order: 'weight'

    validates :machine_name, presence: true
    validates :name, presence: true

    belongs_to :page

    before_validation on: :create do
      self.machine_name = name
    end

    belongs_to :page

    def self.depth_select_options(item)
      opts = []
      save_pair = proc do |level, i|
        level.each do |key, value|
          next if key.id == item.id
          opts.append(["#{'-' * i}#{key.name}", key.id])
          save_pair.call(value, i + 1) if value.class <= Hash
        end
      end
      save_pair.call(hash_tree, 0)
      opts
    end

    # Force non blank parametized machine name
    def machine_name=(val)
      super val.to_s.parameterize
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cd2_catton_cms-1.1.35 app/models/c/menu_item.rb
cd2_catton_cms-1.1.34 app/models/c/menu_item.rb
cd2_catton_cms-1.1.33 app/models/c/menu_item.rb
cd2_catton_cms-1.1.32 app/models/c/menu_item.rb
cd2_catton_cms-1.1.31 app/models/c/menu_item.rb
cd2_catton_cms-1.1.30 app/models/c/menu_item.rb
cd2_catton_cms-1.1.20 app/models/c/menu_item.rb
cd2_catton_cms-1.1.10 app/models/c/menu_item.rb