overnight 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjUzOWUxNDQ5ZjQ4NDNkNWM1YjZiMDY2NGZiMzY3NWZiODQ3OWUwYg==
4
+ MzU0NmJhOTVkZGY3NWYwNjViNTY5NjE3OTAwZGNmNDBjOTA1MWNhNA==
5
5
  data.tar.gz: !binary |-
6
- MzIxODk2OGUxMGUxN2QyZWM3OGE3ZWM5ZWQ5ZGZkNmU3YjE5ZjU0Zg==
6
+ YjEyNjUwNTU3MGFkMTM5NWJmYzFiOWNmMmNlMmE5Yjg2ZDQyMGI3Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWYxYjQzZjM5NzVmMWYwNzFiYjVjNTBiZTZhYjM4YjVmM2ExY2JhYjgxNjQ1
10
- ZTNhYzI2MDBlZjMyOWExY2FmZmQzNTMyYmQ4Y2Y0ZGI5MWNhYTg2ODlmNGZj
11
- NjQ4MWM2ZmQxNzYxZWY1MjgzZTg0OTdiNGE0MWE3MWNiMjYwYTY=
9
+ NmVjZGM4MzljODU5YjI5YWMxODhlMGE4ZWYxMGY3YjVjNjJiMGM0MWUwODE4
10
+ OTM5NmNmN2E0YzUxNTg1ZGZmOWQwOGMzZGEyMjEwOGUyZTM5N2FlNDAwYWU2
11
+ OGE3ZmI5MjRiZGVmZDRmOWQ0ZjBhYjdhYWMyZDUxMTcyZWVlY2U=
12
12
  data.tar.gz: !binary |-
13
- YTI3MWI1MTA4OTZiNmMzNzRmZjA1MTI2NWZhZWExZTEzMDU5ZTNkMzM5MDYx
14
- Njc2ZDBkODdjYmFlYmExMDU1YmRmNjhkZWFjYzE5OGRiMTY0MTRlMTg2MzE1
15
- YzZkYTVlYmVhYjA4OTJjMGE2MzczZmJiOWE0NTM5NDg5YWIzOWY=
13
+ NjU1YWNmMzc5ODExYWQ3MTAyODE0NzI3MWUzZDVlZGYzMmJhZDNkOTRjODBj
14
+ ODFlYzBkMGQ5YjljN2JjOTM4NWYyMDdjNDdlYjM0YzIxY2YxODNjOGNjZThj
15
+ ODZjNzc0YmFiNDhlOTczNzU5YzJlMTM3MjVlYWJiODU1MTA3Yjc=
@@ -1,28 +1 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.
1
+ == Overnight
@@ -1,5 +1,7 @@
1
1
  module Overnight
2
- autoload :Timey, 'overnight/timey'
3
2
  autoload :Timer, 'overnight/timer'
4
3
  autoload :OvernightService, 'overnight/overnight_service'
4
+ autoload :Report, 'overnight/report'
5
+ autoload :ReportBuilder, 'overnight/report_builder'
6
+ autoload :MethodTimer, 'overnight/mixins/method_timer'
5
7
  end
@@ -0,0 +1,41 @@
1
+ module Overnight
2
+ module MethodTimer
3
+
4
+ def self.included(base_class)
5
+ methods = base_class.instance_methods(false) + base_class.private_instance_methods(false)
6
+ base_class.class_eval do
7
+ methods.each do |method_name|
8
+ old_method = instance_method(method_name)
9
+ define_method(method_name) do |*args, &block|
10
+ logged_name = Overnight::MethodTimer.timer_name(base_class.name + "_" + method_name.to_s)
11
+ OvernightService.start_timer(logged_name)
12
+ result = old_method.bind(self).call(*args, &block)
13
+ OvernightService.stop_timer(logged_name)
14
+ return result
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.timer_name(name)
21
+ name.scan(/[A-Z][a-z_]*/).join("_").downcase.to_sym
22
+ end
23
+
24
+ # module MethodLogger
25
+ # def self.included(base)
26
+ # methods = base.instance_methods(false) + base.private_instance_methods(false)
27
+ # base.class_eval do
28
+ # methods.each do |method_name|
29
+ # original_method = instance_method(method_name)
30
+ # define_method(method_name) do |*args, &block|
31
+ # Rails.logger.info "-> #{base}##{method_name}(#{args.inspect})"
32
+ # return_value = original_method.bind(self).call(*args, &block)
33
+ # Rails.logger.info "<- #{base}##{method_name} #=> #{return_value.inspect}"
34
+ # return_value
35
+ # end
36
+ # end
37
+ # end
38
+ # end
39
+ # end
40
+ end
41
+ end
@@ -2,28 +2,35 @@ module Overnight
2
2
  class OvernightService
3
3
  @@timers = {}
4
4
 
5
+ # start a timer with a name
6
+ # if a name is not selected, then a random one will be assigned
5
7
  def self.start_timer(timer_name = nil)
6
8
  timer_name ||= self.random_timer_name
7
9
  @@timers[timer_name] = Timer.new.start
8
10
  return @@timers[timer_name]
9
11
  end
10
12
 
13
+ # stops a timer with either the actual timer or the name
14
+ # just in case there wasnt a name passed when the timer was started
11
15
  def self.stop_timer(timer)
12
-
16
+ (@@timers[timer] || @@timers.values.select{|e| e == timer}.first).stop
13
17
  end
14
18
 
19
+ # get all of the timers
15
20
  def self.timers
16
21
  return @@timers
17
22
  end
18
23
 
24
+ # get a single timer by name
19
25
  def self.get_timer(timer_name)
20
26
  return @@timers[timer_name]
21
27
  end
22
28
 
23
29
  private
24
30
 
31
+ # the random timer name generator
25
32
  def self.random_timer_name
26
- (0...8).map { (65 + rand(26)).chr }.join.to_sym
33
+ (0...16).map { (65 + rand(26)).chr }.join.to_sym
27
34
  end
28
35
  end
29
36
  end
@@ -0,0 +1,11 @@
1
+ module Overnight
2
+ class Report
3
+ def initialize
4
+ @report = File.new 'profile', 'w'
5
+ end
6
+
7
+ def write(line)
8
+ @report.syswrite(line)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Overnight
2
+ class ReportBuilder
3
+
4
+ end
5
+ end
@@ -1,11 +1,19 @@
1
1
  module Overnight
2
2
  class Timer
3
+ attr_reader :start_time, :end_time
4
+
3
5
  def start
4
- @start_time = Timey.new
6
+ @start_time ||= Time.now
7
+ self
8
+ end
9
+
10
+ def stop
11
+ @end_time ||= Time.now
12
+ self
5
13
  end
6
14
 
7
- def end
8
- @end_time = Timey.new
15
+ def elapsed_time
16
+ @end_time - @start_time
9
17
  end
10
18
  end
11
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overnight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan L. Davis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-06 00:00:00.000000000 Z
11
+ date: 2014-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,9 +47,11 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - README.rdoc
49
49
  - lib/overnight.rb
50
+ - lib/overnight/mixins/method_timer.rb
50
51
  - lib/overnight/overnight_service.rb
52
+ - lib/overnight/report.rb
53
+ - lib/overnight/report_builder.rb
51
54
  - lib/overnight/timer.rb
52
- - lib/overnight/timey.rb
53
55
  homepage: https://github.com/adavidev/overnight
54
56
  licenses: []
55
57
  metadata: {}
@@ -1,11 +0,0 @@
1
- module Overnight
2
- class Timey
3
- def initialize
4
- @time = Time.now
5
- end
6
-
7
- def get
8
- @time
9
- end
10
- end
11
- end