cube-ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,17 +1,31 @@
1
1
  # cube-ruby
2
2
 
3
3
  A Cube client for Ruby (http://square.github.com/cube). Heavily based on
4
- [this statsd ruby client](https://github.com/github/statsd-ruby).
4
+ [this statsd ruby client][sdc].
5
5
 
6
- MIT licensed. See https://github.com/codykrieger/cube-ruby/blob/master/LICENSE
6
+ MIT licensed. See [the LICENSE file][license] for more details.
7
7
  for more details.
8
8
 
9
9
  ## Installation
10
10
 
11
- Add this line to your application's Gemfile:
11
+ Since Cube is under constant development, it's best if you specify a particular
12
+ version of cube-ruby in your `Gemfile`. That way, you can ensure your Ruby
13
+ application and your Cube instance will be compatible with each other.
14
+
15
+ Here's a version compatibility table:
16
+
17
+ Cube | cube-ruby
18
+ --------------------
19
+ 0.2.0 | 0.0.1
20
+ 0.2.1 | 0.0.2 (master)
21
+
22
+ Add this line to your application's `Gemfile`:
12
23
 
13
24
  gem 'cube-ruby', require: "cube"
14
25
 
26
+ # or specify a particular version:
27
+ gem 'cube-ruby', '0.0.2', require: "cube"
28
+
15
29
  And then execute:
16
30
 
17
31
  $ bundle
@@ -35,6 +49,9 @@ $cube = Cube::Client.new 'cube.example.org', 2280
35
49
  ### Send Cube some metrics!
36
50
 
37
51
  ```ruby
52
+ # send a new "foo" event to cube
53
+ $cube.send "foo"
54
+
38
55
  # send a new event to cube that looks like this:
39
56
  # { type: "request", time: [now], data: { value: "somevalue" } }
40
57
  $cube.send "request", value: "somevalue"
@@ -47,6 +64,9 @@ event_id = 42
47
64
  $cube.send "request", DateTime.now, event_id, duration_ms: 234
48
65
  ```
49
66
 
67
+ Yes, the method is called `send`. You can still call `Object#send` on
68
+ `Cube::Client` objects by using the `__send__` method, [per the Ruby docs][rd].
69
+
50
70
  ## Testing
51
71
 
52
72
  Run the specs with `rake`.
@@ -60,3 +80,8 @@ To include real UDP socket testing in the specs, run `LIVE=true rake`.
60
80
  3. Commit your changes (`git commit -am 'Added some feature'`)
61
81
  4. Push to the branch (`git push origin my-new-feature`)
62
82
  5. Create new Pull Request
83
+
84
+ [sdc]: https://github.com/github/statsd-ruby
85
+ [license]: https://github.com/codykrieger/cube-ruby/blob/master/LICENSE
86
+ [rd]: http://ruby-doc.org/core-1.9.3/Object.html#method-i-send
87
+
data/cube-ruby.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/cube/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Cody Krieger"]
6
6
  gem.email = ["cody@codykrieger.com"]
7
- gem.description = %q{A Cube client for Ruby (https://square.github.com/cube)}
8
- gem.summary = %q{A Cube client for Ruby (https://square.github.com/cube)}
7
+ gem.description = %q{A Cube client for Ruby (https://square.github.com/cube).}
8
+ gem.summary = %q{A Cube client for Ruby (https://square.github.com/cube).}
9
9
  gem.homepage = "https://github.com/codykrieger/cube-ruby"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
data/lib/cube.rb CHANGED
@@ -34,7 +34,6 @@ module Cube
34
34
  # cube.send "request", DateTime.now, duration_ms: 234
35
35
  # ```
36
36
  def send(type, *args)
37
- default_time = DateTime.now
38
37
  time = nil
39
38
  id = nil
40
39
  data = nil
@@ -52,7 +51,7 @@ module Cube
52
51
  end
53
52
 
54
53
  # Send off our parsed arguments to be further massaged and socketized.
55
- actual_send type, (time || default_time), id, data
54
+ actual_send type, time, id, data
56
55
  end
57
56
 
58
57
  private
@@ -67,9 +66,9 @@ module Cube
67
66
 
68
67
  # Start constructing the message to be sent to Cube over UDP.
69
68
  message = {
70
- type: "#{prefix}#{type}",
71
- time: time.iso8601
69
+ type: "#{prefix}#{type}"
72
70
  }
71
+ message[:time] = time.iso8601 unless time.nil?
73
72
  message[:id] = id unless id.nil?
74
73
  message[:data] = data unless data.nil?
75
74
 
data/lib/cube/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cube
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/cube_spec.rb CHANGED
@@ -32,13 +32,20 @@ describe Cube::Client do
32
32
  describe "#send" do
33
33
  it "should format the message according to the Cube spec" do
34
34
  type = "request"
35
- time = DateTime.now
36
- data = { duration_ms: 234 }
37
- @cube.send type, time, data
35
+ @cube.send type
38
36
  recv = JSON.parse @cube.socket.recv.first
39
37
  recv["type"].must_equal "request"
40
- recv["time"].must_equal time.iso8601
41
- recv["data"].must_equal({ "duration_ms" => 234 })
38
+ end
39
+
40
+ describe "with a time" do
41
+ it "should format the message according to the Cube spec" do
42
+ type = "request"
43
+ time = DateTime.now
44
+ @cube.send type, time
45
+ recv = JSON.parse @cube.socket.recv.first
46
+ recv["type"].must_equal "request"
47
+ recv["time"].must_equal time.iso8601
48
+ end
42
49
  end
43
50
 
44
51
  describe "with an id" do
@@ -55,6 +62,21 @@ describe Cube::Client do
55
62
  recv["data"].must_equal({ "duration_ms" => 234 })
56
63
  end
57
64
  end
65
+
66
+ describe "with data" do
67
+ it "should format the message according to the Cube spec" do
68
+ type = "request"
69
+ time = DateTime.now
70
+ id = 42
71
+ data = { duration_ms: 234 }
72
+ @cube.send type, time, id, data
73
+ recv = JSON.parse @cube.socket.recv.first
74
+ recv["type"].must_equal "request"
75
+ recv["time"].must_equal time.iso8601
76
+ recv["id"].must_equal 42
77
+ recv["data"].must_equal({ "duration_ms" => 234 })
78
+ end
79
+ end
58
80
  end
59
81
 
60
82
  describe "with namespace" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cube-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-30 00:00:00.000000000 Z
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- description: A Cube client for Ruby (https://square.github.com/cube)
30
+ description: A Cube client for Ruby (https://square.github.com/cube).
31
31
  email:
32
32
  - cody@codykrieger.com
33
33
  executables: []
@@ -67,7 +67,7 @@ rubyforge_project:
67
67
  rubygems_version: 1.8.23
68
68
  signing_key:
69
69
  specification_version: 3
70
- summary: A Cube client for Ruby (https://square.github.com/cube)
70
+ summary: A Cube client for Ruby (https://square.github.com/cube).
71
71
  test_files:
72
72
  - spec/cube_spec.rb
73
73
  - spec/helper.rb