Class: Rack::WebProfiler::Collector::DataStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/web_profiler/collector.rb

Overview

TODO:

do DataStorage compatible with Marshal

DataStorage

Used to store datas who Collector needs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDataStorage

Returns a new instance of DataStorage.



109
110
111
112
113
114
# File 'lib/rack/web_profiler/collector.rb', line 109

def initialize
  @datas      = Hash.new
  @status     = nil
  @show_tab   = true
  @show_panel = true
end

Instance Attribute Details

#datasObject (readonly)

Returns the value of attribute datas.



107
108
109
# File 'lib/rack/web_profiler/collector.rb', line 107

def datas
  @datas
end

Instance Method Details

#show_panel(b = nil) ⇒ Boolean

Parameters:

  • b (Boolean, nil) (defaults to: nil)

Returns:

  • (Boolean)


142
143
144
145
# File 'lib/rack/web_profiler/collector.rb', line 142

def show_panel(b = nil)
  @show_panel = !!b unless b.nil?
  @show_panel
end

#show_tab(b = nil) ⇒ Boolean

Parameters:

  • b (Boolean, nil) (defaults to: nil)

Returns:

  • (Boolean)


152
153
154
155
# File 'lib/rack/web_profiler/collector.rb', line 152

def show_tab(b = nil)
  @show_tab = !!b unless b.nil?
  @show_tab
end

#status(v = nil) ⇒ Symbol?

Status.

Parameters:

  • v (Symbol, nil) (defaults to: nil)

Returns:

  • (Symbol, nil)


130
131
132
133
134
135
# File 'lib/rack/web_profiler/collector.rb', line 130

def status(v = nil)
  # @todo check status?
  # raise Exception, "" unless [:success, :warning, :danger].include?(v)
  @status = v.to_sym unless v.nil?
  @status
end

#store(k, v) ⇒ Object

Store a value.

Parameters:

  • k (String, Symbol)
  • v


120
121
122
123
# File 'lib/rack/web_profiler/collector.rb', line 120

def store(k, v)
  # @todo check data format (must be compatible with Marshal)
  @datas[k.to_sym] = v
end

#to_hHash<Symbol, Object>

Transform DataStorage to an Hash

Returns:

  • (Hash<Symbol, Object>)


160
161
162
163
164
165
166
167
# File 'lib/rack/web_profiler/collector.rb', line 160

def to_h
  {
    datas:      @datas,
    status:     @status,
    show_panel: @show_panel,
    show_tab:   @show_tab,
  }
end