Class: Comet::DSL::Software

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/comet/dsl/software.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#quote

Constructor Details

#initialize(name, depends:, &block) ⇒ Software

Returns a new instance of Software.



13
14
15
16
17
18
19
# File 'lib/comet/dsl/software.rb', line 13

def initialize(name, depends:, &block)
  @name = name
  @depends = depends
  @sources = []

  instance_exec(&block) if block_given?
end

Instance Attribute Details

#dependsObject

Returns the value of attribute depends.



25
26
27
# File 'lib/comet/dsl/software.rb', line 25

def depends
  @depends
end

#sourcesObject (readonly)

Returns the value of attribute sources.



26
27
28
# File 'lib/comet/dsl/software.rb', line 26

def sources
  @sources
end

Instance Method Details

#hardware_for(device) ⇒ Object



28
29
30
31
32
# File 'lib/comet/dsl/software.rb', line 28

def hardware_for(device)
  @depends.flat_map do |dependent|
    dependent.hardware_for device
  end.uniq
end

#source(language:, **kwargs, &block) ⇒ Object



7
8
9
10
11
# File 'lib/comet/dsl/software.rb', line 7

def source(language:, **kwargs, &block)
  source = Source.create(language: language, **kwargs, &block)
  raise 'native source only allowed in hardware block' if source.native?
  @sources.push source
end

#to_sObject



21
22
23
# File 'lib/comet/dsl/software.rb', line 21

def to_s
  "software #{@name}"
end

#validate!Object



34
35
36
37
38
39
# File 'lib/comet/dsl/software.rb', line 34

def validate!
  raise "#{@name} has no source directives" if sources.empty?

  depends.each(&:validate!)
  sources.each(&:validate!)
end