Sha256: aca0f87f4c457abe89e6b5a06bffa55e11fd7f82fb6e85d19326d1ee603da563

Contents?: true

Size: 1006 Bytes

Versions: 62

Compression:

Stored size: 1006 Bytes

Contents

module Workarea
  class SaveTaxonomy
    def self.build(navigable)
      navigable.taxon || navigable.build_taxon(
        name: navigable.name,

        # These two fields necessary because Mongoid isn't setting them
        # automatically :(
        navigable_type: navigable.class.name,
        navigable_id: navigable.id
      )
    end

    def initialize(taxon, params)
      @taxon = taxon
      @params = params
    end

    def perform
      @taxon.update_attributes!(parent_id: @params[:parent_id])
      @taxon.move_to_position(@params[:position]) if @params[:position].present?

      set_taxonomy_slug
    end

    def set_taxonomy_slug
      Release.with_current(nil) do
        Sidekiq::Callbacks.disable(RedirectNavigableSlugs) do
          slug = FindTaxonomySlug.new(@taxon.navigable, @taxon).slug
          @taxon.navigable.update_attributes!(slug: slug) if slug.present?
        end
      end
    end

    def top_level?
      @taxon.parent == Navigation::Taxon.root
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

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