forked from charlotte-ruby/impressionist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 755bd93
Showing
86 changed files
with
12,760 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
source "http://rubygems.org" | ||
|
||
group :development do | ||
gem "shoulda", ">= 0" | ||
gem "bundler", "~> 1.0.0" | ||
gem "jeweler", "~> 1.5.1" | ||
gem "rcov", ">= 0" | ||
end | ||
|
||
if ENV['MY_BUNDLE_ENV'] == "dev" | ||
group :development do | ||
gem 'ZenTest' | ||
gem 'autotest' | ||
gem 'systemu' | ||
gem "rspec" | ||
gem "rspec-rails" | ||
gem "mongrel", "1.2.0.pre2" | ||
gem 'capybara' | ||
gem 'database_cleaner' | ||
gem 'cucumber-rails' | ||
gem 'cucumber' | ||
gem 'spork' | ||
gem 'launchy' | ||
gem 'autotest-notification' | ||
gem 'httpclient' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2011 cowboycoded | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
= impressionist | ||
|
||
A lightweight plugin that logs impressions per action or manually per model | ||
|
||
== I would not call this a stable plugin yet, although I have been running it in prod with no problems. Use at your own risk ;-) | ||
|
||
== What does this thing do? | ||
|
||
Logs an impression... and I use that term loosely. It can log page impressions (technically action impressions), but it is not limited to that. You can log impressions multiple times per request. | ||
And you can also attach it to a model. The goal of this project is to provide customizable web stats that are immediately accessible in your application as opposed to using G Analytics and pulling data using their API. | ||
You can attach custom messages to impressions and log multiple impressions per request. No reporting yet.. this thingy just creates the data. | ||
|
||
== Which versions of Rails and Ruby is this compatible with? | ||
|
||
Rails 3.0.3 and Ruby 1.9.2 - Sorry, but you need to upgrade if you are using Rails 2. You know you want to anyways.. all the cool kids are doing it ;-) | ||
|
||
== Installation | ||
|
||
Add it to your Gemfile | ||
|
||
gem 'impressionist', :git => '[email protected]:cowboycoded/impressionist.git'" | ||
|
||
Install with Bundler | ||
|
||
bundle install | ||
|
||
Generate the impressions table migration | ||
|
||
rails g impressionist | ||
|
||
Run the migration | ||
|
||
rake db:migrate | ||
|
||
The following fields are provided in the migration: | ||
|
||
t.string "impressionable_type" # model type: Widget | ||
t.integer "impressionable_id" # model instance ID: @widget.id | ||
t.integer "user_id" # automatically logs @current_user.id | ||
t.string "controller_name" # logs the controller name | ||
t.string "action_name" # logs the action_name | ||
t.string "view_name" # TODO: log individual views (as well as partials and nested partials) | ||
t.string "request_hash" # unique ID per request, in case you want to log multiple impressions and associate them together | ||
t.string "ip_address" # request.remote_ip | ||
t.string "message" # custom message you can add | ||
t.datetime "created_at" # I am not sure what this is.... Any clue? | ||
t.datetime "updated_at" # never seen this one before either.... Your guess is as good as mine?? | ||
|
||
== Usage | ||
|
||
Log all actions in a controller | ||
|
||
WidgetsController < ApplicationController | ||
impressionist | ||
end | ||
|
||
Specify actions you want logged in a controller | ||
|
||
WidgetsController < ApplicationController | ||
impressionist :actions=>[:show,:index] | ||
end | ||
|
||
Make your models impressionable. This allows you to attach impressions to an AR model instance. | ||
|
||
class Widget < ActiveRecord::Base | ||
is_impressionable | ||
end | ||
|
||
Log an impression per model instance in your controller: | ||
|
||
@widget = Widget.find | ||
impressionist(@widget,message:"wtf is a widget?") | ||
|
||
== Development Roadmap | ||
|
||
* Automatic impression logging in views. For example, log initial view, and any partials called from initial view | ||
* Customizable black list for user-agents or IP addresses. Impressions will be ignored. Web admin as part of the Engine. | ||
* Reporting engine | ||
* AB testing integration | ||
|
||
== Contributing to impressionist | ||
|
||
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet | ||
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it | ||
* Fork the project | ||
* Start a feature/bugfix branch | ||
* Commit and push until you are happy with your contribution | ||
* Make sure to add rpsec tests for it. Patches or features without tests will be ignored. Also, try to write better tests than I do ;-) | ||
* If adding engine controller or view functionality, use HAML and Inherited Resources. | ||
* All testing is done inside a small Rails app (test_app). You will find specs within this app. | ||
== Copyright | ||
|
||
Copyright (c) 2011 cowboycoded. See LICENSE.txt for | ||
further details. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
require 'rubygems' | ||
require 'bundler' | ||
|
||
begin | ||
Bundler.setup(:default, :development) | ||
rescue Bundler::BundlerError => e | ||
$stderr.puts e.message | ||
$stderr.puts "Run `bundle install` to install missing gems" | ||
exit e.status_code | ||
end | ||
require 'rake' | ||
|
||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options | ||
gem.name = "impressionist" | ||
gem.homepage = "http://github.com/johnmcaliley/impressionist" | ||
gem.license = "MIT" | ||
gem.summary = %Q{Easy way to log impressions} | ||
gem.description = %Q{Log impressions from controller actions or from a model} | ||
gem.email = "[email protected]" | ||
gem.authors = ["cowboycoded"] | ||
gem.files.exclude "test_app" | ||
end | ||
Jeweler::RubygemsDotOrgTasks.new | ||
|
||
require 'rake/testtask' | ||
Rake::TestTask.new(:test) do |test| | ||
test.libs << 'lib' << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
|
||
require 'rcov/rcovtask' | ||
Rcov::RcovTask.new do |test| | ||
test.libs << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
|
||
task :default => :test | ||
|
||
require 'rake/rdoctask' | ||
Rake::RDocTask.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "impressionist #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
namespace :version do | ||
desc "create a new version, create tag and push to github" | ||
task :patch_release do | ||
if Jeweler::Commands::ReleaseToGit.new.clean_staging_area? | ||
Rake::Task['version:bump:patch'].invoke | ||
Rake::Task['gemspec:release'].invoke | ||
Rake::Task['git:release'].invoke | ||
else | ||
puts "Commit your changed files first" | ||
end | ||
end | ||
|
||
desc "create a new version, create tag and push to github" | ||
task :minor_release do | ||
Rake::Task['version:bump:minor'].invoke | ||
Rake::Task['gemspec:release'].invoke | ||
Rake::Task['git:release'].invoke | ||
end | ||
|
||
desc "create a new version, create tag and push to github" | ||
task :major_release do | ||
Rake::Task['version:bump:major'].invoke | ||
Rake::Task['gemspec:release'].invoke | ||
Rake::Task['git:release'].invoke | ||
end | ||
end | ||
|
||
namespace :impressionist do | ||
require File.dirname(__FILE__) + "/lib/impressionist/bots" | ||
|
||
desc "output the list of bots from http://www.user-agents.org/" | ||
task :bots do | ||
p Impressionist::Bots.consume | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'digest/sha2' | ||
|
||
module ImpressionistController | ||
module ClassMethods | ||
def impressionist(opts={}) | ||
before_filter { |c| c.impressionist_subapp_filter opts[:actions] } | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def self.included(base) | ||
base.before_filter :impressionist_app_filter | ||
end | ||
|
||
def impressionist(obj,message=nil) | ||
unless bypass | ||
if obj.respond_to?("impressionable?") | ||
obj.impressions.create(message: message, | ||
request_hash: @impressionist_hash, | ||
ip_address: request.remote_ip, | ||
user_id: user_id) | ||
else | ||
raise "#{obj.class.to_s} is not impressionable!" | ||
end | ||
end | ||
end | ||
|
||
def impressionist_app_filter | ||
@impressionist_hash = Digest::SHA2.hexdigest(Time.now.to_f.to_s+rand(10000).to_s) | ||
end | ||
|
||
def impressionist_subapp_filter(actions=nil) | ||
unless bypass | ||
actions.collect!{|a|a.to_s} unless actions.blank? | ||
if actions.blank? or actions.include?(action_name) | ||
Impression.create(controller_name: controller_name, | ||
action_name: action_name, | ||
user_id: user_id, | ||
request_hash: @request_hash, | ||
request_hash: @impressionist_hash, | ||
ip_address: request.remote_ip, | ||
impressionable_type: controller_name.singularize.camelize, | ||
impressionable_id: params[:id]) | ||
end | ||
end | ||
end | ||
|
||
private | ||
def bypass | ||
Impressionist::Bots::WILD_CARDS.each do |wild_card| | ||
return true if request.user_agent.include? wild_card | ||
end | ||
Impressionist::Bots::LIST.include? request.user_agent | ||
end | ||
|
||
def user_id | ||
@current_user ? @current_user.id : nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Impression < ActiveRecord::Base | ||
belongs_to :impressionable, :polymorphic=>true | ||
end |
Oops, something went wrong.