Class: Bones::GemPackageTask

Inherits:
Rake::PackageTask
  • Object
show all
Defined in:
lib/bones/gem_package_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_spec) {|_self| ... } ⇒ GemPackageTask

Create a GEM Package task library. Automatically define the gem if a block is given. If no block is supplied, then define needs to be called to define the task.

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
# File 'lib/bones/gem_package_task.rb', line 23

def initialize(gem_spec)
  init(gem_spec)
  yield self if block_given?
  define if block_given?
end

Instance Attribute Details

#gem_specObject

Ruby GEM spec containing the metadata for this package. The name, version and package_files are automatically determined from the GEM spec and don’t need to be explicitly provided.



17
18
19
# File 'lib/bones/gem_package_task.rb', line 17

def gem_spec
  @gem_spec
end

Instance Method Details

#defineObject

Create the Rake tasks and actions specified by this GemPackageTask. (define is automatically called if a block is given to new).



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

def define
  super
  task :prereqs
  task :package => ["#{package_dir_path}/#{gem_file}"]

  file "#{package_dir_path}/#{gem_file}" => [package_dir_path] + package_files do
    when_writing("Creating GEM") {
      chdir(package_dir_path) do
        if defined? Gem::Package.build
          Gem::Package.build(gem_spec)
        else
          Gem::Builder.new(gem_spec).build
        end
        verbose(true) {
          mv gem_file, "../#{gem_file}"
        }
      end
    }
  end

  file package_dir_path => 'gem:prereqs' do
    mkdir_p package_dir rescue nil
  end
end

#gem_fileObject



67
68
69
70
71
72
73
# File 'lib/bones/gem_package_task.rb', line 67

def gem_file
  if @gem_spec.platform == Gem::Platform::RUBY
    "#{gem_spec.full_name}.gem"
  else
    "#{gem_spec.full_name}-#{gem_spec.platform}.gem"
  end
end

#init(gem) ⇒ Object

Initialization tasks without the “yield self” or define operations.



32
33
34
35
36
# File 'lib/bones/gem_package_task.rb', line 32

def init(gem)
  super(gem.name, gem.version)
  @gem_spec = gem
  @package_files += gem_spec.files if gem_spec.files
end