Class: Lifer::Tag
- Inherits:
-
Object
- Object
- Lifer::Tag
- Defined in:
- lib/lifer/tag.rb
Overview
A tag is a way to categorize entries. You’ve likely encountered tags in other software before. In Lifer, tags are sort of the inverse of collections. It’s a nice way to associate entries across many collections.
Because tags are used to link entries, we definitely do not want duplicate tags. So the only way to build or retrieve tags is via the ‘.build_or_update` class method, which helps us responsibly manage the global tag manifest.
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.build_or_update(name:, entries: []) ⇒ Lifer:Tag
Builds or updates a Lifer tag.
Instance Method Summary collapse
-
#initialize(name:, entries:) ⇒ Tag
constructor
A new instance of Tag.
Constructor Details
#initialize(name:, entries:) ⇒ Tag
Returns a new instance of Tag.
48 49 50 51 |
# File 'lib/lifer/tag.rb', line 48 def initialize(name:, entries:) @name = name @entries = entries end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
46 47 48 |
# File 'lib/lifer/tag.rb', line 46 def entries @entries end |
#name ⇒ Object
Returns the value of attribute name.
44 45 46 |
# File 'lib/lifer/tag.rb', line 44 def name @name end |
Class Method Details
.build_or_update(name:, entries: []) ⇒ Lifer:Tag
Builds or updates a Lifer tag. On update, its list of entries gets freshened.
22 23 24 |
# File 'lib/lifer/tag.rb', line 22 def build_or_update(name:, entries: []) update(name:, entries:) || build(name:, entries:) end |