Class: InertiaRails::FlashExtension::InertiaFlashScope
- Inherits:
-
Object
- Object
- InertiaRails::FlashExtension::InertiaFlashScope
- Defined in:
- lib/inertia_rails/flash_extension.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(flash_or_now) ⇒ InertiaFlashScope
constructor
A new instance of InertiaFlashScope.
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(flash_or_now) ⇒ InertiaFlashScope
Returns a new instance of InertiaFlashScope.
37 38 39 40 41 42 43 44 45 |
# File 'lib/inertia_rails/flash_extension.rb', line 37 def initialize(flash_or_now) if flash_or_now.respond_to?(:flash) @flash = flash_or_now.flash @now = true else @flash = flash_or_now @now = false end end |
Instance Method Details
#[](key) ⇒ Object
53 54 55 |
# File 'lib/inertia_rails/flash_extension.rb', line 53 def [](key) @flash[INERTIA_KEY]&.[](key.to_s) end |
#[]=(key, value) ⇒ Object
47 48 49 50 51 |
# File 'lib/inertia_rails/flash_extension.rb', line 47 def []=(key, value) @flash[INERTIA_KEY] ||= {} @flash[INERTIA_KEY][key.to_s] = value @flash.inertia_now_keys.add(key.to_s) if @now end |
#to_hash ⇒ Object Also known as: to_h
57 58 59 |
# File 'lib/inertia_rails/flash_extension.rb', line 57 def to_hash @flash[INERTIA_KEY]&.dup || {} end |