schlep 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1,8 @@
1
+ CC=/usr/bin/gcc-4.2
2
+ if [ -x $CC ]; then
3
+ export CC
4
+ fi
5
+
6
+ rvm 1.9.3@schlep
7
+ rvm_project_rvmrc_default=1
8
+
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx-2.0
6
+ - jruby
7
+ - ruby-head
8
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in schlep.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ group :darwin do
8
+ gem 'rb-fsevent'
9
+ gem 'growl'
10
+ end
11
+ end
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :test do
2
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
3
+ watch(%r{^test/.+_test\.rb$})
4
+ watch('test/test_helper.rb') { "test" }
5
+ end
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'bundler/gem_tasks'
3
+ rescue LoadError
4
+ puts "Ruby >= 1.9 required for build tasks"
5
+ end
6
+
7
+ require 'rake/testtask'
8
+
9
+ task :default => :test
10
+
11
+ desc "Run basic tests"
12
+ Rake::TestTask.new("test") { |t| t.pattern = 'test/*_test.rb' }
data/Readme.md ADDED
@@ -0,0 +1 @@
1
+ # schlep [![Build Status](https://secure.travis-ci.org/Movitas/schlep-ruby.png)](https://secure.travis-ci.org/Movitas/schlep-ruby) [![Dependency Status](https://gemnasium.com/Movitas/schlep-ruby.png)](https://gemnasium.com/Movitas/schlep-ruby)
@@ -0,0 +1,3 @@
1
+ module Schlep
2
+ VERSION = "0.1.0"
3
+ end
data/lib/schlep.rb ADDED
@@ -0,0 +1,57 @@
1
+ require "schlep/version"
2
+
3
+ require "json"
4
+ require "redis"
5
+
6
+ module Schlep
7
+ extend self
8
+
9
+ attr_writer :app, :hostname
10
+
11
+ def app
12
+ @app ||= ""
13
+ end
14
+
15
+ def configure
16
+ yield self
17
+ end
18
+
19
+ def envelope(type, message)
20
+ {
21
+ :timestamp => timestamp,
22
+ :app => app,
23
+ :host => hostname,
24
+ :type => type,
25
+ :message => serialize_message(message)
26
+ }.to_json
27
+ end
28
+
29
+ def event(type, message)
30
+ e = envelope(type, message)
31
+ redis.rpush 'schlep', e
32
+ e
33
+ end
34
+
35
+ def hostname
36
+ @hostname ||= `hostname`.split(".").first
37
+ end
38
+
39
+ def redis
40
+ @redis ||= Redis.new
41
+ end
42
+
43
+ def reset
44
+ %w[app hostname redis].each do |ivar|
45
+ instance_variable_set "@#{ivar}", nil
46
+ end
47
+ end
48
+
49
+ def serialize_message(message)
50
+ return message if [String, Fixnum, Float].index message.class
51
+ message.to_json
52
+ end
53
+
54
+ def timestamp
55
+ Time.now.to_f
56
+ end
57
+ end
data/schlep.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "schlep/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "schlep"
7
+ s.version = Schlep::VERSION
8
+ s.authors = ["Justin Campbell"]
9
+ s.email = ["justin@justincampbell.me"]
10
+ s.homepage = "http://github.com/Movitas/schlep-ruby"
11
+ s.summary = %q{Ruby client for schlep http://github.com/Movitas/schlep}
12
+ s.description = %q{Ruby client for schlep. Schlep provides a simple interface for logging and broadcasting events.}
13
+
14
+ s.rubyforge_project = "schlep"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "redis"
22
+
23
+ if RUBY_VERSION =~ /1.8/
24
+ s.add_runtime_dependency "json"
25
+ s.add_runtime_dependency "system_timer"
26
+ end
27
+
28
+ s.add_development_dependency "guard-test"
29
+ s.add_development_dependency "rake"
30
+ s.add_development_dependency "shoulda"
31
+ end
@@ -0,0 +1,105 @@
1
+ begin
2
+ require "test_helper"
3
+ rescue LoadError
4
+ require File.join(File.dirname(__FILE__), ".", "test_helper")
5
+ end
6
+
7
+ class SchlepTest < Test::Unit::TestCase
8
+ context "schlep" do
9
+ should "be defined as a module" do
10
+ assert_equal Module, Schlep.class
11
+ end
12
+ end
13
+
14
+ context "configure" do
15
+ should "be configurable with setters" do
16
+ Schlep.app = "test_app_1"
17
+ Schlep.hostname = "test_hostname_1"
18
+
19
+ assert_equal "test_app_1", Schlep.app, "app"
20
+ assert_equal "test_hostname_1", Schlep.hostname, "hostname"
21
+ end
22
+
23
+ should "be configurable with a block" do
24
+ Schlep.configure do |config|
25
+ config.app = "test_app_2"
26
+ config.hostname = "test_hostname_2"
27
+ end
28
+
29
+ assert_equal "test_app_2", Schlep.app, "app"
30
+ assert_equal "test_hostname_2", Schlep.hostname, "hostname"
31
+ end
32
+ end
33
+
34
+ context "envelope" do
35
+ should "return valid json" do
36
+ assert_nothing_raised(Exception) {
37
+ JSON.parse(Schlep.envelope "test_type", { :one => { :two => 3 }})
38
+ }
39
+ end
40
+ end
41
+
42
+ context "hostname" do
43
+ should "be a string" do
44
+ assert Schlep.hostname.is_a? String
45
+ end
46
+ end
47
+
48
+ context "reset" do
49
+ should "reset instance variables to nil" do
50
+ Schlep.configure do |config|
51
+ config.app = "test_app"
52
+ config.hostname = "test_hostname"
53
+ end
54
+
55
+ Schlep.reset
56
+
57
+ %w[app hostname redis].each do |ivar|
58
+ assert_nil Schlep.instance_variable_get("@#{ivar}"), "@#{ivar}"
59
+ end
60
+ end
61
+ end
62
+
63
+ context "serialize message" do
64
+ should "leave valid json alone" do
65
+ assert_equal "{\"one\":{\"two\":3}}",
66
+ Schlep.serialize_message("{\"one\":{\"two\":3}}")
67
+ end
68
+
69
+ should "leave strings alone" do
70
+ assert_equal "test string",
71
+ Schlep.serialize_message("test string")
72
+ end
73
+
74
+ should "convert arrays to json" do
75
+ assert_equal "[1,2,[3,4]]",
76
+ Schlep.serialize_message([1,2,[3,4]])
77
+ end
78
+
79
+ should "convert hashes to json" do
80
+ assert_equal "{\"one\":{\"two\":3}}",
81
+ Schlep.serialize_message({ :one => { :two => 3 }})
82
+ end
83
+
84
+ should "convert an array of hashes to json" do
85
+ assert_equal "[{\"one\":{\"two\":3}},{\"four\":{\"five\":6}}]",
86
+ Schlep.serialize_message([{ :one => { :two => 3 }},{ :four => { :five => 6 }}])
87
+ end
88
+
89
+ should "leave integers alone" do
90
+ assert_equal 123,
91
+ Schlep.serialize_message(123)
92
+ end
93
+
94
+ should "leave floats alone" do
95
+ assert_equal 1.23,
96
+ Schlep.serialize_message(1.23)
97
+ end
98
+ end
99
+
100
+ context "timestamp" do
101
+ should "be a float" do
102
+ assert Schlep.timestamp.is_a? Float
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
6
+
7
+ require 'schlep'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: schlep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin Campbell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: &70138116747200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70138116747200
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard-test
27
+ requirement: &70138116746760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70138116746760
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70138116746340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70138116746340
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda
49
+ requirement: &70138116745900 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70138116745900
58
+ description: Ruby client for schlep. Schlep provides a simple interface for logging
59
+ and broadcasting events.
60
+ email:
61
+ - justin@justincampbell.me
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .rvmrc
68
+ - .travis.yml
69
+ - Gemfile
70
+ - Guardfile
71
+ - Rakefile
72
+ - Readme.md
73
+ - lib/schlep.rb
74
+ - lib/schlep/version.rb
75
+ - schlep.gemspec
76
+ - test/schlep_test.rb
77
+ - test/test_helper.rb
78
+ homepage: http://github.com/Movitas/schlep-ruby
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project: schlep
98
+ rubygems_version: 1.8.10
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Ruby client for schlep http://github.com/Movitas/schlep
102
+ test_files:
103
+ - test/schlep_test.rb
104
+ - test/test_helper.rb