Class: Tdc::Generators::CatalogEntries

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/tdc/generators/catalog_entries.rb

Overview

Knows how to contain arbitrary collections of model objects. As model instances are created by generators, the model instances are added to the current catalog as catalog entries.

Instance Method Summary collapse

Instance Method Details

#add_catalog_entry(tag, entry) ⇒ Object



8
9
10
# File 'lib/tdc/generators/catalog_entries.rb', line 8

def add_catalog_entry(tag, entry)
  send(:"#{tag}=", entry)
end

#empty?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/tdc/generators/catalog_entries.rb', line 12

def empty?
  to_h.empty?
end

#entriesObject



16
17
18
# File 'lib/tdc/generators/catalog_entries.rb', line 16

def entries
  to_h.keys
end

#firstObject



20
21
22
# File 'lib/tdc/generators/catalog_entries.rb', line 20

def first
  to_h.first&.second
end

#single_entryObject

Raises:



24
25
26
27
28
# File 'lib/tdc/generators/catalog_entries.rb', line 24

def single_entry
  raise Tdc::FatalError, "There is more than one entry" if to_h.many?

  first
end