Class: Packtory::RakeTask

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(which = [ ]) ⇒ RakeTask

Returns a new instance of RakeTask.



7
8
9
10
11
12
# File 'lib/packtory/rake_task.rb', line 7

def initialize(which = [ ])
  @which = which

  Packer.setup
  detect_environment
end

Class Method Details

.install_tasksObject



3
4
5
# File 'lib/packtory/rake_task.rb', line 3

def self.install_tasks
  new.define_tasks
end

Instance Method Details

#build_debObject



81
82
83
84
85
# File 'lib/packtory/rake_task.rb', line 81

def build_deb
  puts 'Building DEB package file...'
  packager, pkg_path = Packer.build_deb
  puts 'Done creating DEB: %s' % pkg_path
end

#build_packageObject



71
72
73
74
75
76
77
78
79
# File 'lib/packtory/rake_task.rb', line 71

def build_package
  packages = Packer.config[:packages]
  packages.each do |pack|
    build_method = PACKAGE_METHOD_MAP[pack]
    unless build_method.nil?
      send(build_method)
    end
  end
end

#build_rpmObject



87
88
89
90
91
# File 'lib/packtory/rake_task.rb', line 87

def build_rpm
  puts 'Building RPM package file...'
  packager, pkg_path = Packer.build_rpm
  puts 'Done creating RPM: %s' % pkg_path
end

#bundle_standaloneObject



103
104
105
# File 'lib/packtory/rake_task.rb', line 103

def bundle_standalone
  RakeTools.bundle_standalone
end

#define_tasksObject



35
36
37
38
39
40
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
69
# File 'lib/packtory/rake_task.rb', line 35

def define_tasks
  @which.each do |task_name|
    case task_name
    when :build_package
      desc 'Create all the packages'
      task :build_package do
        build_package
      end
    when :build_deb
      desc 'Create a debian package'
      task :build_deb do
        build_deb
      end
    when :build_rpm
      desc 'Create an RPM package'
      task :build_rpm do
        build_rpm
      end
    when :spec_with_package
      desc 'Run RSpec code examples with package files'
      task :spec_with_package do
        spec_with_package
      end
    when :bundle_standalone
      desc 'Execute bundle --standalone to download and install local copies of gems'
      task :bundle_standalone do
        bundle_standalone
      end
    else
      # do nothing
    end
  end

  self
end

#detect_environmentObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/packtory/rake_task.rb', line 14

def detect_environment
  if defined?(::RSpec)
    unless @which.include?(:spec_with_package)
      @which << :spec_with_package
    end
  end

  packages = Packer.config[:packages]
  packages.each do |pack|
    unless @which.include?(PACKAGE_METHOD_MAP)
      @which << PACKAGE_METHOD_MAP[pack]
    end
  end

  unless packages.empty?
    @which << :build_package
  end

  @which
end

#spec_with_packageObject



93
94
95
96
97
98
99
100
101
# File 'lib/packtory/rake_task.rb', line 93

def spec_with_package
  prefix_path = Packer.config[:deb_prefix]

  packager = Packer.new
  sfiles_map = packager.prepare_files(prefix_path)

  ENV['PACKTORY_WORKING_PATH'] = packager.working_path
  Rake::Task['spec'].execute
end