Class: Mongoid::PathExtension
- Inherits:
-
String
- Object
- String
- Mongoid::PathExtension
- Defined in:
- lib/mongoid/path_extension.rb,
lib/mongoid/path_extension/version.rb
Constant Summary collapse
- VERSION =
'0.2.1'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #absolute ⇒ Object
- #ancestors ⇒ Object (also: #ancestor_paths)
- #components ⇒ Object
- #has_parent? ⇒ Boolean
-
#initialize(str) ⇒ PathExtension
constructor
A new instance of PathExtension.
- #parent ⇒ Object (also: #parent_path)
- #permalink ⇒ Object
- #permalink=(value) ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(str) ⇒ PathExtension
Returns a new instance of PathExtension.
7 8 9 10 |
# File 'lib/mongoid/path_extension.rb', line 7 def initialize(str) super str.to_s @str = str.to_s end |
Class Method Details
.demongoize(value) ⇒ Object
52 53 54 |
# File 'lib/mongoid/path_extension.rb', line 52 def demongoize(value) PathExtension.new(value) end |
.evolve(value) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/mongoid/path_extension.rb', line 63 def evolve(value) case value when PathExtension then value.mongoize else value end end |
.mongoize(value) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/mongoid/path_extension.rb', line 56 def mongoize(value) case value when PathExtension then value.mongoize else value end end |
Instance Method Details
#absolute ⇒ Object
31 32 33 |
# File 'lib/mongoid/path_extension.rb', line 31 def absolute ['/', @str].join end |
#ancestors ⇒ Object Also known as: ancestor_paths
44 45 46 47 48 |
# File 'lib/mongoid/path_extension.rb', line 44 def ancestors components[0..-2].each_with_index.map do |component, index| Mongoid::PathExtension.new(components[0..index].join('/')) end end |
#components ⇒ Object
12 13 14 15 |
# File 'lib/mongoid/path_extension.rb', line 12 def components return [] unless @str.present? @str.split('/') end |
#has_parent? ⇒ Boolean
35 36 37 |
# File 'lib/mongoid/path_extension.rb', line 35 def has_parent? parent.present? end |
#parent ⇒ Object Also known as: parent_path
39 40 41 |
# File 'lib/mongoid/path_extension.rb', line 39 def parent ancestors.last end |
#permalink ⇒ Object
21 22 23 |
# File 'lib/mongoid/path_extension.rb', line 21 def permalink components.last end |
#permalink=(value) ⇒ Object
25 26 27 28 29 |
# File 'lib/mongoid/path_extension.rb', line 25 def permalink=(value) return if value.blank? new_str = [parent&.to_s, value].compact.join("/") @str.replace(new_str) end |
#root ⇒ Object
17 18 19 |
# File 'lib/mongoid/path_extension.rb', line 17 def root components.first end |