Class: Include

Inherits:
Object show all
Defined in:
lib/ceedling/includes/includes.rb

Overview

Base class for C header includes

Direct Known Subclasses

SystemInclude, UserInclude

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement, include_path: nil) ⇒ Include

Initialize an Include object from a C include statement or simple filepath.

Parameters:

  • statement (String)

    A C include statement. Examples:

    • #include "header.h"
    • #include <stdio.h>
    • A quoted/bracketed filepath (e.g., '"header.h"' or <stdio.h>')
    • A plain filepath (e.g., 'path/to/header.h')
  • include_path (String, nil) (defaults to: nil)

    (default: nil)

    • When set, this exact spelling is used in the include directive, taking precedence over filepath/filename. This exists for a reconciled SystemInclude, whose filepath is deliberately the header's real, resolved location (needed elsewhere for identity -- see Includes.sanitize!) rather than the original, as-written directive text a reconciled render needs.

Raises:

  • (ArgumentError)

    If the statement is empty or becomes empty after cleaning



285
286
287
288
289
290
291
292
293
# File 'lib/ceedling/includes/includes.rb', line 285

def initialize(statement, include_path: nil)
  @filepath = clean(statement)

  raise ArgumentError, "Empty include statement" if @filepath.empty?

  @filename = File.basename(@filepath)
  @path = File.dirname(@filepath)
  @include_path = clean(include_path) if include_path
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



267
268
269
# File 'lib/ceedling/includes/includes.rb', line 267

def filename
  @filename
end

#filepathObject (readonly)

Returns the value of attribute filepath.



266
267
268
# File 'lib/ceedling/includes/includes.rb', line 266

def filepath
  @filepath
end

#include_pathObject (readonly)

Returns the value of attribute include_path.



269
270
271
# File 'lib/ceedling/includes/includes.rb', line 269

def include_path
  @include_path
end

#pathObject (readonly)

Returns the value of attribute path.



268
269
270
# File 'lib/ceedling/includes/includes.rb', line 268

def path
  @path
end

Instance Method Details

#!~(pattern) ⇒ Object

Not matching operator for pattern matching on filename



337
338
339
# File 'lib/ceedling/includes/includes.rb', line 337

def !~(pattern)
  @filename !~ pattern
end

#==(other) ⇒ Object Also known as: eql?

Equality operator -- for Include objects and strings



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/ceedling/includes/includes.rb', line 308

def ==(other)
  case other
  when String
    include == other
  when UserInclude, MockInclude
    if self.is_a?(SystemInclude)
      false
    else
      include == other.include
    end
  when SystemInclude
    if self.is_a?(UserInclude)
      false
    else
      include == other.include
    end
  when Include
    include == other.include
  else
    false
  end
end

#=~(pattern) ⇒ Object

Matching operator for pattern matching on filename



332
333
334
# File 'lib/ceedling/includes/includes.rb', line 332

def =~(pattern)
  @filename =~ pattern
end

#hashObject

Hash method for use in sets and as hash keys



342
343
344
# File 'lib/ceedling/includes/includes.rb', line 342

def hash()
  include.hash
end

#includeObject

Returns the configured entry to use in the include directive



350
351
352
353
# File 'lib/ceedling/includes/includes.rb', line 350

def include()
  return @include_path if @include_path
  @filename
end

#to_sObject

Method specialized by subclasses



296
297
298
299
# File 'lib/ceedling/includes/includes.rb', line 296

def to_s()
  # Simple string representation of class contents with no additional formatting or #include decoration
  return @filename
end

#to_strObject



301
302
303
304
305
# File 'lib/ceedling/includes/includes.rb', line 301

def to_str()
  # Coerce to string for implicit conversions (e.g., string interpolation, concatenation)
  # For instance, Rake#FileList needs this to treat Include objects as strings when extending with #pathmap
  return @filename
end