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, use_path: false) ⇒ 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')
  • use_path (Boolean) (defaults to: false)

    (default: false)

    • If true, use the full filepath in the include directive
    • If false, use only the filename

Raises:

  • (ArgumentError)

    If the statement is empty or becomes empty after cleaning



231
232
233
234
235
236
237
238
239
# File 'lib/ceedling/includes/includes.rb', line 231

def initialize(statement, use_path: false)
  @filepath = clean(statement)

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

  @filename = File.basename(@filepath)
  @path = File.dirname(@filepath)
  @use_path = use_path
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



217
218
219
# File 'lib/ceedling/includes/includes.rb', line 217

def filename
  @filename
end

#filepathObject (readonly)

Returns the value of attribute filepath.



216
217
218
# File 'lib/ceedling/includes/includes.rb', line 216

def filepath
  @filepath
end

#pathObject (readonly)

Returns the value of attribute path.



218
219
220
# File 'lib/ceedling/includes/includes.rb', line 218

def path
  @path
end

Instance Method Details

#!~(pattern) ⇒ Object

Not matching operator for pattern matching on filename



283
284
285
# File 'lib/ceedling/includes/includes.rb', line 283

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

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

Equality operator -- for Include objects and strings



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/ceedling/includes/includes.rb', line 254

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



278
279
280
# File 'lib/ceedling/includes/includes.rb', line 278

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

#hashObject

Hash method for use in sets and as hash keys



288
289
290
# File 'lib/ceedling/includes/includes.rb', line 288

def hash()
  include.hash
end

#includeObject

Returns the configured entry to use in the include directive



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

def include()
  @use_path ? @filepath : @filename
end

#to_sObject

Method specialized by subclasses



242
243
244
245
# File 'lib/ceedling/includes/includes.rb', line 242

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

#to_strObject



247
248
249
250
251
# File 'lib/ceedling/includes/includes.rb', line 247

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