hal_api-rails 0.6.0 → 0.7.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 +4 -4
- data/lib/hal_api/controller/filtering.rb +18 -0
- data/lib/hal_api/controller/resources.rb +4 -0
- data/lib/hal_api/paged_collection.rb +1 -1
- data/lib/hal_api/rails/version.rb +1 -1
- data/lib/hal_api/representer.rb +1 -0
- data/lib/hal_api/representer/collection_paging.rb +10 -0
- data/lib/hal_api/representer/uri_methods.rb +21 -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: e8ca09414db3082766a5b86ee83310563af05628
|
4
|
+
data.tar.gz: 002aceca75878356759760d73f5dd68cd6dc03d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25f710db7f628fbbd0b708c06e04f4b1f2eb8335ecbb8a48311e68ac4259ad5cfe80d5bbbd02df41d55ea846c8b0d4423055cf1fcbe64f09e37217d1d7c92d33
|
7
|
+
data.tar.gz: df4c7da616d62d01b5dddeb031b2e2c7bd94b61e6399452ab17fbe7a43ffe12c1909e5b138821de4e74dad83ac98295355a1550729a5a4220508f24faaa9f849
|
@@ -53,6 +53,24 @@ module HalApi::Controller::Filtering
|
|
53
53
|
@filters ||= parse_filters_param
|
54
54
|
end
|
55
55
|
|
56
|
+
def filter_facets
|
57
|
+
end
|
58
|
+
|
59
|
+
def index_collection
|
60
|
+
collection = defined?(super) ? super : HalApi::PagedCollection.new([])
|
61
|
+
|
62
|
+
# add facets if defined, removing filters/facets with counts of 0
|
63
|
+
non_zero_facets = (filter_facets || {}).with_indifferent_access.tap do |hash|
|
64
|
+
hash.each do |filter_key, facets|
|
65
|
+
hash[filter_key] = facets.try(:select) { |f| f.try(:[], :count) > 0 }
|
66
|
+
hash.delete(filter_key) if hash[filter_key].blank?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
collection.facets = non_zero_facets unless non_zero_facets.blank?
|
70
|
+
|
71
|
+
collection
|
72
|
+
end
|
73
|
+
|
56
74
|
private
|
57
75
|
|
58
76
|
def parse_filters_param
|
@@ -6,7 +6,7 @@ class HalApi::PagedCollection
|
|
6
6
|
extend ActiveModel::Naming
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
attr_accessor :items, :request, :options
|
9
|
+
attr_accessor :items, :request, :options, :facets
|
10
10
|
|
11
11
|
def_delegators :items, :total_count, :prev_page, :next_page, :total_pages, :first_page?, :last_page?
|
12
12
|
alias_method :total, :total_count
|
data/lib/hal_api/representer.rb
CHANGED
@@ -7,6 +7,7 @@ module HalApi::Representer::CollectionPaging
|
|
7
7
|
class_eval do
|
8
8
|
property :count
|
9
9
|
property :total
|
10
|
+
property :facets
|
10
11
|
|
11
12
|
embeds :items, decorator: lambda{|*| item_decorator }, class: lambda{|*| item_class }, zoom: :always
|
12
13
|
|
@@ -36,6 +37,14 @@ module HalApi::Representer::CollectionPaging
|
|
36
37
|
href_url_helper(represented.params)
|
37
38
|
end
|
38
39
|
|
40
|
+
def vary_url(represented)
|
41
|
+
href_url_helper(represented.params.except(*vary_params))
|
42
|
+
end
|
43
|
+
|
44
|
+
def vary_params
|
45
|
+
%w(page per zoom filters sorts)
|
46
|
+
end
|
47
|
+
|
39
48
|
def profile_url(represented)
|
40
49
|
model_uri(:collection, represented.item_class)
|
41
50
|
end
|
@@ -46,6 +55,7 @@ module HalApi::Representer::CollectionPaging
|
|
46
55
|
# if it is a lambda, execute in the context against the represented.parent (if there is one) or represented
|
47
56
|
def href_url_helper(options={})
|
48
57
|
if represented_url.nil?
|
58
|
+
options = options.except(:format)
|
49
59
|
result = url_for(options.merge(only_path: true)) rescue nil
|
50
60
|
if represented.parent
|
51
61
|
result ||= polymorphic_path([:api, represented.parent, represented.item_class], options) rescue nil
|
@@ -21,6 +21,15 @@ module HalApi::Representer::UriMethods
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
def vary_link
|
25
|
+
link(:vary) do
|
26
|
+
{
|
27
|
+
href: vary_url(represented) + vary_query_params,
|
28
|
+
templated: true,
|
29
|
+
} if vary_url(represented).present? && vary_params.present?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
24
33
|
def profile_link
|
25
34
|
link(:profile) { profile_url(represented) }
|
26
35
|
end
|
@@ -46,6 +55,18 @@ module HalApi::Representer::UriMethods
|
|
46
55
|
polymorphic_path([:api, rep])
|
47
56
|
end
|
48
57
|
|
58
|
+
def vary_url(represented)
|
59
|
+
self_url(represented)
|
60
|
+
end
|
61
|
+
|
62
|
+
def vary_params
|
63
|
+
[]
|
64
|
+
end
|
65
|
+
|
66
|
+
def vary_query_params
|
67
|
+
"{?#{vary_params.join(',')}}"
|
68
|
+
end
|
69
|
+
|
49
70
|
def becomes_represented_class(rep)
|
50
71
|
return rep unless rep.respond_to?(:becomes)
|
51
72
|
klass = rep.try(:item_class) || rep.class.try(:base_class)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal_api-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Rhoden
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|