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,
lib/stackable_flash/test_helpers.rb,
lib/stackable_flash/rspec_matchers.rb

Defined Under Namespace

Modules: RspecMatchers, StackLayer, TestHelpers Classes: Config, FlashStack, Railtie

Constant Summary collapse

VERSION =
'0.1.1'

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



61
62
63
64
65
66
67
# File 'lib/stackable_flash.rb', line 61

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'  # You can continue to use flash as if this gem did not exist
flash[:notice] << 'another'         # will concatenate the strings
flash[:notice]                      # => "a simple stringanother"
flash[:notice].stack                # => "a simple stringanother"
flash[:notice] = ''                 # will overwrite everything above, and set back to empty string

end



55
56
57
58
59
# File 'lib/stackable_flash.rb', line 55

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'  # You can continue to use flash as if this gem did not exist
   flash[:notice] << 'another'         # will stack the strings
   flash[:notice]                      # => ['a simple string','another'],
   # Uses the default :stack_with_proc to transform
   flash[:notice].stack                # => "a simple string<br/>another" (default config uses <br/>),
   flash[:notice] = ''                 # will overwrite everything above, and set back to empty string
end

StackableFlash.stacked({:stack_with_proc => Proc.new {|arr| arr.map! {|x| "<p>#{x}</p>"}.join } } ) do
  flash[:error] = 'original'
  flash[:error] << 'message'
  flash[:error]        # => ['original','message']
  # Uses the custom :stack_with_proc above to transform
  flash[:error].stack  # => '<p>original</p><p>message</p>'
end


36
37
38
39
40
41
42
43
# File 'lib/stackable_flash.rb', line 36

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