Module: StackableFlash

Defined in:
lib/stackable_flash.rb,
lib/stackable_flash/config.rb,
lib/stackable_flash/railtie.rb,
lib/stackable_flash/version.rb,
lib/stackable_flash/flash_stack.rb,
lib/stackable_flash/stack_layer.rb

Defined Under Namespace

Modules: StackLayer Classes: Config, FlashStack, Railtie

Constant Summary collapse

VERSION =
"0.0.4"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.stackingObject

Returns the value of attribute stacking.



13
14
15
# File 'lib/stackable_flash.rb', line 13

def stacking
  @stacking
end

Class Method Details

.flashing(options, &block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/stackable_flash.rb', line 49

def self.flashing(options, &block)
  return false unless block_given?
  original = StackableFlash.stacking
  StackableFlash.stacking = options[:forcing]
  yield
  StackableFlash.stacking = original
end

.not_stacked(&block) ⇒ Object

Regardless of the value of StackableFlash.stacking you can do a local override to force non-stacking.

StackableFlash.not_stacked do

flash[:notice] = 'a simple string'  # Use flash as if this gem did not exist
flash[:notice] = ''                 # will overwrite the string above
flash[:notice] # => ''

end



43
44
45
46
47
# File 'lib/stackable_flash.rb', line 43

def self.not_stacked &block
  flashing({:forcing => false}) do
    yield
  end
end

.stacked(config_options = {}, &block) ⇒ Object

Regardless of the value of StackableFlash.stacking you can do a local override to force stacking.

StackableFlash.stacked do

flash[:notice] = 'a simple string'  # Use flash as if this gem did not exist
flash[:notice] = 'another'          # will stack the strings
flash[:notice] # => ['a simple string','another'],
               #    but returned as "a simple string<br/>another" with default config

end



26
27
28
29
30
31
32
33
# File 'lib/stackable_flash.rb', line 26

def self.stacked(config_options = {}, &block)
  flashing({:forcing => true}) do
    original = StackableFlash::Config.config.dup
    StackableFlash::Config.config.merge!(config_options)
    yield
    StackableFlash::Config.config = original
  end
end