Class: Comet::DSL::CLike::Source
- Inherits:
-
Object
- Object
- Comet::DSL::CLike::Source
- Includes:
- Helpers
- Defined in:
- lib/comet/dsl/clike/source.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#imports ⇒ Object
readonly
Returns the value of attribute imports.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #define(*args, **kwargs) ⇒ Object
- #files ⇒ Object
- #import(pattern) ⇒ Object
-
#initialize(language:, headers:, &block) ⇒ Source
constructor
A new instance of Source.
- #native? ⇒ Boolean
- #option(*args, **kwargs) ⇒ Object
- #to_s ⇒ Object
- #validate! ⇒ Object
Methods included from Helpers
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
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
38 39 40 |
# File 'lib/comet/dsl/clike/source.rb', line 38 def headers @headers end |
#imports ⇒ Object (readonly)
Returns the value of attribute imports.
39 40 41 |
# File 'lib/comet/dsl/clike/source.rb', line 39 def imports @imports end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
37 38 39 |
# File 'lib/comet/dsl/clike/source.rb', line 37 def language @language end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
40 41 42 |
# File 'lib/comet/dsl/clike/source.rb', line 40 def @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 |
#files ⇒ Object
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
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_s ⇒ Object
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 |