wolf_core 1.0.69 → 1.0.70

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
  SHA256:
3
- metadata.gz: 4d5fa238459aefb14f513bd81c063aff7227a31f27ff2b3d56fbc98b4cfcd38b
4
- data.tar.gz: ec08c21d261cde65e3107cde28b3d297d797ee27724df5996b5aea23e43b4755
3
+ metadata.gz: bc7e1aed79786c312930031227ec5cbd339d3415a22178ec0539f606f43abb89
4
+ data.tar.gz: 4e3245f77f19ad9d00b1eb11258e4c0828694938a06bf647f45988488b7f6158
5
5
  SHA512:
6
- metadata.gz: 7a5f7d94c752f04cef2bd762cfef9ba6ae77ff3c57e5d0913fbce580fa8f88a18e29c2c40cb6c287540cfa193fa95b4ef42335824050390fc52f9c1585ed9d64
7
- data.tar.gz: cf5ad9f109e43bbb6beac1f24eaba663515a83f0c955a949c29469067c433c6637c870dc35c7a1c9e89d42bd8bbddae61ad90099503e11e403939b45b0791ce3
6
+ metadata.gz: 7e1a7e8f0020bc1e1a4b1ed6edb861680cb543167d431b76b47153bd8ee9e536fe4e5662a26728d8205a4f282d9c32b382c1f3704c3f8d267b9c7a286a5741f2
7
+ data.tar.gz: dc29ae8cf0eb87f0c3bede9f273bbfb924d5fbc66df9d935b28863d92f8638553541df92e1671602e86501c594af157cc698abe94006618b95972262653fb6d2
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # In order to use this module on a model you only need to include it and implement the friendly_id_candidates method.
3
+ # Steps to use this module:
4
+ # 1. Create a migration to add the friendly_id column to your model.
5
+ # 2. Include the WolfCore::FriendlyModelId in your model.
6
+ # 3. Implement the friendly_id_candidates method in your model.
4
7
  #
5
8
  # Example:
6
9
  #
@@ -8,13 +11,15 @@
8
11
  # include WolfCore::FriendlyModelId
9
12
  #
10
13
  # def friendly_id_candidates
11
- # [[:name], [:name, :id]]
14
+ # [:fullname, :address]
12
15
  # end
13
16
  # end
14
- # This will generate a friendly_id based on the name field.
15
- # If it is not unique it will append the id to the friendly_id.
16
17
  #
17
- # You can also override the set_friendly_id method to customize the friendly_id generation
18
+ # This will generate a friendly_id based on the fullname field.
19
+ # If the fullname is not unique, it will attempt to use the address field instead.
20
+ # If neither can be used to generate a unique friendly_id, it will append the id to
21
+ # the value of the first field name in the array returned by the friendly_id_candidates
22
+ # method, which is fullname in this case.
18
23
 
19
24
  module WolfCore
20
25
  module FriendlyModelId
@@ -39,12 +44,12 @@ module WolfCore
39
44
  friendly_id = find_unique_friendly_id
40
45
  return friendly_id if friendly_id.present?
41
46
 
42
- default_candidate = Array(friendly_id_candidates.first) + [:id]
47
+ default_candidate = friendly_id_candidates_array.first + [:id]
43
48
  convert_candidate_to_friendly_id(default_candidate)
44
49
  end
45
50
 
46
51
  def find_unique_friendly_id
47
- friendly_id_candidates.each do |candidate|
52
+ friendly_id_candidates_array.each do |candidate|
48
53
  friendly_id = convert_candidate_to_friendly_id(candidate)
49
54
  return friendly_id if friendly_id.present? && !friendly_id_used?(friendly_id)
50
55
  end
@@ -55,6 +60,10 @@ module WolfCore
55
60
  [:id]
56
61
  end
57
62
 
63
+ def friendly_id_candidates_array
64
+ Array(friendly_id_candidates)
65
+ end
66
+
58
67
  def convert_candidate_to_friendly_id(candidate)
59
68
  candidate = Array(candidate)
60
69
  candidate.map!(&:to_sym).uniq!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WolfCore
4
- VERSION = "1.0.69"
4
+ VERSION = "1.0.70"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wolf_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.69
4
+ version: 1.0.70
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Roncallo