Class: Riddler::UseCases::ShowSlug

Inherits:
Object
  • Object
show all
Defined in:
lib/riddler/use_cases/show_slug.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_definition_repo:, slug_repo:, interaction_repo:, interaction_class:, slug_name:, params: {}, headers: {}) ⇒ ShowSlug

Returns a new instance of ShowSlug.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/riddler/use_cases/show_slug.rb', line 7

def initialize content_definition_repo:, slug_repo:, interaction_repo:,
  interaction_class:, slug_name:, params: {}, headers: {}

  @content_definition_repo = content_definition_repo
  @slug_repo = slug_repo
  @interaction_repo = interaction_repo
  @interaction_class = interaction_class
  @context_director = ::Riddler::ContextDirector.new params: params, headers: headers
  @slug_name = slug_name
  @slug = lookup_slug
end

Instance Attribute Details

#content_definition_repoObject (readonly)

Returns the value of attribute content_definition_repo.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def content_definition_repo
  @content_definition_repo
end

#context_directorObject (readonly)

Returns the value of attribute context_director.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def context_director
  @context_director
end

#interactionObject (readonly)

Returns the value of attribute interaction.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def interaction
  @interaction
end

#interaction_classObject (readonly)

Returns the value of attribute interaction_class.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def interaction_class
  @interaction_class
end

#interaction_repoObject (readonly)

Returns the value of attribute interaction_repo.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def interaction_repo
  @interaction_repo
end

#slugObject (readonly)

Returns the value of attribute slug.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def slug
  @slug
end

#slug_nameObject (readonly)

Returns the value of attribute slug_name.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def slug_name
  @slug_name
end

#slug_repoObject (readonly)

Returns the value of attribute slug_repo.



4
5
6
# File 'lib/riddler/use_cases/show_slug.rb', line 4

def slug_repo
  @slug_repo
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/riddler/use_cases/show_slug.rb', line 35

def completed?
  return false unless slug_defines_identity?
  find_interaction
  return false if @interaction.nil?
  @interaction.status == "COMPLETED"
end

#dismissed?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/riddler/use_cases/show_slug.rb', line 28

def dismissed?
  return false unless slug_defines_identity?
  find_interaction
  return false if @interaction.nil?
  @interaction.status == "DISMISSED"
end

#excluded?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/riddler/use_cases/show_slug.rb', line 46

def excluded?
  definition_use_case.excluded?
end

#exists?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/riddler/use_cases/show_slug.rb', line 19

def exists?
  !slug.nil?
end

#paused?Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/riddler/use_cases/show_slug.rb', line 23

def paused?
  return true if slug.nil?
  slug.status == "PAUSED"
end

#processObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/riddler/use_cases/show_slug.rb', line 50

def process
  find_interaction || create_interaction
  context.assign "interaction", interaction.to_hash

  content_hash = definition_use_case.process.merge \
    interaction_id: interaction.id,
    dismiss_url: "/interactions/#{interaction.id}/dismiss"

  interaction.content_type = content_hash[:content_type]
  interaction.content_id = content_hash[:id]

  interaction_repo.update interaction

  content_hash
end

#targeted?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/riddler/use_cases/show_slug.rb', line 42

def targeted?
  slug_targeted?
end