module Rack::WebProfiler::Collector::DSL::ClassMethods

Attributes

definition[R]

Public Instance Methods

collect(&block) click to toggle source
# File lib/rack/web_profiler/collector.rb, line 41
def collect(&block); definition.collect = block; end
icon(icon = nil) click to toggle source

Set the icon of the {Rack::WebProfiler::Collector}.

@param icon [String, nil]

# File lib/rack/web_profiler/collector.rb, line 25
def icon(icon = nil); definition.icon = icon; end
identifier(identifier = nil) click to toggle source

Set the identifier of the {Rack::WebProfiler::Collector}.

@param identifier [String, nil]

# File lib/rack/web_profiler/collector.rb, line 30
def identifier(identifier = nil); definition.identifier = identifier; end
is_enabled?(is_enabled = true) click to toggle source

Tell if the {Rack::WebProfiler::Collector} is enabled.

@param is_enabled [Boolean, Block]

# File lib/rack/web_profiler/collector.rb, line 55
def is_enabled?(is_enabled = true)
  definition.is_enabled = Proc.new if block_given?
  definition.is_enabled = is_enabled
end
label(label = nil) click to toggle source

Set the label of the {Rack::WebProfiler::Collector}.

@param label [String, nil]

# File lib/rack/web_profiler/collector.rb, line 35
def label(label = nil); definition.label = label; end
position(position = nil) click to toggle source
# File lib/rack/web_profiler/collector.rb, line 38
def position(position = nil); definition.position = position.to_i; end
template(template = nil, type: :file) click to toggle source

Set the template of the {Rack::WebProfiler::Collector}.

@param template [String, nil] @option type [Symbol] :file or :DATA

# File lib/rack/web_profiler/collector.rb, line 47
def template(template = nil, type: :file)
  template = get_data_contents(template) if type == :DATA
  definition.template = template
end

Private Instance Methods

get_data_contents(path) click to toggle source
# File lib/rack/web_profiler/collector.rb, line 62
def get_data_contents(path)
  data = ""
  ::File.open(path, "rb") do |f|
    begin
      line = f.gets
    end until line.nil? || /^__END__$/ === line
    data << line while line = f.gets
  end
  data
end