Class: Comet::Parser
- Inherits:
-
Object
- Object
- Comet::Parser
- Includes:
- DSL::Helpers
- Defined in:
- lib/comet/parser.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #array_hash ⇒ Object
- #compute_targets ⇒ Object
- #firmware(name, imports:, &block) ⇒ Object
- #hardware(name, targets:, &block) ⇒ Object
-
#initialize(filename) ⇒ Parser
constructor
A new instance of Parser.
- #plain_hash ⇒ Object
- #software(name, depends:, &block) ⇒ Object
- #targets ⇒ Object
Methods included from DSL::Helpers
Constructor Details
#initialize(filename) ⇒ Parser
Returns a new instance of Parser.
32 33 34 35 36 37 |
# File 'lib/comet/parser.rb', line 32 def initialize(filename) @software = plain_hash @hardware = array_hash @firmware = [] @filename = filename end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
39 40 41 |
# File 'lib/comet/parser.rb', line 39 def filename @filename end |
Instance Method Details
#array_hash ⇒ Object
24 25 26 |
# File 'lib/comet/parser.rb', line 24 def array_hash Hash.new { |h, k| h[k] = [] } end |
#compute_targets ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/comet/parser.rb', line 46 def compute_targets @firmware.flat_map do |firmware| firmware.validate! firmware.targets.map do |device| [firmware, device] end end end |
#firmware(name, imports:, &block) ⇒ Object
19 20 21 22 |
# File 'lib/comet/parser.rb', line 19 def firmware(name, imports:, &block) raise "firmware `#{name}' redefined" if firmware_defined? name @firmware.push DSL::Firmware.new(name, imports: imports, &block) end |
#hardware(name, targets:, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/comet/parser.rb', line 11 def hardware(name, targets:, &block) if hardware_defined? name, targets raise "hardware `#{name}' redefined for `#{targets}'" end raise "`#{name}' already used by software" if @software.key? name @hardware[name].push DSL::Hardware.new(name, targets: targets, &block) end |
#plain_hash ⇒ Object
28 29 30 |
# File 'lib/comet/parser.rb', line 28 def plain_hash {} end |
#software(name, depends:, &block) ⇒ Object
6 7 8 9 |
# File 'lib/comet/parser.rb', line 6 def software(name, depends:, &block) raise "software `#{name}' redefined" if @software.key? name @software[name] = DSL::Software.new(name, depends: depends, &block) end |
#targets ⇒ Object
41 42 43 44 |
# File 'lib/comet/parser.rb', line 41 def targets parse_file! if @targets.nil? @targets ||= compute_targets end |