fictium 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5934206031e83692052ec6d5184d6c0ea7a040f5a7c859d274eb9101daa664f4
4
- data.tar.gz: feaf049eee613925b0b3c14dcbaadb3a6a3c4f3e051b265853db873729e8ce37
3
+ metadata.gz: 6d68f0182b847a3713bd7891b4e63273ffa7a79759fea9f3081d7b840ed693a3
4
+ data.tar.gz: 91b28c80cc8291ccc7474fb4d643a5c12119742886e737eee6a0af8e4f7d7de4
5
5
  SHA512:
6
- metadata.gz: 2ecc05097ef9652469e114db2fbb484a957afbb49b80feedbbb00dac03b0e47db441dac08a8694de1b0cc6cafa25ccfa00d90d6f375343bcec4d48f91e74a9bc
7
- data.tar.gz: bf81849ffcafd6bc42c94b3ed06fedf1f2959c74a333ee2268e7cc02c8379f564512f4d0e2e8bf845f9aeb89d69ba6ce7a4c3d21373a3b26eaa360196f8fceb0
6
+ metadata.gz: 925a29a49dc0dc7ba6987e9970e500d90d327869709ad7c5134a416f71404b685219c954359acd4d5ca3e8bfb584d205dd74826cfbc7059919175c00895fa54e
7
+ data.tar.gz: f68a1b545102693083580f8cdc2542f8ddf846b0846d123bf7147ebd8dc504a0896938fee6956df6ed5b3d86ef8b92029b83477f87b6149b2646193a9cfabf30
data/CHANGELOG.md CHANGED
@@ -17,6 +17,14 @@
17
17
 
18
18
  ## LOG
19
19
 
20
+ ### 0.3.3 (2019-11-12)
21
+
22
+ Improve path recognition using controller actions.
23
+
24
+ #### Changes
25
+
26
+ - Use path parameters instead of formatting path.
27
+
20
28
  ### 0.3.2 (2019-11-12)
21
29
 
22
30
  Use path parameters instead of formatting path.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fictium (0.3.2)
4
+ fictium (0.3.3)
5
5
  activesupport (>= 5.1, < 6.2)
6
6
  json-schema (~> 2.8)
7
7
  verbs (~> 2.1.4)
@@ -3,19 +3,11 @@ module Fictium
3
3
  module Autocomplete
4
4
  module Action
5
5
  ACTION_NAME = /#([A-Z_]+)/i.freeze
6
- DEFAULT_PATHS = {
7
- index: '',
8
- create: '',
9
- new: '/new',
10
- show: '/{id}',
11
- update: '/{id}',
12
- destroy: '/{id}'
13
- }.freeze
6
+
14
7
  class << self
15
8
  def description_attributes(action, description)
16
9
  name = find_action_name(description)&.downcase
17
10
  find_summary(action, name)
18
- find_path(action, name)
19
11
  end
20
12
 
21
13
  private
@@ -34,13 +26,6 @@ module Fictium
34
26
  @descriptors ||= Fictium.configuration.default_action_descriptors || {}
35
27
  end
36
28
 
37
- def find_path(action, name)
38
- return if name.blank?
39
-
40
- key = name.to_sym
41
- action.path = DEFAULT_PATHS[key] || "/{id}/#{name}"
42
- end
43
-
44
29
  def find_action_name(description)
45
30
  match = description.match(ACTION_NAME)
46
31
  match.presence && match[1]
@@ -6,7 +6,10 @@ module Fictium
6
6
  IGNORED_PATH_PARAMETERS = %i[action controller].freeze
7
7
 
8
8
  class << self
9
+ include Rails.application.routes.url_helpers
10
+
9
11
  def extract_from_request(action, request)
12
+ extract_path(action, request)
10
13
  REQUEST_SECTIONS.each do |section|
11
14
  action.params[section] ||= ActiveSupport::HashWithIndifferentAccess.new
12
15
  send(:"parse_request_#{section}", action.params[section], action, request)
@@ -27,6 +30,25 @@ module Fictium
27
30
 
28
31
  private
29
32
 
33
+ def extract_path(action, request)
34
+ return unless action.path.nil?
35
+
36
+ mapped_controllers = transform_path(request)
37
+ full_path = CGI.unescape(url_for(**mapped_controllers.merge(only_path: true)))
38
+ action.path = full_path.sub(action.resource.base_path || '', '')
39
+ end
40
+
41
+ def transform_path(request)
42
+ {}.tap do |result|
43
+ request.path_parameters.except(*IGNORED_PATH_PARAMETERS).each do |key, _|
44
+ result[key] = "{#{key}}"
45
+ end
46
+ request.path_parameters.slice(*IGNORED_PATH_PARAMETERS).each do |key, value|
47
+ result[key] = value
48
+ end
49
+ end
50
+ end
51
+
30
52
  def parse_request_query(params, _action, request)
31
53
  request.query_parameters.each do |key, value|
32
54
  params[key] ||= {}
@@ -1,5 +1,5 @@
1
1
  module Fictium
2
- VERSION = '0.3.2'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  RAILS_MIN_VERSION = '>= 5.1'.freeze
4
4
  RAILS_MAX_VERSION = '< 6.2'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fictium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramiro Rojo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport