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.



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

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.



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

def datas
  @datas
end

Instance Method Details

#show_panel(b = nil) ⇒ Boolean

Parameters:

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

Returns:

  • (Boolean)


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

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)


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

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)


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

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


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

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>)


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

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