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.4.27 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.4 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.26 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.3 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.25 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.2 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.24 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.1 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.23 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.22 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.0 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.21 app/services/workarea/save_taxonomy.rb
workarea-core-3.5.0.beta.1 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.20 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.19 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.18 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.17 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.16 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.15 app/services/workarea/save_taxonomy.rb
workarea-core-3.4.14 app/services/workarea/save_taxonomy.rb