Class: Rubex::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Rubex::RakeTask
- Defined in:
- lib/rubex/rake_task.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#ext_dir ⇒ Object
readonly
Returns the value of attribute ext_dir.
-
#rubex_files ⇒ Object
readonly
Returns the value of attribute rubex_files.
Instance Method Summary collapse
- #define_compile_tasks ⇒ Object
-
#ext(ext_dir) ⇒ Object
Change the directory that contains rubex files.
-
#files(files) ⇒ Object
Specify the names of Rubex files with respect to ext directory if compiling multiple files.
-
#initialize(name, gem_spec = nil, &block) ⇒ RakeTask
constructor
A new instance of RakeTask.
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
#debug ⇒ Object
Returns the value of attribute debug.
9 10 11 |
# File 'lib/rubex/rake_task.rb', line 9 def debug @debug end |
#ext_dir ⇒ Object (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_files ⇒ Object (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_tasks ⇒ Object
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.
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.
37 38 39 |
# File 'lib/rubex/rake_task.rb', line 37 def files files @rubex_files = files end |