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.15 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.36 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.14 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.35 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.13 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.34 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.12 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.33 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.11 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.10 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.32 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.9 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.31 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.8 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.30 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.7 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.29 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.6 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.28 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.5 app/services/workarea/save_taxonomy.rb