Class: Showcase::Path
- Inherits:
-
Object
- Object
- Showcase::Path
- Defined in:
- app/models/showcase/path.rb
Defined Under Namespace
Classes: Tree
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Class Method Summary collapse
Instance Method Summary collapse
- #active?(id) ⇒ Boolean
-
#initialize(path) ⇒ Path
constructor
A new instance of Path.
- #preview_for(view_context) ⇒ Object
Constructor Details
#initialize(path) ⇒ Path
60 61 62 63 64 |
# File 'app/models/showcase/path.rb', line 60 def initialize(path) @id = path.split(".").first.delete_prefix("_").sub(/\/_/, "/") @basename = File.basename(@id) @segments = File.dirname(@id).split("/") end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
58 59 60 |
# File 'app/models/showcase/path.rb', line 58 def basename @basename end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
58 59 60 |
# File 'app/models/showcase/path.rb', line 58 def id @id end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
58 59 60 |
# File 'app/models/showcase/path.rb', line 58 def segments @segments end |
Class Method Details
.tree ⇒ Object
53 54 55 56 |
# File 'app/models/showcase/path.rb', line 53 def self.tree paths = Showcase.previews.map { new _1 }.sort_by!(&:id) Tree.index(paths, &:segments) end |
Instance Method Details
#active?(id) ⇒ Boolean
69 70 71 |
# File 'app/models/showcase/path.rb', line 69 def active?(id) self.id == id end |
#preview_for(view_context) ⇒ Object
73 74 75 |
# File 'app/models/showcase/path.rb', line 73 def preview_for(view_context) Showcase::Preview.new(view_context, id: id, title: basename.titleize).tap(&:render_associated_partial) end |