sidekiq-statsd 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.yardopts +1 -1
  2. data/README.md +8 -4
  3. data/lib/sidekiq/statsd/client.rb +10 -10
  4. data/lib/sidekiq/statsd/server_middleware.rb +8 -9
  5. data/lib/sidekiq/statsd/version.rb +1 -1
  6. data/spec/sidekiq/statsd/client_spec.rb +6 -6
  7. data/spec/spec_helper.rb +1 -0
  8. data/vendor/ruby/1.9.1/bin/yard +1 -1
  9. data/vendor/ruby/1.9.1/bin/yardoc +1 -1
  10. data/vendor/ruby/1.9.1/bin/yri +1 -1
  11. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/default_factory.rb +176 -0
  12. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/default_tag.rb +12 -0
  13. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/directives.rb +595 -0
  14. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/library.rb +630 -0
  15. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/option_tag.rb +12 -0
  16. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/overload_tag.rb +65 -0
  17. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/ref_tag.rb +7 -0
  18. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/ref_tag_list.rb +27 -0
  19. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/tag.rb +57 -0
  20. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/tag_format_error.rb +6 -0
  21. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/default_factory_spec.rb +152 -0
  22. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/default_tag_spec.rb +11 -0
  23. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/directives_spec.rb +436 -0
  24. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/library_spec.rb +34 -0
  25. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/overload_tag_spec.rb +53 -0
  26. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/ref_tag_list_spec.rb +53 -0
  27. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/example.erb +11 -0
  28. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/index.erb +3 -0
  29. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/option.erb +24 -0
  30. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/overload.erb +14 -0
  31. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/see.erb +8 -0
  32. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/tag.erb +20 -0
  33. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/setup.rb +55 -0
  34. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/example.erb +12 -0
  35. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/index.erb +1 -0
  36. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/option.erb +20 -0
  37. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/overload.erb +19 -0
  38. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/see.erb +11 -0
  39. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/tag.erb +13 -0
  40. data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/guide/tags/html/setup.rb +8 -0
  41. metadata +34 -4
data/.yardopts CHANGED
@@ -1,3 +1,3 @@
1
- --title 'Sidekiq::Throttler Documentation'
1
+ --title 'Sidekiq::Statsd Documentation'
2
2
  --charset utf-8
3
3
  --markup markdown
data/README.md CHANGED
@@ -31,12 +31,16 @@ Sidekiq::Statsd to your server middleware:
31
31
  ```ruby
32
32
  Sidekiq.configure_server do |config|
33
33
  config.server_middleware do |chain|
34
- chain.add Sidekiq::Statsd, env: "production", prefix: "worker", host: "localhost", port: 8125
34
+ chain.add Sidekiq::Statsd::ServerMiddleware, env: "production", prefix: "worker", host: "localhost", port: 8125
35
35
  end
36
36
  end
37
- ```
38
37
 
