diff --git a/.rvmrc b/.rvmrc index 103deb7..697643d 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1 +1 @@ -rvm --create ruby-1.9.2-p0@log-weasel +rvm --create ruby-1.9.2-p0@log_weasel diff --git a/Gemfile b/Gemfile index 21b932d..7ceb124 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source "http://rubygems.org" -# Specify your gem's dependencies in log-weasel.gemspec +# Specify your gem's dependencies in log_weasel.gemspec gemspec diff --git a/README.md b/README.md index b696510..2c0b67f 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ Instrument Rails and Resque with shared transaction IDs so that you trace execut ## Installation -Add log-weasel to your Gemfile: +Add log_weasel to your Gemfile:
-gem 'log-weasel'
+gem 'log_weasel'
 
Use bundler to install it: diff --git a/Rakefile b/Rakefile index 14cfe0b..58d7c7f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,11 @@ require 'bundler' +Bundler.setup + +require 'rspec' +require 'rspec/core/rake_task' + Bundler::GemHelper.install_tasks + +Rspec::Core::RakeTask.new(:spec) do |spec| + spec.pattern = 'spec/**/*_spec.rb' +end diff --git a/lib/log-weasel.rb b/lib/log-weasel.rb deleted file mode 100644 index 1773952..0000000 --- a/lib/log-weasel.rb +++ /dev/null @@ -1,5 +0,0 @@ -module Log - module Weasel - # Your code goes here... - end -end diff --git a/lib/log_weasel.rb b/lib/log_weasel.rb new file mode 100644 index 0000000..d44c217 --- /dev/null +++ b/lib/log_weasel.rb @@ -0,0 +1 @@ +require 'log_weasel/transaction' diff --git a/lib/log_weasel/transaction.rb b/lib/log_weasel/transaction.rb new file mode 100644 index 0000000..0a429d9 --- /dev/null +++ b/lib/log_weasel/transaction.rb @@ -0,0 +1,21 @@ +module LogWeasel + module Transaction + + def self.create(key = nil) + Thread.current[:manilla_transaction_id] = "#{key ? "#{key}_" : ""}#{SecureRandom.hex(10)}" + end + + def self.destroy + Thread.current[:manilla_transaction_id] = nil + end + + def self.id=(id) + Thread.current[:manilla_transaction_id] = id + end + + def self.id + Thread.current[:manilla_transaction_id] + end + end + +end \ No newline at end of file diff --git a/lib/log-weasel/version.rb b/lib/log_weasel/version.rb similarity index 100% rename from lib/log-weasel/version.rb rename to lib/log_weasel/version.rb diff --git a/log-weasel.gemspec b/log_weasel.gemspec similarity index 60% rename from log-weasel.gemspec rename to log_weasel.gemspec index fcca6e0..75153b1 100644 --- a/log-weasel.gemspec +++ b/log_weasel.gemspec @@ -1,18 +1,23 @@ # -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) -require "log-weasel/version" +require "log_weasel/version" Gem::Specification.new do |s| - s.name = "log-weasel" + s.name = "log_weasel" s.version = Log::Weasel::VERSION s.platform = Gem::Platform::RUBY s.authors = ["Alon Salant"] s.email = ["alon@salant.org"] - s.homepage = "" - s.summary = %q{Instrument Rails and Resque with shared transaction IDs so that you trace execution across instances.} + s.homepage = "http://github.com/carbonfive/log_weasel" + s.summary = "log_weasel-#{Log::Weasel::VERSION}" s.description = %q{Instrument Rails and Resque with shared transaction IDs so that you trace execution across instances.} - s.rubyforge_project = "log-weasel" + s.rubyforge_project = "log_weasel" + + s.add_development_dependency('rspec') + s.add_development_dependency('mocha') + s.add_development_dependency('resque', ['~> 1.0']) + s.add_development_dependency('activesupport', ['~> 3.0']) s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") diff --git a/spec/log_weasel/transaction_spec.rb b/spec/log_weasel/transaction_spec.rb new file mode 100644 index 0000000..2ccc2c7 --- /dev/null +++ b/spec/log_weasel/transaction_spec.rb @@ -0,0 +1,54 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') +require 'active_support' +require 'active_support/secure_random' + +describe LogWeasel::Transaction do + + describe ".id" do + + it "is nil if not created" do + LogWeasel::Transaction.id.should be_nil + end + + end + + describe ".id=" do + before do + LogWeasel::Transaction.id = "1234" + end + + it "sets the id" do + LogWeasel::Transaction.id.should == "1234" + end + + end + + describe ".create" do + before do + SecureRandom.stubs(:hex).returns('94b2') + end + + it 'creates a transaction id with no key' do + id = LogWeasel::Transaction.create + id.should == '94b2' + end + + it 'creates a transaction id with a key' do + id = LogWeasel::Transaction.create 'KEY' + id.should == 'KEY_94b2' + LogWeasel::Transaction.id.should == id + end + + end + + describe ".destroy" do + before do + LogWeasel::Transaction.create + end + + it "removes transaction id" do + LogWeasel::Transaction.destroy + LogWeasel::Transaction.id.should be_nil + end + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..1fa6685 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,9 @@ +$LOAD_PATH.unshift(File.dirname(__FILE__)) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) + +require 'log_weasel' +require 'rspec' + +Rspec.configure do |config| + config.mock_with :mocha +end