Class: MarkdownServer::CsvBrowser::RowContext::StateHash

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


140
141
142
# File 'lib/markdown_server/csv_browser/row_context.rb', line 140

def empty?
  @h.empty?
end

#key?(key) ⇒ Boolean

Returns:

  • (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_hObject



136
137
138
# File 'lib/markdown_server/csv_browser/row_context.rb', line 136

def to_h
  @h.dup
end