Class: Comet::DSL::CLike::Source

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#quote

Constructor Details

#initialize(language:, headers:, &block) ⇒ Source

Returns a new instance of Source.



20
21
22
23
24
25
26
27
# File 'lib/comet/dsl/clike/source.rb', line 20

def initialize(language:, headers:, &block)
  @language = language
  @headers = headers
  @imports = []
  @options = Comet::DSL::Options.new

  instance_exec(&block) if block_given?
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



38
39
40
# File 'lib/comet/dsl/clike/source.rb', line 38

def headers
  @headers
end

#importsObject (readonly)

Returns the value of attribute imports.



39
40
41
# File 'lib/comet/dsl/clike/source.rb', line 39

def imports
  @imports
end

#languageObject (readonly)

Returns the value of attribute language.



37
38
39
# File 'lib/comet/dsl/clike/source.rb', line 37

def language
  @language
end

#optionsObject (readonly)

Returns the value of attribute options.



40
41
42
# File 'lib/comet/dsl/clike/source.rb', line 40

def options
  @options
end

Instance Method Details

#define(*args, **kwargs) ⇒ Object



16
17
18
# File 'lib/comet/dsl/clike/source.rb', line 16

def define(*args, **kwargs)
  @options.add('D', *args, **kwargs)
end

#filesObject



46
47
48
49
50
# File 'lib/comet/dsl/clike/source.rb', line 46

def files
  @imports.flat_map do |pattern|
    Dir.glob pattern
  end.uniq
end

#import(pattern) ⇒ Object



8
9
10
# File 'lib/comet/dsl/clike/source.rb', line 8

def import(pattern)
  @imports.push pattern
end

#native?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/comet/dsl/clike/source.rb', line 42

def native?
  false
end

#option(*args, **kwargs) ⇒ Object



12
13
14
# File 'lib/comet/dsl/clike/source.rb', line 12

def option(*args, **kwargs)
  @options.add('', *args, **kwargs)
end

#to_sObject



29
30
31
32
33
34
35
# File 'lib/comet/dsl/clike/source.rb', line 29

def to_s
  if language == :c
    'C source'
  elsif language == :cpp
    'C++ source'
  end
end

#validate!Object



52
53
54
55
# File 'lib/comet/dsl/clike/source.rb', line 52

def validate!
  raise "#{self} references no source files" if @imports.empty?
  @options.validate!
end