Class: MarkdownServer::CsvBrowser::RowContext::StateHash
- Inherits:
-
Object
- Object
- MarkdownServer::CsvBrowser::RowContext::StateHash
- Defined in:
- lib/markdown_server/csv_browser/row_context.rb
Overview
Hash wrapper that allows symbol OR string key access, so handlers can write ‘ctx.state` regardless of JSON round-trip. Values are plain JSON-serializable objects (the round-trip strips Ruby symbols —use strings for step identifiers).
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(h) ⇒ StateHash
constructor
A new instance of StateHash.
- #key?(key) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(h) ⇒ StateHash
Returns a new instance of StateHash.
120 121 122 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 120 def initialize(h) @h = h.is_a?(Hash) ? h : {} end |
Class Method Details
.wrap(h) ⇒ Object
113 114 115 116 117 118 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 113 def self.wrap(h) return new({}) if h.nil? return h if h.is_a?(StateHash) new(h) end |
Instance Method Details
#[](key) ⇒ Object
124 125 126 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 124 def [](key) @h[key] || @h[key.to_s] || @h[key.to_sym] end |
#[]=(key, value) ⇒ Object
128 129 130 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 128 def []=(key, value) @h[key.to_s] = value end |
#empty? ⇒ Boolean
140 141 142 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 140 def empty? @h.empty? end |
#key?(key) ⇒ Boolean
132 133 134 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 132 def key?(key) @h.key?(key) || @h.key?(key.to_s) || @h.key?(key.to_sym) end |
#to_h ⇒ Object
136 137 138 |
# File 'lib/markdown_server/csv_browser/row_context.rb', line 136 def to_h @h.dup end |