mongoid-path_extension 0.1.4 → 0.2.0

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: bf48430bb1dd3ac34563c2890f6c8bb54920e6d4cb46b6d2407f2eb9f267b1c2
4
- data.tar.gz: eefb073e6ed0a9ef27ace4d08cea509746faebbbee5e2c6c73d12d343448d30d
3
+ metadata.gz: d546c233ca871e5a593b7b15258fac16b11b95e5437e9de723e4466637745152
4
+ data.tar.gz: 442abc2acd91f2891fead82ff9711739ded7f1f596b4e8a02b9189aac0082051
5
5
  SHA512:
6
- metadata.gz: 7410b776693f7e199e35707f5cb00c59cc260f89bca7f21faf51185984d32e993ea1cf980a1ff694983aa73baa251cf52415372303f34269a61dcad12e70e55d
7
- data.tar.gz: 9515f1f17cb93a14aa2e539b349d8ece7cc498d78691623c40a3ef7f58279a39f96221abb34ee8a2ca7adcf8a413b3f7c040331319fd5784645383aaacf7da00
6
+ metadata.gz: fe93b14e53bb80f2427e4831b885dfd8cce51b6286bd9666713b4fa57b494db1dc80856e6fab341e8b81f0a6105b4264d716fad5a82c53057aa4aa1a7a177a4e
7
+ data.tar.gz: 72724dcdaa0adae4cfa1483da7bbe5e76250ef270335c3565de5b1f52a22277ffee6a828fc2334170cfc3b4cf4f39ec8dedd07a288ff9c3746a0bbea0cfaefa8
@@ -9,7 +9,7 @@ jobs:
9
9
  fail-fast: false
10
10
  matrix:
11
11
  gemfile: ["6", "7", "8"]
12
- ruby: ["2.7", "3.0", "3.1"]
12
+ ruby: ["2.7", "3.0", "3.1", "3.2"]
13
13
  runs-on: ubuntu-latest
14
14
  services:
15
15
  mongodb:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.0
4
+
5
+ * Add permalink setter
6
+
3
7
  ## 0.1.4
4
8
 
5
9
  * Mongoid 8 compatibility
data/README.md CHANGED
@@ -38,6 +38,9 @@ my_doc.path.permalink # => 'LevelThree'
38
38
  my_doc.path.parent_path # => 'LevelOne/LevelTwo'
39
39
  my_doc.path.parent_permalink # => 'LevelTwo'
40
40
  my_doc.path.has_parent? # => true
41
+
42
+ my_doc.path.permalink = 'NewPermalink'
43
+ puts my_doc.path.permalink # => 'NewPermalink'
41
44
  ```
42
45
 
43
46
  ## Development
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  class PathExtension < String
3
- VERSION = '0.1.4'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -2,6 +2,8 @@ require 'mongoid'
2
2
 
3
3
  module Mongoid
4
4
  class PathExtension < String
5
+ delegate(:permalink, to: :parent, prefix: true)
6
+
5
7
  def initialize(str)
6
8
  super str.to_s
7
9
  @str = str.to_s
@@ -20,32 +22,31 @@ module Mongoid
20
22
  components.last
21
23
  end
22
24
 
25
+ def permalink=(value)
26
+ return if value.blank?
27
+ new_str = [parent.to_s, value].join('/')
28
+ @str.replace(new_str)
29
+ end
30
+
23
31
  def absolute
24
32
  ['/', @str].join
25
33
  end
26
34
 
27
35
  def has_parent?
28
- components.length > 1
36
+ parent.present?
29
37
  end
30
38
 
31
- def ancestor_paths
32
- return unless has_parent?
33
- res = []
34
- components[0..-2].each_with_index do |component, index|
35
- res << components[0..index].join('/')
36
- end
37
- res
39
+ def parent
40
+ ancestors.last
38
41
  end
42
+ alias_method :parent_path, :parent
39
43
 
40
- def parent_path
41
- return unless has_parent?
42
- components[0..-2].join('/')
43
- end
44
-
45
- def parent_permalink
46
- return unless has_parent?
47
- components[-2]
44
+ def ancestors
45
+ components[0..-2].each_with_index.map do |component, index|
46
+ Mongoid::PathExtension.new(components[0..index].join('/'))
47
+ end
48
48
  end
49
+ alias_method :ancestor_paths, :ancestors
49
50
 
50
51
  class << self
51
52
  def demongoize(value)
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'guard'
26
26
  spec.add_development_dependency 'guard-minitest'
27
27
  spec.add_development_dependency 'minitest'
28
- spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rake'
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-path_extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-17 00:00:00.000000000 Z
11
+ date: 2023-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: '0'
111
111
  description:
112
112
  email:
113
113
  - tomas.celizna@gmail.com