39
- ## Usage
38
+ # @param [Hash] options The options to initialize the StatsD client.
39
+ # @option options [String] :env ("production") The env to segment the metric key (e.g. env.prefix.worker_name.success|failure).
40
+ # @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
41
+ # @option options [String] :host ("localhost") The StatsD host.
42
+ # @option options [String] :port ("8125") The StatsD port.
43
+ ```
40
44
 
41
45
  ## Contributing
42
46
 
@@ -48,4 +52,4 @@ end
48
52
 
49
53
  ## License
50
54
 
51
- MIT Licensed. See LICENSE.txt for details.
55
+ MIT Licensed. See LICENSE.txt for details.
@@ -8,17 +8,17 @@ module Sidekiq::Statsd
8
8
  # Initializes StatsD client with options.
9
9
  #
10
10
  # @param [Hash] options The options to initialize the StatsD client.
11
- # @option options [String] :env ("production")
12
- # @option options [String] :prefix ("worker")
13
- # @option options [String] :host ("localhost")
14
- # @option options [String] :port ("8125")
11
+ # @option options [String] :env ("production") The env to segment the metric key (e.g. env.prefix.worker_name.success|failure).
12
+ # @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
13
+ # @option options [String] :host ("localhost") The StatsD host.
14
+ # @option options [String] :port ("8125") The StatsD port.
15
15
  def initialize options={}
16
- @options = { "env" => "production",
17
- "prefix" => "worker",
18
- "host" => "localhost",
19
- "port" => 8125 }.merge options
16
+ @options = { env: "production",
17
+ prefix: "worker",
18
+ host: "localhost",
19
+ port: 8125 }.merge options
20
20
 
21
- @statsd_client = ::Statsd.new @options["host"], @options["port"]
21
+ @statsd_client = ::Statsd.new @options[:host], @options[:port]
22
22
  end
23
23
 
24
24
  ##
@@ -28,7 +28,7 @@ module Sidekiq::Statsd
28
28
  #
29
29
  # @param key [String] The key to be incremented.
30
30
  def increment key
31
- @statsd_client.increment [@options["env"], @options["prefix"], key].join(".")
31
+ @statsd_client.increment [@options[:env], @options[:prefix], key].join(".")
32
32
  end
33
33
  end
34
34
  end
@@ -9,12 +9,12 @@ module Sidekiq::Statsd
9
9
  # Initializes the middleware with options.
10
10
  #
11
11
  # @param [Hash] options The options to initialize the StatsD client.
12
- # @option options [String] :env ("production")
13
- # @option options [String] :prefix ("worker")
14
- # @option options [String] :host ("localhost")
15
- # @option options [String] :port ("8125")
12
+ # @option options [String] :env ("production") The env to segment the metric key (e.g. env.prefix.worker_name.success|failure).
13
+ # @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
14
+ # @option options [String] :host ("localhost") The StatsD host.
15
+ # @option options [String] :port ("8125") The StatsD port.
16
16
  def initialize options={}
17
- @options = options
17
+ @statsd = Sidekiq::Statsd::Client.new options
18
18
  end
19
19
 
20
20
  ##
@@ -24,13 +24,12 @@ module Sidekiq::Statsd
24
24
  # @param msg [Hash] The job message.
25
25
  # @param queue [String] The current queue.
26
26
  def call worker, msg, queue
27
- stastd = Sidekiq::Statsd::Client.new @options
28
27
  yield
29
- stastd.increment [worker.class.name, "success"].join(".")
28
+ @statsd.increment [worker.class.name, "success"].join(".")
30
29
  rescue => e
31
- stastd.increment [worker.class.name, "failure"].join(".")
30
+ @statsd.increment [worker.class.name, "failure"].join(".")
32
31
  raise e
33
32
  end
34
- end # Statsd
33
+ end # ServerMiddleware
35
34
  end # Sidekiq
36
35
 
@@ -1,6 +1,6 @@
1
1
  module Sidekiq
2
2
  module Statsd
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
6
6
 
@@ -9,24 +9,24 @@ describe Sidekiq::Statsd::Client do
9
9
 
10
10
  context "user defined options" do
11
11
  let(:options) do
12
- { "prefix" => "super",
13
- "env" => "man",
14
- "host" => "lobster",
15
- "port" => 6666 }
12
+ { prefix: "super",
13
+ env: "man",
14
+ host: "lobster",
15
+ port: 6666 }
16
16
  end
17
17
 
18
18
  subject(:statsd) { described_class.new options }
19
19
 
20
20
  describe "#initialize" do
21
21
  it "initializes Statsd client" do
22
- ::Statsd.should_receive(:new).with options["host"], options["port"]
22
+ ::Statsd.should_receive(:new).with options[:host], options[:port]
23
23
  statsd
24
24
  end
25
25
  end
26
26
 
27
27
  describe "#increment" do
28
28
  it "increments counter" do
29
- statsd_client.should_receive(:increment).with [options["env"], options["prefix"], worker_name].join(".")
29
+ statsd_client.should_receive(:increment).with [options[:env], options[:prefix], worker_name].join(".")
30
30
  statsd.increment worker_name
31
31
  end
32
32
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ unless ENV["CI"]
8
8
  require "simplecov"
9
9
  SimpleCov.start do
10
10
  add_filter "/spec/"
11
+ add_filter "/vendor/"
11
12
  end
12
13
  end
13
14
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/Users/pablo/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
2
2
  #
3
3
  # This file was generated by RubyGems.
4
4
  #
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/Users/pablo/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
2
2
  #
3
3
  # This file was generated by RubyGems.
4
4
  #
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ #!/Users/pablo/.rvm/rubies/ruby-1.9.3-p392/bin/ruby
2
2
  #
3
3
  # This file was generated by RubyGems.
4
4
  #
@@ -0,0 +1,176 @@
1
+ module YARD
2
+ module Tags
3
+ class DefaultFactory
4
+ TYPELIST_OPENING_CHARS = '[({<'
5
+ TYPELIST_CLOSING_CHARS = '>})]'
6
+
7
+ # Parses tag text and creates a new tag with descriptive text
8
+ #
9
+ # @param tag_name the name of the tag to parse
10
+ # @param [String] text the raw tag text
11
+ # @return [Tag] a tag object with the tag_name and text values filled
12
+ def parse_tag(tag_name, text)
13
+ Tag.new(tag_name, text.strip)
14
+ end
15
+
16
+ # Parses tag text and creates a new tag with a key name and descriptive text
17
+ #
18
+ # @param tag_name the name of the tag to parse
19
+ # @param [String] text the raw tag text
20
+ # @return [Tag] a tag object with the tag_name, name and text values filled
21
+ def parse_tag_with_name(tag_name, text)
22
+ name, text = *extract_name_from_text(text)
23
+ Tag.new(tag_name, text, nil, name)
24
+ end
25
+
26
+ # Parses tag text and creates a new tag with formally declared types and
27
+ # descriptive text
28
+ #
29
+ # @param tag_name the name of the tag to parse
30
+ # @param [String] text the raw tag text
31
+ # @return [Tag] a tag object with the tag_name, types and text values filled
32
+ def parse_tag_with_types(tag_name, text)
33
+ name, types, text = *extract_types_and_name_from_text(text)
34
+ raise TagFormatError, "cannot specify a name before type list for '@#{tag_name}'" if name
35
+ Tag.new(tag_name, text, types)
36
+ end
37
+
38
+ # Parses tag text and creates a new tag with formally declared types, a key
39
+ # name and descriptive text
40
+ #
41
+ # @param tag_name the name of the tag to parse
42
+ # @param [String] text the raw tag text
43
+ # @return [Tag] a tag object with the tag_name, name, types and text values filled
44
+ def parse_tag_with_types_and_name(tag_name, text)
45
+ name, types, text = *extract_types_and_name_from_text(text)
46
+ name, text = *extract_name_from_text(text) unless name
47
+ Tag.new(tag_name, text, types, name)
48
+ end
49
+
50
+ # Parses tag text and creates a new tag with formally declared types, a title
51
+ # on the first line and descriptive text
52
+ #
53
+ # @param tag_name the name of the tag to parse
54
+ # @param [String] text the raw tag text
55
+ # @return [Tag] a tag object with the tag_name, name, types and text values filled
56
+ def parse_tag_with_types_and_title(tag_name, text)
57
+ name, types, text = *extract_types_and_name_from_text_unstripped(text)
58
+ if name
59
+ title, desc = name, text
60
+ else
61
+ title, desc = *extract_title_and_desc_from_text(text)
62
+ end
63
+ Tag.new(tag_name, desc, types, title)
64
+ rescue TagFormatError
65
+ Tag.new(tag_name, '', types, nil)
66
+ end
67
+
68
+ def parse_tag_with_title_and_text(tag_name, text)
69
+ title, desc = *extract_title_and_desc_from_text(text)
70
+ Tag.new(tag_name, desc, nil, title)
71
+ end
72
+
73
+ def parse_tag_with_types_name_and_default(tag_name, text)
74
+ # Can't allow () in a default tag, otherwise the grammar is too ambiguous when types is omitted.
75
+ open, close = TYPELIST_OPENING_CHARS.gsub('(', ''), TYPELIST_CLOSING_CHARS.gsub(')', '')
76
+ name, types, text = *extract_types_and_name_from_text(text, open, close)
77
+ name, text = *extract_name_from_text(text) unless name
78
+ if text =~ /\A\(/
79
+ _, default, text = *extract_types_and_name_from_text(text, '(', ')')
80
+ DefaultTag.new(tag_name, text, types, name, default)
81
+ else
82
+ DefaultTag.new(tag_name, text, types, name, nil)
83
+ end
84
+ end
85
+
86
+ def parse_tag_with_options(tag_name, text)
87
+ name, text = *extract_name_from_text(text)
88
+ OptionTag.new(tag_name, name, parse_tag_with_types_name_and_default(tag_name, text))
89
+ end
90
+
91
+ private
92
+
93
+ # Extracts the name from raw tag text returning the name and remaining value
94
+ #
95
+ # @param [String] text the raw tag text
96
+ # @return [Array] an array holding the name as the first element and the
97
+ # value as the second element
98
+ def extract_name_from_text(text)
99
+ text.strip.split(/\s+/, 2)
100
+ end
101
+
102
+ def extract_title_and_desc_from_text(text)
103
+ raise TagFormatError if text.nil? || text.empty?
104
+ title, desc = nil, nil
105
+ if text =~ /\A[ \t]\n/
106
+ desc = text
107
+ else
108
+ text = text.split(/\r?\n/)
109
+ title = text.shift.squeeze(' ').strip
110
+ desc = text.join("\n")
111
+ end
112
+ [title, desc]
113
+ end
114
+
115
+ # Parses a [], <>, {} or () block at the beginning of a line of text
116
+ # into a list of comma delimited values.
117
+ #
118
+ # @example
119
+ # obj.parse_types('[String, Array<Hash, String>, nil]') # => [nil, ['String', 'Array<Hash, String>', 'nil'], ""]
120
+ # obj.parse_types('b<String> A string') # => ['b', ['String'], 'A string']
121
+ #
122
+ # @return [Array(String, Array<String>, String)] the text before the type
123
+ # list (or nil), followed by the type list parsed into an array of
124
+ # strings, followed by the text following the type list.
125
+ def extract_types_and_name_from_text(text, opening_types = TYPELIST_OPENING_CHARS, closing_types = TYPELIST_CLOSING_CHARS)
126
+ before, list, text = *extract_types_and_name_from_text_unstripped(text, opening_types, closing_types)
127
+ if list.nil?
128
+ [nil, nil, text.strip]
129
+ else
130
+ [before ? before.strip : nil, list.map {|e| e.strip }, text.strip]
131
+ end
132
+ end
133
+
134
+ def extract_types_and_name_from_text_unstripped(text, opening_types = TYPELIST_OPENING_CHARS, closing_types = TYPELIST_CLOSING_CHARS)
135
+ s, e = 0, 0
136
+ before = ''
137
+ list, level, seen_space, i = [''], 0, false, 0
138
+ last_seen = ''
139
+ while i < text.length
140
+ c = text[i, 1]
141
+ if level > 0 && c == '#' && text[i+1..-1] =~ CodeObjects::METHODNAMEMATCH
142
+ list.last << c + $&
143
+ i += $&.length + 1
144
+ next
145
+ elsif opening_types.include?(c)
146
+ list.last << c if level > 0
147
+ s = i if level == 0
148
+ level += 1
149
+ elsif closing_types.include?(c)
150
+ level -= 1 unless last_seen == '=' && c == '>'
151
+ break e = i if level == 0
152
+ list.last << c
153
+ elsif c == ',' && level == 1
154
+ list.push ''
155
+ elsif c =~ /\S/ && level == 0
156
+ break e = i if seen_space && list == ['']
157
+ before << c
158
+ elsif c =~ /\s/ && level == 0 && !before.empty?
159
+ seen_space = true
160
+ elsif level >= 1
161
+ list.last << c
162
+ end
163
+ last_seen = c
164
+ i += 1
165
+ end
166
+
167
+ before = before.empty? ? nil : before
168
+ if list.size == 1 && list.first == ''
169
+ [nil, nil, text]
170
+ else
171
+ [before, list, text[(e+1)..-1]]
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,12 @@
1
+ module YARD
2
+ module Tags
3
+ class DefaultTag < Tag
4
+ attr_reader :defaults
5
+
6
+ def initialize(tag_name, text, types = nil, name = nil, defaults = nil)
7
+ super(tag_name, text, types, name)
8
+ @defaults = defaults
9
+ end
10
+ end
11
+ end
12
+ end