Class: Showcase::Path

Inherits:
Object
  • Object
show all
Defined in:
app/models/showcase/path.rb

Defined Under Namespace

Classes: Tree

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Path

Returns a new instance of 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

#basenameObject (readonly)

Returns the value of attribute basename.



58
59
60
# File 'app/models/showcase/path.rb', line 58

def basename
  @basename
end

#idObject (readonly)

Returns the value of attribute id.



58
59
60
# File 'app/models/showcase/path.rb', line 58

def id
  @id
end

#segmentsObject (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

.treeObject



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

Returns:

  • (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