kpi 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/app/mailers/kpi/mailer.rb +12 -0
- data/app/models/kpi/entry.rb +4 -0
- data/app/models/kpi/report/base.rb +51 -0
- data/app/models/kpi/report/suppress_memoization.rb +16 -0
- data/app/views/kpi/mailer/report.html.erb +32 -0
- data/lib/engine.rb +17 -0
- data/lib/kpi.rb +16 -0
- data/spec/models/kpi/report/base_spec.rb +59 -0
- data/spec/spec_helper.rb +20 -0
- metadata +136 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Artur Roszczyk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= kpi
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to kpi
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Artur Roszczyk. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class KPI::Mailer < ActionMailer::Base
|
2
|
+
default :from => KPI.mail_from
|
3
|
+
default :to => KPI.mail_to
|
4
|
+
|
5
|
+
def report(kpi_report)
|
6
|
+
@entries = kpi_report.entries
|
7
|
+
@time = kpi_report.time
|
8
|
+
@title = kpi_report.title
|
9
|
+
|
10
|
+
mail :subject => "[#{KPI.app_name} KPI][#{@time.to_date.to_s(:db)}] #{@title}"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module KPI
|
2
|
+
module Report
|
3
|
+
class Base
|
4
|
+
@@do_not_memoize = [:initialize, :collect!, :entries, :time, :title]
|
5
|
+
extend KPI::Report::SuppressMemoization
|
6
|
+
extend ActiveSupport::Memoizable
|
7
|
+
|
8
|
+
def self.method_added(name)
|
9
|
+
unless self.method_blacklisted?(name) || suppressed_memoization?
|
10
|
+
self.defined_kpis << name
|
11
|
+
suppress_memoization { memoize name }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.method_blacklisted?(name)
|
16
|
+
@@do_not_memoize.include?(name) || name =~ /_unmemoized_/
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.defined_kpis
|
20
|
+
@kpi_methods ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.collect_and_send!
|
24
|
+
KPI::Mailer.report(self.new.tap(&:collect!)).deliver
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(time=Time.now)
|
28
|
+
@time = time
|
29
|
+
end
|
30
|
+
attr_reader :time
|
31
|
+
|
32
|
+
def collect!
|
33
|
+
self.class.defined_kpis.each {|kpi_method| send(kpi_method) }
|
34
|
+
self.class.defined_kpis.count
|
35
|
+
end
|
36
|
+
|
37
|
+
def entries
|
38
|
+
Enumerator.new do |yielder|
|
39
|
+
self.class.defined_kpis.each do |kpi_method|
|
40
|
+
result = send(kpi_method)
|
41
|
+
yielder.yield(Entry.new(result.shift, result.shift, result.shift))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def title
|
47
|
+
self.class.name
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module KPI
|
2
|
+
module Report
|
3
|
+
module SuppressMemoization
|
4
|
+
def suppress_memoization
|
5
|
+
Thread.current[:'suppress memoization'] = true
|
6
|
+
yield
|
7
|
+
ensure
|
8
|
+
Thread.current[:'suppress memoization'] = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def suppressed_memoization?
|
12
|
+
Thread.current[:'suppress memoization']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
5
|
+
</head>
|
6
|
+
|
7
|
+
<body>
|
8
|
+
<h1><%= KPI.app_name %> KPI Report</h1>
|
9
|
+
<h2><%= @title %></h2>
|
10
|
+
<p>Created at: <%= @time.to_s(:db) %></p>
|
11
|
+
<table style="border-collapse: collapse;width: 100%;" width="100%">
|
12
|
+
<tr style="border-bottom: 1px solid black;">
|
13
|
+
<td>KPI</td>
|
14
|
+
<td>Value</td>
|
15
|
+
</tr>
|
16
|
+
<% for entry in @entries %>
|
17
|
+
<tr style="border-bottom: 1px solid black;">
|
18
|
+
<td>
|
19
|
+
<strong><%= entry.name %></strong>
|
20
|
+
<% unless entry.description.blank? %>
|
21
|
+
<br />
|
22
|
+
<span style="color: grey; font-size: smaller;">
|
23
|
+
<%= entry.description %>
|
24
|
+
</span>
|
25
|
+
<% end %>
|
26
|
+
</td>
|
27
|
+
<td style="text-align: center;"><%= entry.value %></td>
|
28
|
+
</tr>
|
29
|
+
<% end %>
|
30
|
+
</table>
|
31
|
+
</body>
|
32
|
+
</html>
|
data/lib/engine.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'kpi'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module KPI
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
# Config defaults
|
8
|
+
config.mount_at = '/'
|
9
|
+
|
10
|
+
# Check the gem config
|
11
|
+
initializer "check config" do |app|
|
12
|
+
|
13
|
+
# make sure mount_at ends with trailing slash
|
14
|
+
config.mount_at += '/' unless config.mount_at.last == '/'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/kpi.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module KPI
|
2
|
+
require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
3
|
+
|
4
|
+
mattr_accessor :app_name
|
5
|
+
@@app_name = "Your app"
|
6
|
+
|
7
|
+
mattr_accessor :mail_from
|
8
|
+
@@mail_from = "example@example.com"
|
9
|
+
|
10
|
+
mattr_accessor :mail_to
|
11
|
+
@@mail_to = "example@example.com"
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe "KPI::Report::Base" do
|
4
|
+
before(:all) do
|
5
|
+
class TestKpi < KPI::Report::Base
|
6
|
+
def test_kpi
|
7
|
+
return ["title", 1, "description"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def another_kpi
|
11
|
+
return ["another title", 0]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should define indicators" do
|
17
|
+
TestKpi.defined_kpis.should == [:test_kpi, :another_kpi]
|
18
|
+
end
|
19
|
+
|
20
|
+
describe :collect! do
|
21
|
+
before { @kpi = TestKpi.new }
|
22
|
+
it "should call all KPIs" do
|
23
|
+
TestKpi.defined_kpis.each do |kpi_method|
|
24
|
+
@kpi.should_receive(kpi_method)
|
25
|
+
end
|
26
|
+
@kpi.collect!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe :entries do
|
31
|
+
before { @kpi = TestKpi.new }
|
32
|
+
|
33
|
+
it "should return enumerator" do
|
34
|
+
@kpi.entries.should be_kind_of(Enumerable)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return enumerator with entries" do
|
38
|
+
@kpi.entries.first.should be_kind_of(KPI::Entry)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should fill entries with names" do
|
42
|
+
@kpi.entries.map(&:name).should == ["title", "another title"]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should fill entries with values" do
|
46
|
+
@kpi.entries.map(&:value).should == [1, 0]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should fill entries with descriptions" do
|
50
|
+
@kpi.entries.map(&:description).should == ["description", nil]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe :title do
|
55
|
+
it "should return class name by default" do
|
56
|
+
TestKpi.new.title.should == "TestKpi"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'active_support'
|
4
|
+
require 'action_mailer'
|
5
|
+
require 'rspec'
|
6
|
+
require 'kpi'
|
7
|
+
|
8
|
+
# Requires supporting files with custom matchers and macros, etc,
|
9
|
+
# in ./support/ and its subdirectories.
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
|
+
|
12
|
+
require File.join(File.dirname(__FILE__), '..', 'app/models/kpi/entry')
|
13
|
+
require File.join(File.dirname(__FILE__), '..', 'app/models/kpi/report/suppress_memoization')
|
14
|
+
require File.join(File.dirname(__FILE__), '..', 'app/models/kpi/report/base')
|
15
|
+
require File.join(File.dirname(__FILE__), '..', 'app/mailers/kpi/mailer')
|
16
|
+
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kpi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Artur Roszczyk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-21 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: actionmailer
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.0.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bundler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.0.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: jeweler
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.5.2
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rcov
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
description: This gem helps you to track key indicators in your Rails app.
|
83
|
+
email: artur.roszczyk@gmail.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- app/mailers/kpi/mailer.rb
|
93
|
+
- app/models/kpi/entry.rb
|
94
|
+
- app/models/kpi/report/base.rb
|
95
|
+
- app/models/kpi/report/suppress_memoization.rb
|
96
|
+
- app/views/kpi/mailer/report.html.erb
|
97
|
+
- lib/engine.rb
|
98
|
+
- lib/kpi.rb
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.rdoc
|
101
|
+
- spec/models/kpi/report/base_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
has_rdoc: true
|
104
|
+
homepage: http://github.com/sevos/kpi
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: -1994630966239560221
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: "0"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.5.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Key Performance Indicators for Rails 3.x
|
134
|
+
test_files:
|
135
|
+
- spec/models/kpi/report/base_spec.rb
|
136
|
+
- spec/spec_helper.rb
|