nunes 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ # 0.3.0
2
+
3
+ ## Backwards Compatibility Break
4
+
5
+ * Cleaning action view template and partial paths before sending to adapter. Prior to this change, action view metrics looked like: action_view.template.app.views.posts.post.html.erb. They now look like: action_view.template.app_views_posts_post_html_erb. The reason is that "." is typically a namespace in most metric services, which means really deep nesting of metrics, especially for views rendered from engines in gems. This keeps shallows up the nesting. Thanks to @dewski for reporting.
6
+
1
7
  # 0.2.0
2
8
 
3
9
  ## Backwards Compatibility Break
data/README.md CHANGED
@@ -16,6 +16,10 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install nunes
18
18
 
19
+ ## Compatibility
20
+
21
+ * >= Ruby 1.9
22
+
19
23
  ## Usage
20
24
 
21
25
  nunes works out of the box with [instrumental app](http://instrumentalapp.com) (my person favorite) and [statsd](https://github.com/reinh/statsd). All you need to do is subscribe using an instance of statsd or instrumental's agent and you are good to go.
@@ -57,19 +57,17 @@ module Nunes
57
57
  # Private: The default metric namespace separator.
58
58
  Separator = "."
59
59
 
60
- RegexSeparator = Regexp.escape(Separator)
61
-
62
- # Private: Regex to match metric ending with separator.
63
- StartsOrEndsWithSeparator = /\A#{RegexSeparator}|#{RegexSeparator}\Z/
64
-
65
60
  # Private
66
61
  Nothing = ""
67
62
 
68
63
  # Private: Prepare a metric name before it is sent to the adapter's client.
69
- def prepare(metric)
70
- metric = metric.to_s.gsub(ReplaceRegex, Separator)
71
- metric.squeeze!(Separator)
72
- metric.gsub!(StartsOrEndsWithSeparator, Nothing)
64
+ def prepare(metric, replacement = Separator)
65
+ escaped = Regexp.escape(replacement)
66
+ replace_begin_end_regex = /\A#{escaped}|#{escaped}\Z/
67
+
68
+ metric = metric.to_s.gsub(ReplaceRegex, replacement)
69
+ metric.squeeze!(replacement)
70
+ metric.gsub!(replace_begin_end_regex, Nothing)
73
71
  metric
74
72
  end
75
73
  end
@@ -29,14 +29,17 @@ module Nunes
29
29
  end
30
30
  end
31
31
 
32
+ # Private: What to replace file separators with.
33
+ FileSeparatorReplacement = "_"
34
+
32
35
  # Private: Converts an identifier to a metric name. Strips out the rails
33
36
  # root from the full path.
34
37
  #
35
38
  # identifier - The String full path to the template or partial.
36
39
  def identifier_to_metric(kind, identifier)
37
- rails_root = ::Rails.root.to_s + File::SEPARATOR
38
- view_path = identifier.gsub(rails_root, '')
39
- "action_view.#{kind}.#{view_path}" if view_path
40
+ view_path = identifier.to_s.gsub(::Rails.root.to_s, "")
41
+ metric = adapter.prepare(view_path, FileSeparatorReplacement)
42
+ "action_view.#{kind}.#{metric}"
40
43
  end
41
44
  end
42
45
  end
@@ -1,3 +1,3 @@
1
1
  module Nunes
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -106,11 +106,11 @@ class AdapterTest < ActiveSupport::TestCase
106
106
  end
107
107
  end
108
108
 
109
- test "prepare does not modify original metric" do
109
+ test "prepare does not modify original metric object" do
110
110
  adapter = Nunes::Adapter.new(nil)
111
- original = "app/views/posts"
111
+ original = "app.views.posts"
112
112
  result = adapter.prepare("original")
113
113
 
114
- assert_equal "app/views/posts", original
114
+ assert_equal "app.views.posts", original
115
115
  end
116
116
  end
@@ -18,13 +18,13 @@ class ViewInstrumentationTest < ActionController::TestCase
18
18
  get :index
19
19
 
20
20
  assert_response :success
21
- assert_timer "action_view.template.app.views.posts.index.html.erb"
21
+ assert_timer "action_view.template.app_views_posts_index_html_erb"
22
22
  end
23
23
 
24
24
  test "render_partial" do
25
25
  get :index
26
26
 
27
27
  assert_response :success
28
- assert_timer "action_view.partial.app.views.posts._post.html.erb"
28
+ assert_timer "action_view.partial.app_views_posts_post_html_erb"
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nunes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
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: 2013-04-23 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler