Class: Nova::Constructor

Inherits:
Object
  • Object
show all
Defined in:
lib/nova/constructor.rb

Overview

Creates a star from a create call.

Instance Method Summary collapse

Constructor Details

#initialize(options) { ... } ⇒ Constructor

Initialize the constructor.

Examples:

Constructor.new(some_star: :another_star) do
  on :some_event do; end
end.create # => Nova::Star/SomeStar.another_star

Parameters:

  • options (Hash)

    the definition of the star. It should be a single key-value pair, with the first key being the type of star, and the first value being the name of the star.

Yields:

  • for the construction of the new Star.



17
18
19
20
# File 'lib/nova/constructor.rb', line 17

def initialize(options, &block)
  @options = options
  @block = block
end

Instance Method Details

#dataHash<Symbol, Object>

Returns information about the star, like the type, the required platforms, and what it’s named.

Returns:

  • (Hash<Symbol, Object>)


45
46
47
48
49
50
# File 'lib/nova/constructor.rb', line 45

def data
  @_data ||= {
    :as   => @options.values.first,
    :type => @options.keys.first
  }
end

#modify_or_createClass

Modifies an already existing star if it exists, or creates it if it doesn’t.

Returns:

  • (Class)

    a subclass of the star type.

Raises:

  • (NoStarError)

    when the star type couldn’t be found.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nova/constructor.rb', line 27

def modify_or_create
  star_type = Star.types[data[:type]]

  raise NoStarError,
    "Could not find star type #{data[:type]}." unless star_type

  if Star.stars[data[:type]][data[:as]]
    handle_existing
  else
    handle_new star_type
  end
end