express_analytics 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/express_analytics/daily_statistics/index.html.et +22 -6
- data/config/initializers/initialize_logger.rb +1 -0
- data/lib/express_analytics/default_logger.rb +89 -0
- data/lib/express_analytics/version.rb +1 -1
- data/lib/express_analytics.rb +17 -0
- metadata +3 -2
- data/config/initializers/default_logger.rb +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7abe0673ba3998d5fd74e802648f889fa8c1902
|
4
|
+
data.tar.gz: 4be92f4156160e140a2102b1eca58e1e3409ceb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c257ab462f9083eb471e2f8684f8e30377ea9afea07306fb394aaf4e64f191609e639619a5dedb7f4dd74e5adc0c0ac2e88c0ec787212c79cf08a0ef502fdcf
|
7
|
+
data.tar.gz: 51245652186485fef2e37ba4b5f89cd99b4319b22d56ea12be25ac38b6c8b01109288041e837405378ee1b5c02370f8ead0f9f49215890a577b7455c419a5724
|
@@ -1,8 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
v_box {
|
2
|
+
div {
|
3
|
+
collection_filter :log_entries
|
4
|
+
|
5
|
+
h2(class: 'content-title') {"Daily Statistics"}
|
6
|
+
}
|
7
|
+
|
8
|
+
div {
|
9
|
+
# table(class: table_classes) {
|
10
|
+
# thead {
|
11
|
+
# tr {
|
12
|
+
# ExpressAnalytics::Daily.each do |column|
|
13
|
+
# th(class: column.name) {
|
14
|
+
# config[:sortable].present? ? sortable(column) : column.title
|
15
|
+
# }
|
16
|
+
# end
|
17
|
+
# actions_header if should_show_actions?
|
18
|
+
# hidden_columns_header_indicator if columns_hidden?
|
19
|
+
# }
|
20
|
+
# }
|
21
|
+
# tbody {
|
22
|
+
|
7
23
|
}
|
8
24
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
ExpressAnalytics.initialize!
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# meant to extend ApplicationController or ActionController::Base
|
2
|
+
# to override anything just override the appropriate method here.
|
3
|
+
module ExpressAnalytics
|
4
|
+
module DefaultLogger
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
include InstanceMethods
|
8
|
+
extend ClassMethods
|
9
|
+
|
10
|
+
before_action do
|
11
|
+
create_log_entry!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def skip_logging!
|
18
|
+
define_method(:create_log_entry!) do
|
19
|
+
#nothing
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def create_log_entry!
|
26
|
+
geo_data = begin
|
27
|
+
ExpressGeoip.lookup(request.remote_ip)
|
28
|
+
rescue => e
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
|
32
|
+
entity = entity_for_log
|
33
|
+
|
34
|
+
entry_data = {
|
35
|
+
action: action_for_log,
|
36
|
+
username: current_user.try(:email),
|
37
|
+
ip_address: request.ip,
|
38
|
+
user_agent: request.user_agent,
|
39
|
+
entity_type: entity.try(:class).try(:to_s),
|
40
|
+
entity_id: entity.try(:id),
|
41
|
+
notes: notes_for_log
|
42
|
+
}
|
43
|
+
|
44
|
+
ExpressAnalytics::LogEntry.create(entry_data.merge(geo_data))
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def action_for_log
|
49
|
+
# ExpressAnalytics::LogEntriesController#show becomes
|
50
|
+
# express_analytics/log_entries_controller#show
|
51
|
+
# show log entry
|
52
|
+
is_plural = %w(list index).include?(request.params[:action])
|
53
|
+
object_name = self.class.to_s.demodulize.underscore.titleize
|
54
|
+
object_name.gsub!(/ Controller/, '')
|
55
|
+
object_name = is_plural ? object_name : object_name.singularize
|
56
|
+
|
57
|
+
verb = is_plural ? 'view' : request.params[:action]
|
58
|
+
"#{verb} #{object_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def entity_for_log
|
62
|
+
self.respond_to?(:resource) ? resource : nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def notes_for_log
|
66
|
+
request.path # override to add notes
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
# TODO: Move this to ExpressGeoip
|
75
|
+
module ExpressGeoip
|
76
|
+
def lookup(remote_ip)
|
77
|
+
geo_data = {}
|
78
|
+
if result = ExpressGeoip::GeoipLookup.lookup(request.remote_ip)
|
79
|
+
if result.present?
|
80
|
+
geo_data.merge!(geo_country_code: result.country.name,
|
81
|
+
geo_administrative_area: nil,
|
82
|
+
geo_locality: result.city.name,
|
83
|
+
geo_latitude: (result.location.present? ? result.location.latitude : nil),
|
84
|
+
geo_longitude: (result.location.present? ? result.location.latitude : nil) )
|
85
|
+
end
|
86
|
+
end
|
87
|
+
geo_data
|
88
|
+
end
|
89
|
+
end
|
data/lib/express_analytics.rb
CHANGED
@@ -1,4 +1,21 @@
|
|
1
1
|
require "express_analytics/engine"
|
2
|
+
require "express_analytics/default_logger"
|
2
3
|
|
3
4
|
module ExpressAnalytics
|
5
|
+
|
6
|
+
def self.initialize!
|
7
|
+
initialize_filter!
|
8
|
+
|
9
|
+
|
10
|
+
ActionDispatch::Reloader.to_prepare do
|
11
|
+
ExpressAccess.initialize_filter!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.initialize_filter!
|
16
|
+
ActionController::Base.send(:include, ExpressAnalytics::DefaultLogger)
|
17
|
+
puts "Added ExpressAnalytics::DefaultLogger to ActionController::Base" unless Rails.env.test?
|
18
|
+
end
|
19
|
+
|
20
|
+
|
4
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: express_analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Talcott Smith
|
@@ -76,13 +76,14 @@ files:
|
|
76
76
|
- app/views/express_analytics/log_entries/index.html.et
|
77
77
|
- app/views/layouts/express_analytics/admin.html.et
|
78
78
|
- app/views/layouts/express_analytics/application.html.erb
|
79
|
-
- config/initializers/
|
79
|
+
- config/initializers/initialize_logger.rb
|
80
80
|
- config/initializers/mount_engine.rb
|
81
81
|
- config/menu.yml
|
82
82
|
- config/routes.rb
|
83
83
|
- db/migrate/20160215051456_create_express_analytics_daily_statistics.rb
|
84
84
|
- db/migrate/20160215053321_create_express_analytics_log_entries.rb
|
85
85
|
- lib/express_analytics.rb
|
86
|
+
- lib/express_analytics/default_logger.rb
|
86
87
|
- lib/express_analytics/engine.rb
|
87
88
|
- lib/express_analytics/version.rb
|
88
89
|
- lib/generators/express_analytics/install/USAGE
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# opening ApplicationController here to add default functionality
|
2
|
-
# to override anything just override the appropriate method here.
|
3
|
-
class ApplicationController < ActionController::Base
|
4
|
-
before_action do
|
5
|
-
create_log_entry!
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.skip_logging!
|
9
|
-
define_method(:create_log_entry!) do
|
10
|
-
#nothing
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def create_log_entry!
|
15
|
-
|
16
|
-
geo_data = begin
|
17
|
-
ExpressGeoip.lookup(request.remote_ip)
|
18
|
-
rescue => e
|
19
|
-
{}
|
20
|
-
end
|
21
|
-
|
22
|
-
entity = entity_for_log
|
23
|
-
|
24
|
-
entry_data = {
|
25
|
-
action: action_for_log,
|
26
|
-
username: current_user.try(:email),
|
27
|
-
ip_address: request.ip,
|
28
|
-
user_agent: request.user_agent,
|
29
|
-
entity_type: entity.try(:class).try(:to_s),
|
30
|
-
entity_id: entity.try(:id),
|
31
|
-
notes: notes_for_log
|
32
|
-
}
|
33
|
-
|
34
|
-
ExpressAnalytics::LogEntry.create(entry_data.merge(geo_data))
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def action_for_log
|
39
|
-
# ExpressAnalytics::LogEntriesController#show becomes
|
40
|
-
# express_analytics/log_entries_controller#show
|
41
|
-
# show log entry
|
42
|
-
is_plural = %w(list index).include?(request.params[:action])
|
43
|
-
object_name = self.class.to_s.demodulize.underscore.titleize
|
44
|
-
object_name.gsub!(/ Controller/, '')
|
45
|
-
object_name = is_plural ? object_name : object_name.singularize
|
46
|
-
|
47
|
-
verb = is_plural ? 'view' : request.params[:action]
|
48
|
-
"#{verb} #{object_name}"
|
49
|
-
end
|
50
|
-
|
51
|
-
def entity_for_log
|
52
|
-
self.respond_to?(:resource) ? resource : nil
|
53
|
-
end
|
54
|
-
|
55
|
-
def notes_for_log
|
56
|
-
request.path # override to add notes
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# TODO: Move this to ExpressGeoip
|
64
|
-
module ExpressGeoip
|
65
|
-
def lookup(remote_ip)
|
66
|
-
geo_data = {}
|
67
|
-
if result = ExpressGeoip::GeoipLookup.lookup(request.remote_ip)
|
68
|
-
if result.present?
|
69
|
-
geo_data.merge!(geo_country_code: result.country.name,
|
70
|
-
geo_administrative_area: nil,
|
71
|
-
geo_locality: result.city.name,
|
72
|
-
geo_latitude: (result.location.present? ? result.location.latitude : nil),
|
73
|
-
geo_longitude: (result.location.present? ? result.location.latitude : nil) )
|
74
|
-
end
|
75
|
-
end
|
76
|
-
geo_data
|
77
|
-
end
|
78
|
-
end
|