Sha256: 29da9e5ad4631a11c0a91acb31dd4a87d4e526de019f82d03bffb96c10cd290b

Contents?: true

Size: 635 Bytes

Versions: 62

Compression:

Stored size: 635 Bytes

Contents

module Workarea
  class SortNavigationMenusByOrders
    def self.perform
      new.perform
    end

    def perform
      sorted_menus.each_with_index { |m, i| m.set(position: i) }
    end

    def menus
      @menus ||= Navigation::Menu.all.to_a
    end

    def sorted_menus
      @sorted_menus ||= menus.sort_by { |m| scores[m] || 999 }.reverse
    end

    private

    def scores
      menus.reduce({}) do |memo, menu|
        memo.merge(
          menu => Metrics::MenuByDay
            .by_menu(menu.id)
            .since(Workarea.config.sorting_score_ttl.ago)
            .score(:orders)
        )
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.26 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.45 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.25 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.23 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.44 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.22 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.43 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.21 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.42 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.20 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.41 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.19 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.40 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.18 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.39 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.17 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.38 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.5.16 app/services/workarea/sort_navigation_menus_by_orders.rb
workarea-core-3.4.37 app/services/workarea/sort_navigation_menus_by_orders.rb