statsd_helper 0.0.0.1 → 0.0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/LICENSE.txt +20 -0
- data/lib/statsd_helper.rb +1 -0
- data/lib/statsd_helper/metric.rb +20 -0
- data/lib/statsd_helper/version.rb +3 -0
- data/spec/metrics_spec.rb +57 -0
- data/spec/spec_helper.rb +14 -0
- data/statsd_helper.gemspec +21 -0
- metadata +11 -3
data/.rspec
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Ryan Boucher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'statsd_helper/metric.rb'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module StatsdHelper
|
2
|
+
class Metric
|
3
|
+
def self.standard_prefix
|
4
|
+
company = get_env 'COMPANY'
|
5
|
+
product = get_env 'PRODUCT'
|
6
|
+
environment = get_env 'ENV'
|
7
|
+
release = get_env 'RELEASE'
|
8
|
+
|
9
|
+
"#{company}.#{product}.#{environment}.#{release}.metrics".downcase
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.standard_name metric
|
13
|
+
"#{standard_prefix}.#{metric}".downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_env key
|
17
|
+
ENV[key].nil? ? "#{key}-unset" : ENV[key]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module StatsdHelper
|
4
|
+
describe Metric do
|
5
|
+
let(:company){'distributedlife'}
|
6
|
+
let(:product){'statsd_helper'}
|
7
|
+
let(:environment){'development'}
|
8
|
+
let(:release){'1_0'}
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
ENV['COMPANY'] = company
|
12
|
+
ENV['PRODUCT'] = product
|
13
|
+
ENV['ENV'] = environment
|
14
|
+
ENV['RELEASE'] = release
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'standard_prefix' do
|
18
|
+
let(:subject) {Metric.standard_prefix}
|
19
|
+
|
20
|
+
it 'should retrieve the company, product, environment and release dot joined' do
|
21
|
+
subject.should == "#{company}.#{product}.#{environment}.#{release}.metrics"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should downcase the returned string' do
|
25
|
+
ENV['COMPANY'] = 'DISTRIBUTEDLIFE'
|
26
|
+
|
27
|
+
subject.should == "#{company}.#{product}.#{environment}.#{release}.metrics"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'standard_name' do
|
32
|
+
let(:subject) {Metric.standard_name "HELLO"}
|
33
|
+
|
34
|
+
it 'should return the prefix and the metric name joined with a dot' do
|
35
|
+
subject.should == "#{company}.#{product}.#{environment}.#{release}.metrics.hello"
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should downcase the returned string' do
|
39
|
+
subject.should == "#{company}.#{product}.#{environment}.#{release}.metrics.hello"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'get_env' do
|
44
|
+
let(:subject){Metric.get_env('BANANA')}
|
45
|
+
|
46
|
+
it 'should return the key-unset when the environment variable is not set' do
|
47
|
+
subject.should == "BANANA-unset"
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return the value when set' do
|
51
|
+
ENV['BANANA'] = 'cavendish'
|
52
|
+
|
53
|
+
subject.should == "cavendish"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'statsd_helper'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "statsd_helper/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "statsd_helper"
|
7
|
+
s.version = StatsdHelper::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ryan Boucher"]
|
10
|
+
s.email = ["ryan.boucher@distributedlife.com"]
|
11
|
+
s.homepage = "http://github.com/distributedlife/statsd_helper"
|
12
|
+
s.summary = %q{Some helpers for consitent use across of statsd gems}
|
13
|
+
s.description = %q{Some helpers for consitent use across of statsd gems. Nothing is automatic but consistency is slightly easier}
|
14
|
+
|
15
|
+
s.add_development_dependency "rspec"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsd_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-27 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &76442430 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *76442430
|
25
25
|
description: Some helpers for consitent use across of statsd gems. Nothing is automatic
|
26
26
|
but consistency is slightly easier
|
27
27
|
email:
|
@@ -30,7 +30,15 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- .rspec
|
34
|
+
- LICENSE.txt
|
33
35
|
- README
|
36
|
+
- lib/statsd_helper.rb
|
37
|
+
- lib/statsd_helper/metric.rb
|
38
|
+
- lib/statsd_helper/version.rb
|
39
|
+
- spec/metrics_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- statsd_helper.gemspec
|
34
42
|
homepage: http://github.com/distributedlife/statsd_helper
|
35
43
|
licenses: []
|
36
44
|
post_install_message:
|