Class: Rubex::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rubex/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, gem_spec = nil, &block) ⇒ RakeTask

Returns a new instance of RakeTask.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubex/rake_task.rb', line 11

def initialize name, gem_spec=nil, &block
  @name = name
  @gem_spec = gem_spec
  @ext_dir = "#{Dir.pwd}/ext/#{@name}"
  @lib_dir = 'lib'
  @source_pattern = "*.rubex"
  @compiled_pattern = "*.c"
  @config_script = "extconf.rb"
  @debug = true
  instance_eval(&block) if block_given?
  define_compile_tasks
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



9
10
11
# File 'lib/rubex/rake_task.rb', line 9

def debug
  @debug
end

#ext_dirObject (readonly)

Returns the value of attribute ext_dir.



8
9
10
# File 'lib/rubex/rake_task.rb', line 8

def ext_dir
  @ext_dir
end

#rubex_filesObject (readonly)

Returns the value of attribute rubex_files.



8
9
10
# File 'lib/rubex/rake_task.rb', line 8

def rubex_files
  @rubex_files
end

Instance Method Details

#define_compile_tasksObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rubex/rake_task.rb', line 41

def define_compile_tasks
  namespace :rubex do
    desc "Compile a Rubex file into a shared object."
    task :compile do
      file_name = "#{@ext_dir}/#{@name}#{@source_pattern[1..-1]}"
      Rubex::Compiler.compile file_name, target_dir: "#{@ext_dir}", debug: @debug
    end

    desc "Delete all generated files."
    task :clobber do
      path = @ext_dir
      unless path.end_with?(@name)
        path += "/#{@name}"
      end

      Dir.chdir(path) do
        FileUtils.rm(
          Dir.glob(
          "#{path}/*.{c,h,so,o,bundle,dll}") + ["Makefile", "extconf.rb"], force: true
        )
      end
    end
  end
  Rake::ExtensionTask.new(@name)

  desc "Compile Rubex code into a .so file for use in Ruby scripts."
  task "compile" => "rubex:compile"
end

#ext(ext_dir) ⇒ Object

Change the directory that contains rubex files. Overrides default assumption of gem file structure.

Parameters:

  • ext_dir (String)

    Path to new ext dir.



28
29
30
# File 'lib/rubex/rake_task.rb', line 28

def ext ext_dir
  @ext_dir = ext_dir
end

#files(files) ⇒ Object

Specify the names of Rubex files with respect to ext directory if compiling multiple files.

Parameters:

  • files (Array[String])

    Array containing names of all files relative to ext directory as Strings.



37
38
39
# File 'lib/rubex/rake_task.rb', line 37

def files files
  @rubex_files = files
end