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



10
11
12
# File 'lib/tdc/generators/catalog_entries.rb', line 10

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

#empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/tdc/generators/catalog_entries.rb', line 14

def empty?
  to_h.empty?
end

#entriesObject



18
19
20
# File 'lib/tdc/generators/catalog_entries.rb', line 18

def entries
  to_h.keys
end

#firstObject



22
23
24
# File 'lib/tdc/generators/catalog_entries.rb', line 22

def first
  to_h.first&.second
end

#single_entryObject

Raises:



26
27
28
29
30
# File 'lib/tdc/generators/catalog_entries.rb', line 26

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

  first
end