Module: CampingFlash

Defined in:
lib/tarpaulin/camping/flash.rb

Overview

monkey patch Camping to work with rack-flash

include the CampingFlash module in TheApp

> Use ClassName.instance_eval to define class methods.

> Use ClassName.class_eval to define instance methods.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tarpaulin/camping/flash.rb', line 11

def self.included(base)
  Camping::H.class_eval do
    def diff(other)
      self.keys.inject({}) do |memo, key|
        unless self[key] == other[key]
          memo[key] = [self[key], other[key]] 
        end
        memo
      end
    end
  end
end

Instance Method Details

#initialize(env, m) ⇒ Object

:nodoc:



47
48
49
50
# File 'lib/tarpaulin/camping/flash.rb', line 47

def initialize(env, m) #:nodoc:
  super(env,m)
  @_state = @state.clone
end

#to_aObject

:nodoc:



24
25
26
27
28
29
30
# File 'lib/tarpaulin/camping/flash.rb', line 24

def to_a #:nodoc:
  if @state.respond_to? :diff
    diff = @_state.diff(@state)
    diff.each {|k,v| @env['rack.session'].delete(k) }
  end
  super
end