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/) 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.

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)



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

def name
  @name
end

Instance Method Details

#additional_filesArray<String>



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`.



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

def depend
  '%s/depend' % directory
end

#directoryString



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

def directory
  'ext/%s' % name
end

#extconfString



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

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

#filesArray<String>



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>



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>



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

def sources
  []
end

#to_aArray<String>



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

def to_a
  files
end

#to_sString



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

def to_s
  name
end