Module: Harrods

Extended by:
Presenter
Defined in:
lib/harrods.rb,
lib/harrods/web.rb,
lib/harrods/logger.rb,
lib/harrods/tracer.rb,
lib/harrods/version.rb,
lib/harrods/database.rb,
lib/harrods/presenter.rb,
lib/harrods/middleware.rb,
lib/harrods/redis_client.rb,
lib/harrods/configuration.rb,
lib/harrods/basic_middleware.rb

Defined Under Namespace

Modules: Presenter, RedisClient Classes: BasicMiddleware, Configuration, Database, Logger, Middleware, Tracer, Web

Constant Summary collapse

VERSION =
"0.0.3"

Constants included from Presenter

Presenter::G, Presenter::K, Presenter::M, Presenter::T

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Presenter

present_storage_size, present_with_commas

Class Attribute Details

.configObject

Returns the value of attribute config.



15
16
17
# File 'lib/harrods.rb', line 15

def config
  @config
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:



18
19
20
21
# File 'lib/harrods.rb', line 18

def self.configure(&block)
  self.config ||= Configuration.new
  yield(config)
end

.for_your_pleasure(request, type = "average") ⇒ Object



49
50
51
52
# File 'lib/harrods.rb', line 49

def self.for_your_pleasure(request, type="average")
  stats = RedisClient.send("#{type}_stats", request)
  puts stats
end

.how_much?(&block) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/harrods.rb', line 23

def self.how_much?(&block)
  start_ram, start_objects = begin_analysis
  used_ram, used_objects = nil, nil
  begin
    yield
  ensure
    used_ram, used_objects = end_analysis(start_ram, start_objects)
    log(used_ram, used_objects)
  end
  return [used_ram, used_objects]
end

.log(used_ram, used_objects, type = :log) ⇒ Object



61
62
63
# File 'lib/harrods.rb', line 61

def self.log(used_ram, used_objects, type=:log)
  puts "\e[#{35}m#{message(used_ram, used_objects, type)}\e[0m"
end

.message(ram, objects, type) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/harrods.rb', line 65

def self.message(ram, objects, type)
  case type
  when :log
    "[HARRODS::DEBUG] Instantiated: #{present_with_commas(objects)} Objects, using #{present_storage_size(ram)} of Heap Size"
  when :average
    "[HARRODS::AVERAGE] Average for call: #{present_with_commas(objects)} Objects, using  #{present_storage_size(ram)} of Heap Size"
  end
end

.personalised_service(request, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/harrods.rb', line 35

def self.personalised_service(request, &block)
  start_ram, start_objects = begin_analysis
  used_ram, used_objects   = nil, nil
  begin
    yield
  ensure
    used_ram, used_objects = end_analysis(start_ram, start_objects)
    RedisClient.average_log request, used_ram, used_objects
    log(used_ram, used_objects)
    report_average(request)
  end
  return [used_ram, used_objects]
end

.report_average(request) ⇒ Object



56
57
58
59
# File 'lib/harrods.rb', line 56

def self.report_average(request)
  average = RedisClient.get_average_for(request)
  log(average["ram"], average["objects"], :average)
end