Class: Lookbook::Entity

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/lookbook/entities/entity.rb

Overview

Base entity class

Identity collapse

Paths collapse

Instance Method Summary collapse

Constructor Details

#initialize(lookup_path = nil) ⇒ Entity

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Entity.



10
11
12
# File 'lib/lookbook/entities/entity.rb', line 10

def initialize(lookup_path = nil)
  @lookup_path = lookup_path
end

Instance Method Details

#<=>(other) ⇒ Object



74
75
76
# File 'lib/lookbook/entities/entity.rb', line 74

def <=>(other)
  label <=> other.label
end

#idString

Human-readable unique ID for the entity

Returns:

  • (String)

    The ID



19
20
21
# File 'lib/lookbook/entities/entity.rb', line 19

def id
  Utils.id(fetch_config(:id) { lookup_path.tr("/", "-") })
end

#labelString

Titlized name for use in navigation etc.

Can be customized using the ‘@label` tag where supported.

Returns:

  • (String)

    The label



35
36
37
# File 'lib/lookbook/entities/entity.rb', line 35

def label
  @_label ||= fetch_config(:label) { name.titleize }
end

#lookup_pathString Also known as: path

Canonical reference path.

Used for generating URL paths and looking up entities.

Returns:

  • (String)

    The lookup path



55
56
57
58
59
60
61
62
63
# File 'lib/lookbook/entities/entity.rb', line 55

def lookup_path
  return @_lookup_path if @_lookup_path

  directory = fetch_config(:logical_path) do
    dir = File.dirname(@lookup_path)
    dir if !dir.start_with?(".")
  end
  @_lookup_path ||= PathUtils.strip_slashes(PathUtils.to_path(directory, name))
end

#nameString

Parameter-safe entity name.

Returns:

  • (String)

    The name



26
27
28
# File 'lib/lookbook/entities/entity.rb', line 26

def name
  @_name ||= Utils.name(File.basename(@lookup_path))
end

#search_termsObject



68
69
70
# File 'lib/lookbook/entities/entity.rb', line 68

def search_terms
  @_search_terms ||= lookup_path.split("/").map(&:titleize)
end

#typeSymbol

Entity type identifier

Returns:

  • (Symbol)

    The entity type



42
43
44
# File 'lib/lookbook/entities/entity.rb', line 42

def type
  @_type ||= self.class.name.gsub("Entity", "").demodulize.underscore.downcase.to_sym
end