Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Empty first step towards Redis-logged visit tracking
- Loading branch information
James Conroy-Finn
committed
Feb 24, 2011
0 parents
commit 1130e22
Showing
14 changed files
with
164 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,4 @@ | ||
*.gem | ||
.bundle | ||
Gemfile.lock | ||
pkg/* |
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 @@ | ||
--profile |
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 @@ | ||
rvm use 1.9.2@visitors |
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,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in visitors.gemspec | ||
gemspec |
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,15 @@ | ||
# A sample Guardfile | ||
# More info at https://github.com/guard/guard#readme | ||
|
||
guard 'rspec', :version => 2 do | ||
watch('^spec/(.*)_spec.rb') | ||
watch('^lib/(.*)\.rb') { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch('^spec/spec_helper.rb') { "spec" } | ||
|
||
# Rails example | ||
watch('^app/(.*)\.rb') { |m| "spec/#{m[1]}_spec.rb" } | ||
# watch('^lib/(.*)\.rb') { |m| "spec/lib/#{m[1]}_spec.rb" } | ||
watch('^config/routes.rb') { "spec/routing" } | ||
watch('^app/controllers/application_controller.rb') { "spec/controllers" } | ||
watch('^spec/factories.rb') { "spec/models" } | ||
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,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
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,11 @@ | ||
#!/usr/bin/env ruby | ||
|
||
begin | ||
require 'visitors' | ||
require 'visitors/cli' | ||
rescue LoadError | ||
require File.expand_path('../../lib/visitors', __FILE__) | ||
require File.expand_path('../../lib/visitors/cli', __FILE__) | ||
end | ||
|
||
Visitors::CLI.start |
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,18 @@ | ||
require 'active_support' | ||
|
||
$:.push File.expand_path('..', __FILE__) | ||
|
||
module Visitors | ||
extend self | ||
|
||
autoload :Store, 'visitors/store' | ||
autoload :Day, 'visitors/business' | ||
autoload :Month, 'visitors/business' | ||
autoload :Year, 'visitors/business' | ||
|
||
FIELDS = [:show, :search, :email, :website] | ||
|
||
def fields | ||
FIELDS | ||
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,22 @@ | ||
require 'dm-core' | ||
require 'dm-migrations' | ||
|
||
DataMapper.setup(:default, 'postgres://localhost/visitors') | ||
|
||
%w[Day Month Year].each do |class_name| | ||
class_eval <<-RUBY, __FILE__, __LINE__ + 1 | ||
class Visitors::#{class_name} | ||
include DataMapper::Resource | ||
property :id, Serial | ||
property :archived, Time, :default => nil | ||
Visitors.fields.each do |field| | ||
property field, Integer, :default => 0, :required => true | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
DataMapper.finalize | ||
DataMapper.auto_migrate! |
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,13 @@ | ||
require 'thor' | ||
|
||
class Visitors::CLI < Thor | ||
desc 'store', 'start the redis in-memory store' | ||
def store | ||
say "You're running in development, do it yourself!", :blue | ||
end | ||
|
||
desc 'web', 'start the web console (NOT IMPLEMENTED)' | ||
def web | ||
say 'Not implemented yet', :red | ||
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,29 @@ | ||
require 'redis' | ||
require 'redis-namespace' | ||
|
||
class Visitors::Store | ||
attr_reader :redis, :namespace | ||
|
||
def initialize(namespace, redis_config) | ||
@redis = Redis.new(redis_config) | ||
@namespace = Redis::Namespace.new(namespace, :redis => @redis) | ||
end | ||
|
||
def find(business_id) | ||
namespace.hgetall business_id | ||
end | ||
|
||
def increment(business_id, type) | ||
namespace.hincrby business_id, type, 1 | ||
end | ||
|
||
alias :incr :increment | ||
|
||
def method_missing(message, *args, &block) | ||
if namespace.respond_to?(message) | ||
namespace.send(message, *args, &block) | ||
else | ||
super(message, *args, &block) | ||
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 @@ | ||
module Visitors | ||
VERSION = "0.0.1" | ||
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 @@ | ||
require 'rspec' | ||
$:.push File.expand_path('../../lib', __FILE__) | ||
require 'visitors' |
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,38 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "visitors/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "visitors" | ||
s.version = Visitors::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["James Conroy-Finn"] | ||
s.email = ["james@logi.cl"] | ||
s.homepage = "" | ||
s.summary = %q{All-in-one fast logging system for your Rails application} | ||
s.description = %q{All-in-one fast logging system for your Rails application} | ||
|
||
s.rubyforge_project = "visitors" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
|
||
{ | ||
'activesupport' => '3.0.4', | ||
'i18n' => '0.5.0', | ||
'redis' => '2.1.1', | ||
'redis-namespace' => '0.10.0', | ||
'dm-core' => '1.0.2', | ||
'dm-migrations' => '1.0.2', | ||
'dm-postgres-adapter' => '1.0.2', | ||
'sinatra' => '1.1.3', | ||
'thor' => '0.14.6' | ||
}.each { |gem, version| s.add_dependency gem, "~> #{version}" } | ||
|
||
{ | ||
'rspec' => '2.5.0', | ||
'guard-rspec' => '0.1.9' | ||
}.each { |gem, version| s.add_development_dependency gem, "~> #{version}" } | ||
end |