slides 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/slides.rb +39 -0
  2. metadata +46 -0
data/lib/slides.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Slides
2
+ module Log
3
+ def log(action, attrs = {})
4
+ unless block_given?
5
+ str = "#{action} #{unparse(attrs)}"
6
+ mtx.synchronize { $stdout.puts str }
7
+ else
8
+ start = Time.now
9
+ log(action, attrs.merge(at: :start))
10
+ res = yield
11
+ log(action, attrs.merge(at: :finish,
12
+ elapsed: "#{((Time.now - start) * 1000).to_i}ms"))
13
+ res
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def mtx
20
+ @mtx ||= Mutex.new
21
+ end
22
+
23
+ def unparse(attrs)
24
+ attrs.map { |k, v| unparse_pair(k, v) }.join(" ")
25
+ end
26
+
27
+ def unparse_pair(k, v)
28
+ v = v.call if v.is_a?(Proc)
29
+ # only quote strings if they include whitespace
30
+ if v.is_a?(String) && v =~ /\s/
31
+ %{#{k}="#{v}"}
32
+ else
33
+ "#{k}=#{v}"
34
+ end
35
+ end
36
+ end
37
+
38
+ extend Log
39
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slides
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandur
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-17 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: brandur@mutelight.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/slides.rb
21
+ homepage: https://github.com/brandur/slides
22
+ licenses:
23
+ - MIT
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: An extremely simplistic logs-as-data implementation.
46
+ test_files: []