km_everything 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/km_everything.gemspec +21 -0
- data/lib/km_everything.rb +36 -0
- data/lib/km_everything/version.rb +3 -0
- data/spec/km_everything_spec.rb +105 -0
- metadata +76 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
km_everything (0.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.2)
|
10
|
+
rake (10.0.4)
|
11
|
+
rspec (2.13.0)
|
12
|
+
rspec-core (~> 2.13.0)
|
13
|
+
rspec-expectations (~> 2.13.0)
|
14
|
+
rspec-mocks (~> 2.13.0)
|
15
|
+
rspec-core (2.13.1)
|
16
|
+
rspec-expectations (2.13.0)
|
17
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
18
|
+
rspec-mocks (2.13.0)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
km_everything!
|
25
|
+
rake
|
26
|
+
rspec (~> 2.11)
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Case Commons, LLC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# km_everything
|
2
|
+
|
3
|
+
Log Rails controller actions to KissMetrics
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
* Ruby 1.9
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
TBD
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
In config/initializers/km\_everything\_.rb:
|
15
|
+
|
16
|
+
KmEverything.event_names = YAML.load(File.open("path/to/file.yml"))
|
17
|
+
KmEverything.record_every_controller_action = true
|
18
|
+
|
19
|
+
In config/km\_everything\_.yml:
|
20
|
+
|
21
|
+
controller_1:
|
22
|
+
action_1: My Event Name for Action 1
|
23
|
+
|
24
|
+
In application_controller.rb:
|
25
|
+
|
26
|
+
after_filter :queue_kissmetrics, if: :user_signed_in?
|
27
|
+
|
28
|
+
def queue_kissmetrics
|
29
|
+
event_name = KmEverything::KmEvent.new(controller_name, action_name).event
|
30
|
+
KmResque.record(current_user.id, event_name, {}) unless event_name.nil?
|
31
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/km_everything/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Trace Wax", "Justin Schier", "Alex Kramer", "Case Commons LLC"]
|
6
|
+
gem.email = ["gems@tracedwax.com"]
|
7
|
+
gem.summary = "Log Rails controller actions to KissMetrics"
|
8
|
+
gem.homepage = "https://github.com/tracedwax/km_everything"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "km_everything"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = KmEverything::VERSION
|
16
|
+
gem.license = "MIT"
|
17
|
+
|
18
|
+
gem.required_ruby_version = '>= 1.9.2'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec', '~> 2.11'
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module KmEverything
|
2
|
+
class << self
|
3
|
+
attr_accessor :record_every_controller_action
|
4
|
+
attr_accessor :event_names
|
5
|
+
attr_accessor :events_to_exclude
|
6
|
+
end
|
7
|
+
|
8
|
+
class KmEvent < Struct.new(:controller_name, :action_name)
|
9
|
+
def event
|
10
|
+
unless event_excluded?
|
11
|
+
specified_event || unspecified_event
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def specified_event
|
18
|
+
controller_actions = KmEverything.event_names[controller_name]
|
19
|
+
controller_actions[action_name] if controller_actions
|
20
|
+
end
|
21
|
+
|
22
|
+
def unspecified_event
|
23
|
+
"#{controller_name}##{action_name}" if KmEverything.record_every_controller_action
|
24
|
+
end
|
25
|
+
|
26
|
+
def event_excluded?
|
27
|
+
if events_to_exclude && events_to_exclude[controller_name]
|
28
|
+
events_to_exclude[controller_name].include?(action_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def events_to_exclude
|
33
|
+
KmEverything.events_to_exclude
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'km_everything'
|
2
|
+
|
3
|
+
describe KmEverything::KmEvent do
|
4
|
+
let(:km_event) { KmEverything::KmEvent.new(controller_name, action_name) }
|
5
|
+
|
6
|
+
describe "#event" do
|
7
|
+
before do
|
8
|
+
KmEverything.event_names = { "users" => { "show" => "Viewed User Page" } }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "blacklisting events" do
|
12
|
+
context "when using a blacklist" do
|
13
|
+
before do
|
14
|
+
KmEverything.record_every_controller_action = true
|
15
|
+
KmEverything.events_to_exclude = { "notifications" => ["show", "index"] }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "and the event is on the blacklist" do
|
19
|
+
let(:controller_name) {"notifications"}
|
20
|
+
let(:action_name) { "show"}
|
21
|
+
|
22
|
+
it "does not return the event" do
|
23
|
+
km_event.event.should be_nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "and the event is not on the blacklist" do
|
28
|
+
let(:controller_name) {"sessions"}
|
29
|
+
let(:action_name) { "create"}
|
30
|
+
|
31
|
+
it "returns the event" do
|
32
|
+
km_event.event.should == "sessions#create"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
KmEverything.events_to_exclude = nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "whitelisting events" do
|
43
|
+
context "when the controller name is present" do
|
44
|
+
let(:controller_name) { "users" }
|
45
|
+
|
46
|
+
context "when the action name is present" do
|
47
|
+
let(:action_name) { "show" }
|
48
|
+
|
49
|
+
it "returns the event name" do
|
50
|
+
km_event.event.should == "Viewed User Page"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when the action name is not present" do
|
55
|
+
let(:action_name) { "create" }
|
56
|
+
|
57
|
+
context "when the app is configured to record all controller actions" do
|
58
|
+
before do
|
59
|
+
KmEverything.record_every_controller_action = true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns the controller and action name" do
|
63
|
+
km_event.event.should == "users#create"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when the app is configured to NOT record all controller actions" do
|
68
|
+
before do
|
69
|
+
KmEverything.record_every_controller_action = false
|
70
|
+
end
|
71
|
+
|
72
|
+
it "does not return an event name" do
|
73
|
+
km_event.event.should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when the controller name is not present" do
|
80
|
+
let(:controller_name) { "some_other_controller" }
|
81
|
+
let(:action_name) { "some_other_action" }
|
82
|
+
|
83
|
+
context "when the app is configured to record all controller actions" do
|
84
|
+
before do
|
85
|
+
KmEverything.record_every_controller_action = true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns the controller and action name" do
|
89
|
+
km_event.event.should == "some_other_controller#some_other_action"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when the app is configured to NOT record all controller actions" do
|
94
|
+
before do
|
95
|
+
KmEverything.record_every_controller_action = false
|
96
|
+
end
|
97
|
+
|
98
|
+
it "does not return an event name" do
|
99
|
+
km_event.event.should be_nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: km_everything
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Trace Wax
|
9
|
+
- Justin Schier
|
10
|
+
- Alex Kramer
|
11
|
+
- Case Commons LLC
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rspec
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '2.11'
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.11'
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- gems@tracedwax.com
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- Gemfile
|
41
|
+
- Gemfile.lock
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- km_everything.gemspec
|
46
|
+
- lib/km_everything.rb
|
47
|
+
- lib/km_everything/version.rb
|
48
|
+
- spec/km_everything_spec.rb
|
49
|
+
homepage: https://github.com/tracedwax/km_everything
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.9.2
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.23
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Log Rails controller actions to KissMetrics
|
74
|
+
test_files:
|
75
|
+
- spec/km_everything_spec.rb
|
76
|
+
has_rdoc:
|