Class: Crystal::Processors::PrepareFlash

Inherits:
Crystal::Processor show all
Defined in:
lib/crystal/html/processors/prepare_flash.rb

Instance Attribute Summary

Attributes inherited from Crystal::Processor

#next_processor

Instance Method Summary collapse

Methods inherited from Crystal::Processor

#initialize, inspect

Constructor Details

This class inherits a constructor from Crystal::Processor

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/crystal/html/processors/prepare_flash.rb', line 5

def call
  workspace.request.must_be.present
  workspace.params.must_be.defined
  
  previous_messages = workspace.request.session.delete 'flash'
  if previous_messages.present?
    previous_messages = JSON.load previous_messages
    crystal[:flash] = Crystal::Flash.new workspace.params.format, previous_messages
  end
  
  next_processor.call
  
  if crystal.include? :flash
    flash = crystal[:flash]
    messages = flash.messages_for_next_request
    workspace.request.must_be.present
    workspace.request.session['flash'] = messages.to_json unless messages.empty?
  end
end