Class: Workarea::SaveTaxonomy

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/save_taxonomy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taxon, params) ⇒ SaveTaxonomy

Returns a new instance of SaveTaxonomy.



14
15
16
17
# File 'app/services/workarea/save_taxonomy.rb', line 14

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

Class Method Details

.build(navigable) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/services/workarea/save_taxonomy.rb', line 3

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

Instance Method Details

#performObject



19
20
21
22
23
24
# File 'app/services/workarea/save_taxonomy.rb', line 19

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

  set_taxonomy_slug
end

#set_taxonomy_slugObject



26
27
28
29
30
31
32
33
# File 'app/services/workarea/save_taxonomy.rb', line 26

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

#top_level?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/services/workarea/save_taxonomy.rb', line 35

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