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.1.4'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #absolute ⇒ Object
- #ancestor_paths ⇒ Object
- #components ⇒ Object
- #has_parent? ⇒ Boolean
-
#initialize(str) ⇒ PathExtension
constructor
A new instance of PathExtension.
- #parent_path ⇒ Object
- #parent_permalink ⇒ Object
- #permalink ⇒ Object
- #root ⇒ Object
Constructor Details
#initialize(str) ⇒ PathExtension
Returns a new instance of PathExtension.
5 6 7 8 |
# File 'lib/mongoid/path_extension.rb', line 5 def initialize(str) super str.to_s @str = str.to_s end |
Class Method Details
.demongoize(value) ⇒ Object
51 52 53 |
# File 'lib/mongoid/path_extension.rb', line 51 def demongoize(value) PathExtension.new(value) end |
.evolve(value) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/mongoid/path_extension.rb', line 62 def evolve(value) case value when PathExtension then value.mongoize else value end end |
.mongoize(value) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/mongoid/path_extension.rb', line 55 def mongoize(value) case value when PathExtension then value.mongoize else value end end |
Instance Method Details
#absolute ⇒ Object
23 24 25 |
# File 'lib/mongoid/path_extension.rb', line 23 def absolute ['/', @str].join end |
#ancestor_paths ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/mongoid/path_extension.rb', line 31 def ancestor_paths return unless has_parent? res = [] components[0..-2].each_with_index do |component, index| res << components[0..index].join('/') end res end |
#components ⇒ Object
10 11 12 13 |
# File 'lib/mongoid/path_extension.rb', line 10 def components return [] unless @str.present? @str.split('/') end |
#has_parent? ⇒ Boolean
27 28 29 |
# File 'lib/mongoid/path_extension.rb', line 27 def has_parent? components.length > 1 end |
#parent_path ⇒ Object
40 41 42 43 |
# File 'lib/mongoid/path_extension.rb', line 40 def parent_path return unless has_parent? components[0..-2].join('/') end |
#parent_permalink ⇒ Object
45 46 47 48 |
# File 'lib/mongoid/path_extension.rb', line 45 def parent_permalink return unless has_parent? components[-2] end |
#permalink ⇒ Object
19 20 21 |
# File 'lib/mongoid/path_extension.rb', line 19 def permalink components.last end |
#root ⇒ Object
15 16 17 |
# File 'lib/mongoid/path_extension.rb', line 15 def root components.first end |