govuk_navigation_helpers 3.0.2 → 3.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 068eb3be3f3916e3e73b4e9f9d20fa57f880b400
4
- data.tar.gz: a5161e592acfd1b4a18969eb0340ec63d5d119e3
3
+ metadata.gz: 871ba5edc031b3cad2d1efac31fa8850fbf0e3e2
4
+ data.tar.gz: ec6709e88652bf135ce86ed2f897236d8b59c60d
5
5
  SHA512:
6
- metadata.gz: 78ff87bc456090a32b844065d1d682e5654f7623556cb79174586fd0ea5a1013f6dde2fa82370d5d7c166685b44ef5c5dec25057c7bc80832e33b3969f3bc088
7
- data.tar.gz: 58d2455c36389887901ad9026e9f9338815a0060d5dab7d9a0756587272664c47080f2c0bf0b9b9a6c476b604b69d88c823c5671d982bac7b13de51cf9ef174a
6
+ metadata.gz: 356d955ac7d17e35a9277b1c4f57da97b1c476bc2d5a410bf18f0627824566d7b7f53e062670af10c0b696e2a8d2f83c175058d63acfc2e94717c9e3142a510e
7
+ data.tar.gz: 81d2310474c16f54d99636ef143db8d7bef3ce1d1ea37d68c7badf0ef7067926fc358c645b23d4f446662a0ddd273c27415e5d8e35048bf23e5fba829c02b22a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.1.0
2
+
3
+ * Allow a statsd client to be passed in via configuration options. This will
4
+ allow us to track how many Rummager searches we run and how long they take.
5
+
1
6
  ## 3.0.2
2
7
 
3
8
  * Sort parent taxons by title before picking the first one for the breadcrumbs.
data/README.md CHANGED
@@ -22,6 +22,16 @@ And then execute:
22
22
 
23
23
  $ bundle
24
24
 
25
+ ### Configuration
26
+
27
+ This gem allows the configuration of:
28
+
29
+ - an error handler class (e.g. `Airbrake`), that implements a `notify` method
30
+ which takes an exception object (by default, it prints the exception to stdout
31
+ when not configured);
32
+ - a statsd client - when not configured, it does not do anything. This client
33
+ should implement `increment(metric)` and `time(metric, &block)`.
34
+
25
35
  ### Usage
26
36
 
27
37
  Get the JSON representation of a page and initialise the helper:
@@ -8,16 +8,25 @@ module GovukNavigationHelpers
8
8
  end
9
9
 
10
10
  class Configuration
11
- attr_writer :error_handler
12
-
13
- def initialize
14
- @configuration = {}
15
- end
11
+ attr_writer :error_handler, :statsd
16
12
 
17
13
  def error_handler
18
14
  @error_handler ||= NoErrorHandler.new
19
15
  end
20
16
 
17
+ def statsd
18
+ @statsd ||= NoStatsd.new
19
+ end
20
+
21
+ class NoStatsd
22
+ def increment(*)
23
+ end
24
+
25
+ def time(*)
26
+ yield
27
+ end
28
+ end
29
+
21
30
  class NoErrorHandler
22
31
  def notify(exception, *_args)
23
32
  puts exception
@@ -16,6 +16,10 @@ module GovukNavigationHelpers
16
16
 
17
17
  private
18
18
 
19
+ def statsd
20
+ GovukNavigationHelpers.configuration.statsd
21
+ end
22
+
19
23
  def taxons
20
24
  parent_taxons = @content_item.parent_taxons
21
25
  parent_taxons.map do |parent_taxon|
@@ -32,25 +36,29 @@ module GovukNavigationHelpers
32
36
  # temporary method that uses search to achieve this. This behaviour is to be moved into
33
37
  # the content store
34
38
  def content_related_to(taxon)
35
- begin
36
- results = Services.rummager.search(
37
- similar_to: @content_item.base_path,
38
- start: 0,
39
- count: 3,
40
- filter_taxons: [taxon.content_id],
41
- filter_content_store_document_type: Guidance::DOCUMENT_TYPES,
42
- fields: %w[title link],
43
- )['results']
44
-
45
- results.map do |result|
46
- {
47
- title: result['title'],
48
- link: result['link'],
49
- }
39
+ statsd.time(:taxonomy_sidebar_search_time) do
40
+ begin
41
+ results = Services.rummager.search(
42
+ similar_to: @content_item.base_path,
43
+ start: 0,
44
+ count: 3,
45
+ filter_taxons: [taxon.content_id],
46
+ filter_content_store_document_type: Guidance::DOCUMENT_TYPES,
47
+ fields: %w[title link],
48
+ )['results']
49
+
50
+ statsd.increment(:taxonomy_sidebar_searches)
51
+
52
+ results.map do |result|
53
+ {
54
+ title: result['title'],
55
+ link: result['link'],
56
+ }
57
+ end
58
+ rescue StandardError => e
59
+ GovukNavigationHelpers.configuration.error_handler.notify(e)
60
+ []
50
61
  end
51
- rescue StandardError => e
52
- GovukNavigationHelpers.configuration.error_handler.notify(e)
53
- []
54
62
  end
55
63
  end
56
64
  end
@@ -1,3 +1,3 @@
1
1
  module GovukNavigationHelpers
2
- VERSION = "3.0.2".freeze
2
+ VERSION = "3.1.0".freeze
3
3
  end
@@ -41,6 +41,12 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
41
41
 
42
42
  context 'given a content item tagged to taxons' do
43
43
  it 'returns a sidebar hash containing a list of parent taxons and related content' do
44
+ expect(GovukNavigationHelpers.configuration.statsd).to receive(
45
+ :increment
46
+ ).with(
47
+ :taxonomy_sidebar_searches
48
+ ).twice
49
+
44
50
  content_item = content_item_tagged_to_taxon
45
51
 
46
52
  expect(sidebar_for(content_item)).to eq(
@@ -84,6 +90,10 @@ RSpec.describe GovukNavigationHelpers::TaxonomySidebar do
84
90
  GovukNavigationHelpers.configure do |config|
85
91
  config.error_handler = error_handler
86
92
  end
93
+
94
+ expect(GovukNavigationHelpers.configuration.statsd).to_not receive(
95
+ :increment
96
+ )
87
97
  end
88
98
 
89
99
  it 'does not re-raise' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_navigation_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gds-api-adapters