Class: Riddler::UseCases::AdminPreviewStep

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, preview_context_data: {}) ⇒ AdminPreviewStep

Returns a new instance of AdminPreviewStep.



6
7
8
9
10
11
# File 'lib/riddler/use_cases/admin_preview_step.rb', line 6

def initialize definition, preview_context_data: {}
  @definition = definition
  @preview_context_data = preview_context_data
  @context = ::Riddler::Context.new preview_context_data
  @step = ::Riddler::Step.for definition, context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#definitionObject (readonly)

Returns the value of attribute definition.



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

def definition
  @definition
end

#preview_context_dataObject (readonly)

Returns the value of attribute preview_context_data.



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

def preview_context_data
  @preview_context_data
end

#stepObject (readonly)

Returns the value of attribute step.



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

def step
  @step
end

Instance Method Details

#processObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/riddler/use_cases/admin_preview_step.rb', line 13

def process
  if step.include?
    hash = step.to_hash
    return hash unless hash.nil?

    {
      response_code: 204,
      message: "There was no step to include"
    }
  else
    {
      response_code: 204,
      include_predicate: step.include_predicate,
      message: "Excluded - the include_predicate returned false"
    }
  end
end