url_params_manager 0.1.0 → 0.2.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: 20007cb9733a6548af2f7fb5dbb1c3e1bf4cf4c1
4
- data.tar.gz: fd0c71ec50dd016dd88291ab42118c05a139dcbd
3
+ metadata.gz: ebb47a5d6d6197871e1283d76419797d8926ac5b
4
+ data.tar.gz: d2db61a2aae5eb6eb74dcd4e17c088b2573cf15b
5
5
  SHA512:
6
- metadata.gz: f255f9748eef06fb3f09fc28b13cd5d092ddaecfe9ead9d9d11375cd0fc86539f24c222b194d0cce83ee77d9220f43c4d9a72a843c2c2b86edbbbfc06b8d11e6
7
- data.tar.gz: 64f773adecfad17d95a6d29aedf715c866ace65113d366b5cb0a48e42251d04d17c7e890a4c5b46eeb2220bef9dab75fa51bb46c21b1682879cca35aa7d26ba0
6
+ metadata.gz: f45fc8c47d9272c81731f44ccb795e7a40e780a2b0a1cee7fe36c29db5179131424a5778edd85dab2f065e8a65ab30557f9dae6ccf426a002c43f004bd422ad6
7
+ data.tar.gz: 8e47b4f4eb4a004835206bba032d636b5bfdbaba1c7012ab10f26a162179d354d933313ba8e9b4669835846d15a6c727bd52d4e2d90120c42e74b9fac3d2f56a
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /pkg/
9
9
  /spec/reports/
10
10
  /tmp/
11
+ /.ruby-gemset
12
+ /.ruby-version
data/README.md CHANGED
@@ -102,6 +102,12 @@ default_params = {
102
102
  default_params: default_params # Default Params map
103
103
  ```
104
104
 
105
+ ### `filter_params_treatment`
106
+
107
+ `UrlParamsManager` object can receive a `filter_params_treatment` option with a callable object.
108
+ The `filter_params` will be passed to that callable object before returning on `filters_from_url_params` calls
109
+ as well as at the beginning of `url_args_from_filters` calls.
110
+
105
111
  ### Building URLs
106
112
 
107
113
  ```ruby
@@ -135,7 +141,7 @@ routes.rb file:
135
141
 
136
142
  Rails.application.routes.draw do
137
143
 
138
- get 'search(/*filters)', to: 'articles#index', as: :articles_search
144
+ get 'search(/*filters)', to: 'articles#index', as: :my_search
139
145
  end
140
146
  ```
141
147
 
@@ -165,7 +171,7 @@ With a URL like we built before: `'/search/feat-helipad/feat-swimming-pool/cap-2
165
171
 
166
172
  ```ruby
167
173
  {
168
- capacity: ['25+'],
174
+ capacity: '25+',
169
175
  page: 2,
170
176
  feature: ['helipad', 'swimming-pool'],
171
177
  something: ['another', 'other'],
@@ -204,3 +210,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
204
210
  3. Commit your changes (`git commit -am 'Add some feature'`)
205
211
  4. Push to the branch (`git push origin my-new-feature`)
206
212
  5. Create a new Pull Request
213
+
214
+ ## Changeset
215
+
216
+ ### v.0.2.0
217
+
218
+ - added `filter_params_treatment` option.
@@ -4,10 +4,16 @@ require 'url_params_manager/service'
4
4
  require 'url_params_manager/version'
5
5
 
6
6
  module UrlParamsManager
7
- def self.for(url_to_filter_params: nil, indexed_url_params_order: nil, app_url_helpers: nil, default_params: {})
7
+ def self.for(url_to_filter_params: nil,
8
+ indexed_url_params_order: nil,
9
+ app_url_helpers: nil,
10
+ default_params: {},
11
+ filter_params_treatment: ->(filter_params) { filter_params }
12
+ )
8
13
  Service.new url_to_filter_params: url_to_filter_params,
9
14
  indexed_url_params_order: indexed_url_params_order,
10
15
  app_url_helpers: app_url_helpers,
11
- default_params: default_params
16
+ default_params: default_params,
17
+ filter_params_treatment: filter_params_treatment
12
18
  end
13
19
  end
@@ -1,13 +1,24 @@
1
1
  module UrlParamsManager
2
2
  class Service
3
- attr_reader :app_url_helpers, :url_to_filter_params, :indexed_url_params_order, :filter_to_url_params, :default_params
4
-
5
- def initialize(url_to_filter_params: nil, indexed_url_params_order: nil, app_url_helpers: nil, default_params: {})
3
+ attr_reader :app_url_helpers,
4
+ :url_to_filter_params,
5
+ :indexed_url_params_order,
6
+ :filter_to_url_params,
7
+ :default_params,
8
+ :filter_params_treatment
9
+
10
+ def initialize(url_to_filter_params: nil,
11
+ indexed_url_params_order: nil,
12
+ app_url_helpers: nil,
13
+ default_params: {},
14
+ filter_params_treatment: ->(filter_params) { filter_params }
15
+ )
6
16
  @url_to_filter_params = url_to_filter_params
7
17
  @filter_to_url_params = url_to_filter_params.invert
8
18
  @indexed_url_params_order = indexed_url_params_order
9
19
  @app_url_helpers = app_url_helpers
10
20
  @default_params = default_params
21
+ @filter_params_treatment = filter_params_treatment
11
22
  end
12
23
 
13
24
  # for url/path methods from filter args
@@ -31,7 +42,9 @@ module UrlParamsManager
31
42
  end
32
43
  end
33
44
 
34
- filters.merge querystring_to_filters(params)
45
+ pars = filters.merge querystring_to_filters(params)
46
+
47
+ filter_params_treatment.call pars
35
48
  end
36
49
 
37
50
  def querystring_to_filters(querystring_params)
@@ -62,7 +75,8 @@ module UrlParamsManager
62
75
  end
63
76
 
64
77
  def url_args_from_filters(filter_args)
65
- valid_filter_args = remove_defaults(filter_args)
78
+ filter_pars = filter_params_treatment.call filter_args
79
+ valid_filter_args = remove_defaults(filter_pars)
66
80
  bare_args = translate_filter_keys(valid_filter_args)
67
81
 
68
82
  in_uri_args = bare_args.select { |(k, _)| indexed_url_params_order.include? k }
@@ -1,3 +1,3 @@
1
1
  module UrlParamsManager
2
- VERSION = "0.1.0"
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url_params_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2015-05-28 00:00:00.000000000 Z
12
+ date: 2015-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 2.4.6
208
+ rubygems_version: 2.2.2
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Allows SEO Friendly urls for search pages to be built easily. Intended to