Class: Workarea::Navigation::Taxon

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Tree, Mongoid::Tree::Ordering, Mongoid::Tree::Traversal, ApplicationDocument
Defined in:
app/models/workarea/navigation/taxon.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.rootObject



45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/workarea/navigation/taxon.rb', line 45

def self.root
  super || begin
    taxon = new(
      name: I18n.t('workarea.storefront.layouts.home'),
      url: Storefront::Engine.routes.url_helpers.root_path
    )

    taxon.instance_variable_set(:@allow_root, true)
    taxon.tap(&:save!)
  end
end

Instance Method Details

#active?Boolean

Whether this taxon should be shown in the storefront, dependent on it’s navigable being active.

Returns:

  • (Boolean)


116
117
118
# File 'app/models/workarea/navigation/taxon.rb', line 116

def active?
  !navigable? || !navigable.respond_to?(:active?) || navigable.active?
end

#has_children?Boolean

Whether this taxon has any children. Uses the counter cache defined in #children_count. This method exists only as a performance improvement over the ‘taxon.children.any?`.

Returns:

  • (Boolean)


63
64
65
# File 'app/models/workarea/navigation/taxon.rb', line 63

def has_children?
  children_count > 0
end

#in_menu?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/workarea/navigation/taxon.rb', line 107

def in_menu?
  menu.present?
end


103
104
105
# File 'app/models/workarea/navigation/taxon.rb', line 103

def menu
  Menu.where(taxon_id: id).first
end

#move_to_position(new_position) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/workarea/navigation/taxon.rb', line 67

def move_to_position(new_position)
  new_position = new_position.to_i

  if new_position == 0
    move_to_top
  elsif sibling = siblings.find_by(position: new_position) rescue nil
    move_above(sibling)
  else
    move_to_bottom
  end
end

Returns:

  • (Boolean)


87
88
89
# File 'app/models/workarea/navigation/taxon.rb', line 87

def navigable?
  navigable_id.present?
end

#placeholder?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/workarea/navigation/taxon.rb', line 83

def placeholder?
  !navigable? && !url?
end

#resource_nameObject



91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/workarea/navigation/taxon.rb', line 91

def resource_name
  ActiveSupport::StringInquirer.new(
    if placeholder?
      'placeholder'
    elsif url?
      'url'
    else
      navigable_type.constantize.model_name.element
    end
  )
end

#search_results?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'app/models/workarea/navigation/taxon.rb', line 125

def search_results?
  navigable.is_a?(SearchResults)
end

#touchObject



120
121
122
123
# File 'app/models/workarea/navigation/taxon.rb', line 120

def touch
  navigable.touch if navigable.present?
  super
end

#url?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/workarea/navigation/taxon.rb', line 79

def url?
  url.present?
end