Skip to content

Commit

Permalink
Empty first step towards Redis-logged visit tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
James Conroy-Finn committed Feb 24, 2011
0 parents commit 1130e22
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--profile
1 change: 1 addition & 0 deletions .rvmrc
@@ -0,0 +1 @@
rvm use 1.9.2@visitors
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in visitors.gemspec
gemspec
15 changes: 15 additions & 0 deletions Guardfile
@@ -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
2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
11 changes: 11 additions & 0 deletions bin/visitors
@@ -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
18 changes: 18 additions & 0 deletions lib/visitors.rb
@@ -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
22 changes: 22 additions & 0 deletions lib/visitors/business.rb
@@ -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!
13 changes: 13 additions & 0 deletions lib/visitors/cli.rb
@@ -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
29 changes: 29 additions & 0 deletions lib/visitors/store.rb
@@ -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
3 changes: 3 additions & 0 deletions lib/visitors/version.rb
@@ -0,0 +1,3 @@
module Visitors
VERSION = "0.0.1"
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,3 @@
require 'rspec'
$:.push File.expand_path('../../lib', __FILE__)
require 'visitors'
38 changes: 38 additions & 0 deletions visitors.gemspec
@@ -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

0 comments on commit 1130e22

Please sign in to comment.