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 +4 -4
- data/.github/workflows/test.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +3 -0
- data/lib/mongoid/path_extension/version.rb +1 -1
- data/lib/mongoid/path_extension.rb +17 -16
- data/mongoid-path_extension.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d546c233ca871e5a593b7b15258fac16b11b95e5437e9de723e4466637745152
|
4
|
+
data.tar.gz: 442abc2acd91f2891fead82ff9711739ded7f1f596b4e8a02b9189aac0082051
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe93b14e53bb80f2427e4831b885dfd8cce51b6286bd9666713b4fa57b494db1dc80856e6fab341e8b81f0a6105b4264d716fad5a82c53057aa4aa1a7a177a4e
|
7
|
+
data.tar.gz: 72724dcdaa0adae4cfa1483da7bbe5e76250ef270335c3565de5b1f52a22277ffee6a828fc2334170cfc3b4cf4f39ec8dedd07a288ff9c3746a0bbea0cfaefa8
|
data/.github/workflows/test.yml
CHANGED
data/CHANGELOG.md
CHANGED
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
|
@@ -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
|
-
|
36
|
+
parent.present?
|
29
37
|
end
|
30
38
|
|
31
|
-
def
|
32
|
-
|
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
|
41
|
-
|
42
|
-
|
43
|
-
|
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'
|
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.
|
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
|
+
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: '
|
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: '
|
110
|
+
version: '0'
|
111
111
|
description:
|
112
112
|
email:
|
113
113
|
- tomas.celizna@gmail.com
|