Class: Lookbook::Entity
- Inherits:
-
Object
- Object
- Lookbook::Entity
- Includes:
- Comparable
- Defined in:
- lib/lookbook/entities/entity.rb
Overview
Base entity class
Direct Known Subclasses
PageEntity, PreviewEntity, RenderableEntity, ScenarioEntity, ScenarioGroupEntity
Identity collapse
-
#id ⇒ String
Human-readable unique ID for the entity.
-
#label ⇒ String
Titlized name for use in navigation etc.
-
#name ⇒ String
Parameter-safe entity name.
-
#type ⇒ Symbol
Entity type identifier.
Paths collapse
-
#lookup_path ⇒ String
(also: #path)
Canonical reference path.
- #search_terms ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(lookup_path = nil) ⇒ Entity
constructor
private
A new instance of Entity.
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 |
#id ⇒ String
Human-readable unique ID for the entity
19 20 21 |
# File 'lib/lookbook/entities/entity.rb', line 19 def id Utils.id(fetch_config(:id) { lookup_path.tr("/", "-") }) end |
#label ⇒ String
Titlized name for use in navigation etc.
Can be customized using the ‘@label` tag where supported.
35 36 37 |
# File 'lib/lookbook/entities/entity.rb', line 35 def label @_label ||= fetch_config(:label) { name.titleize } end |
#lookup_path ⇒ String Also known as: path
Canonical reference path.
Used for generating URL paths and looking up entities.
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 |
#name ⇒ String
Parameter-safe entity name.
26 27 28 |
# File 'lib/lookbook/entities/entity.rb', line 26 def name @_name ||= Utils.name(File.basename(@lookup_path)) end |
#search_terms ⇒ Object
68 69 70 |
# File 'lib/lookbook/entities/entity.rb', line 68 def search_terms @_search_terms ||= lookup_path.split("/").map(&:titleize) end |
#type ⇒ Symbol
Entity type identifier
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 |