govuk_navigation_helpers 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +10 -0
- data/lib/govuk_navigation_helpers/configuration.rb +14 -5
- data/lib/govuk_navigation_helpers/taxonomy_sidebar.rb +26 -18
- data/lib/govuk_navigation_helpers/version.rb +1 -1
- data/spec/taxonomy_sidebar_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 871ba5edc031b3cad2d1efac31fa8850fbf0e3e2
|
4
|
+
data.tar.gz: ec6709e88652bf135ce86ed2f897236d8b59c60d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 356d955ac7d17e35a9277b1c4f57da97b1c476bc2d5a410bf18f0627824566d7b7f53e062670af10c0b696e2a8d2f83c175058d63acfc2e94717c9e3142a510e
|
7
|
+
data.tar.gz: 81d2310474c16f54d99636ef143db8d7bef3ce1d1ea37d68c7badf0ef7067926fc358c645b23d4f446662a0ddd273c27415e5d8e35048bf23e5fba829c02b22a
|
data/CHANGELOG.md
CHANGED
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
@@ -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
|
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-
|
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
|