Class: Workarea::SetNavigable

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

Defined Under Namespace

Classes: MissingSlugMapEntry

Instance Method Summary collapse

Constructor Details

#initialize(taxon, params) ⇒ SetNavigable

Returns a new instance of SetNavigable.



12
13
14
15
# File 'app/services/workarea/set_navigable.rb', line 12

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

Instance Method Details

#existing_navigable?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/services/workarea/set_navigable.rb', line 22

def existing_navigable?
  @params[:navigable_type].present? && @params[:navigable_id].present?
end


42
43
44
45
46
47
48
49
50
# File 'app/services/workarea/set_navigable.rb', line 42

def navigable
  assert_navigable_class if navigable?

  if new_navigable?
    navigable_class.create!(name: @params[:new_navigable_name])
  elsif existing_navigable?
    navigable_class.find(@params[:navigable_id])
  end
end

Returns:

  • (Boolean)


26
27
28
# File 'app/services/workarea/set_navigable.rb', line 26

def navigable?
  new_navigable? || existing_navigable?
end


38
39
40
# File 'app/services/workarea/set_navigable.rb', line 38

def navigable_class
  slug_map[slug] if slug.present?
end

#new_navigable?Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'app/services/workarea/set_navigable.rb', line 17

def new_navigable?
  @params[:new_navigable_type].present? &&
    @params[:new_navigable_name].present?
end

#setObject



52
53
54
# File 'app/services/workarea/set_navigable.rb', line 52

def set
  @taxon.navigable = navigable
end

#slugObject



30
31
32
33
34
35
36
# File 'app/services/workarea/set_navigable.rb', line 30

def slug
  if new_navigable?
    @params[:new_navigable_type]
  elsif existing_navigable?
    @params[:navigable_type]
  end
end