Class: Require

Inherits:
Object
  • Object
show all
Defined in:
lib/crequire/crequire.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Require

Returns a new instance of Require.



5
6
7
8
9
# File 'lib/crequire/crequire.rb', line 5

def initialize(file_path)
  @full_path = File.expand_path file_path
  @path = File.dirname @full_path
  @name = File.basename file_path
end

Instance Method Details

#interface(source = nil, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/crequire/crequire.rb', line 33

def interface(source=nil, &block)
  if source
    source
  else
    swig = SWIG::Context.new(@name)
    swig.input &block if block
    swig.interface
  end
end

#require(options = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/crequire/crequire.rb', line 11

def require(options = {}, &block)
  if options[:force] or !File.exists? "#{@full_path}.o"

    @src = options[:src]
    @cflags = options[:cflags]
    @dump_interface = options[:interface]
    if options[:dump]
      dir = options[:dump]
      FileUtils.mkpath dir
      save dir, &block
      install dir
    else
      Dir.mktmpdir do |tmp|
        save tmp, &block
        install tmp
      end
    end
  end

  Kernel.require @name
end