Class: Inventory::Extension

Inherits:
Object
  • Object
show all
Defined in:
lib/inventory-1.0/extension.rb

Overview

An extension represents a sub-directory under the “ext” directory in the project. Such a directory contains source files, usually written in C, that interface with the underlying Ruby implementation, and possibly other low-level systems, that aren’t otherwise available to Ruby code.

For an inventory, an extension is a set of files that should be included in the project and can contain multiple extensions. [Inventory-Rake](disu.se/software/inventory-rake-1.0/) uses information found in these extensions to compile them for use from Ruby code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) {|?| ... } ⇒ Extension

Creates an extension named NAME. A block may be given that’ll be #instance_exec’d in the extension being created so that various methods may be overridden to suit the extension being created.

Parameters:

  • name (String)

Yields:

  • (?)


19
20
21
22
# File 'lib/inventory-1.0/extension.rb', line 19

def initialize(name)
  @name = name
  instance_exec(&Proc.new) if block_given?
end

Instance Attribute Details

#nameString (readonly)

Returns The receiver’s #name.

Returns:

  • (String)

    The receiver’s #name



81
82
83
# File 'lib/inventory-1.0/extension.rb', line 81

def name
  @name
end

Instance Method Details

#additional_filesArray<String>

Returns The complete paths to any additional files.

Returns:

  • (Array<String>)

    The complete paths to any additional files



56
57
58
# File 'lib/inventory-1.0/extension.rb', line 56

def additional_files
  []
end

#dependString

Note:

This file is usually created by hand by invoking ‘gcc -MM *.c > depend`

Returns The path into the project that contains the “depend” file for the extension, the default being ‘#directory/depend`.

Returns:

  • (String)

    The path into the project that contains the “depend” file for the extension, the default being ‘#directory/depend`



40
41
42
# File 'lib/inventory-1.0/extension.rb', line 40

def depend
  '%s/depend' % directory
end

#directoryString

Returns The sub-directory into the project that contains the extension, the default being ‘ext/#name`.

Returns:

  • (String)

    The sub-directory into the project that contains the extension, the default being ‘ext/#name`



26
27
28
# File 'lib/inventory-1.0/extension.rb', line 26

def directory
  'ext/%s' % name
end

#extconfString

Returns The path into the project that contains the “extconf.rb” file for the extension, the default being ‘#directory/extconf.rb`.

Returns:

  • (String)

    The path into the project that contains the “extconf.rb” file for the extension, the default being ‘#directory/extconf.rb`



32
33
34
# File 'lib/inventory-1.0/extension.rb', line 32

def extconf
  '%s/extconf.rb' % directory
end

#filesArray<String>

Returns All files included in the package, that is

#extconf, #depend

+ #source_files + #additional_files.

Returns:



62
63
64
# File 'lib/inventory-1.0/extension.rb', line 62

def files
  [extconf, depend] + source_files + additional_files
end

#inspectObject



76
77
78
# File 'lib/inventory-1.0/extension.rb', line 76

def inspect
  '#<%s: %s %s>' % [self.class, name, directory]
end

#source_filesArray<String>

Returns The complete paths of #sources inside the package.

Returns:

  • (Array<String>)

    The complete paths of #sources inside the package



51
52
53
# File 'lib/inventory-1.0/extension.rb', line 51

def source_files
  sources.map{ |e| '%s/%s' % [directory, e] }
end

#sourcesArray<String>

Returns The source files that make up the extension, the default being empty.

Returns:

  • (Array<String>)

    The source files that make up the extension, the default being empty



46
47
48
# File 'lib/inventory-1.0/extension.rb', line 46

def sources
  []
end

#to_aArray<String>

Returns Whatever #files returns.

Returns:

  • (Array<String>)

    Whatever #files returns



67
68
69
# File 'lib/inventory-1.0/extension.rb', line 67

def to_a
  files
end

#to_sString

Returns The receiver’s #name.

Returns:

  • (String)

    The receiver’s #name



72
73
74
# File 'lib/inventory-1.0/extension.rb', line 72

def to_s
  name
end