fnord 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
4
+ pkg
5
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -c
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fnord.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ guard "rspec", :version => 2 do
2
+
3
+ watch %r{^spec/spec_helper\.rb$} do
4
+ "spec/"
5
+ end
6
+
7
+ watch %r{^lib/(.+)\.rb$} do |m|
8
+ "spec/#{m[1]}_spec.rb"
9
+ end
10
+
11
+ watch %r{^spec/.+_spec\.rb$}
12
+
13
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jason Coene
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Fnord
2
+
3
+ A FnordMetric client for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem "fnord"
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fnord
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Jason Coene"]
5
+ gem.email = ["jcoene@gmail.com"]
6
+ gem.description = %q{A FnordMetric client for Ruby}
7
+ gem.summary = gem.description
8
+ gem.homepage = "https://github.com/jcoene/fnord"
9
+
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.name = "fnord"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = "0.0.1"
16
+
17
+ gem.add_dependency "json"
18
+
19
+ gem.add_development_dependency "rspec", "~> 2.8.0"
20
+ gem.add_development_dependency "guard-rspec"
21
+ gem.add_development_dependency "growl"
22
+ end
@@ -0,0 +1,32 @@
1
+ require "socket"
2
+ require "json"
3
+
4
+ class Fnord
5
+ attr_accessor :host, :port, :namespace, :socket
6
+
7
+ def initialize(attrs={})
8
+ self.socket = UDPSocket.new
9
+ attrs.each {|k,v| send("#{k}=", v)}
10
+ yield self if block_given?
11
+ end
12
+
13
+ def event(type, options={})
14
+ options = {_namespace: namespace}.merge(options) if namespace
15
+ packet = { _type: type }.merge(options)
16
+ send_data packet.to_json
17
+ end
18
+
19
+ def time(type, options={}, &block)
20
+ start = Time.now
21
+ result = yield
22
+ event type, options.merge({time: ((Time.now-start)*1000).round})
23
+ result
24
+ end
25
+
26
+ private
27
+
28
+ def send_data(json)
29
+ socket.send "#{json}\n", 0, host, port
30
+ end
31
+
32
+ end
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+
3
+ describe Fnord do
4
+
5
+ let :f do
6
+ Fnord.new host: "localhost", port: 1337
7
+ end
8
+
9
+ before do
10
+ Fnord.class_eval do
11
+ public :send_data
12
+ end
13
+ end
14
+
15
+ context "instantiation" do
16
+ it "takes parameters" do
17
+ f = Fnord.new host: "1.2.3.4"
18
+ f.host.should eql "1.2.3.4"
19
+ end
20
+
21
+ it "takes a block" do
22
+ f = Fnord.new do |f|
23
+ f.host = "1.2.3.4"
24
+ end
25
+ f.host.should eql "1.2.3.4"
26
+ end
27
+
28
+ it "establishes a socket" do
29
+ f = Fnord.new
30
+ f.socket.should be_an_instance_of(UDPSocket)
31
+ end
32
+ end
33
+
34
+ context "event" do
35
+ context "sends the proper message" do
36
+ it "given only a type" do
37
+ f.should_receive(:send_data).with('{"_type":"dogs_hugged"}')
38
+ f.event "dogs_hugged"
39
+ end
40
+
41
+ it "given a type and single argument" do
42
+ f.should_receive(:send_data).with('{"_type":"dogs_hugged","dog_type":"frenchie"}')
43
+ f.event "dogs_hugged", dog_type: "frenchie"
44
+ end
45
+
46
+ it "given a type and complex arguments" do
47
+ f.should_receive(:send_data).with('{"_type":"dogs_rescued","dog_type":"pitty","dog_age":9,"fun_factor":0.82}')
48
+ f.event "dogs_rescued", dog_type: "pitty", dog_age: 9, "fun_factor" => 0.82
49
+ end
50
+
51
+ it "given a type and complex arguments and a namespace" do
52
+ f.should_receive(:send_data).with('{"_type":"dogs_rescued","_namespace":"dogpound","dog_type":"pitty","dog_age":9,"fun_factor":0.82}')
53
+ f.namespace = "dogpound"
54
+ f.event "dogs_rescued", dog_type: "pitty", dog_age: 9, "fun_factor" => 0.82
55
+ end
56
+ end
57
+ end
58
+
59
+ context "time" do
60
+ it "times the given block and sends an event with it attached" do
61
+ f.should_receive(:event) do |e,o|
62
+ o[:name].should eql "Alfie"
63
+ o[:time].should be_an_instance_of(Fixnum)
64
+ o[:time].should be > 0
65
+ end
66
+ f.time "dog_walked", name: "Alfie" do
67
+ 10000.times { n = 5 ** 100 / 100 ** 100 }
68
+ end
69
+ end
70
+ end
71
+
72
+ context "sending data" do
73
+ it "actually sends data with newline" do
74
+ server = UDPSocket.new
75
+ server.bind "localhost", 11111
76
+ f = Fnord.new host: "localhost", port: 11111
77
+ f.event "unicorns_per_hour"
78
+ data, peer = server.recvfrom(128)
79
+ data.should eql "{\"_type\":\"unicorns_per_hour\"}\n"
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "fnord"
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fnord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Coene
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70225224895440 !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: *70225224895440
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70225224894660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70225224894660
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-rspec
38
+ requirement: &70225224893640 !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: *70225224893640
47
+ - !ruby/object:Gem::Dependency
48
+ name: growl
49
+ requirement: &70225224892980 !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: *70225224892980
58
+ description: A FnordMetric client for Ruby
59
+ email:
60
+ - jcoene@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - Gemfile
68
+ - Guardfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - fnord.gemspec
73
+ - lib/fnord.rb
74
+ - spec/fnord_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/jcoene/fnord
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.11
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: A FnordMetric client for Ruby
100
+ test_files:
101
+ - spec/fnord_spec.rb
102
+ - spec/spec_helper.rb