Class: Ore::Tasks
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Ore::Tasks
- Defined in:
- lib/ore/tasks.rb
Overview
Defines basic Rake tasks for managing and releasing projects that use Ore.
Instance Attribute Summary collapse
-
#gemcutter ⇒ Object
Specifies the gemcutter host or if pushing gems to rubygems.org is enabled.
-
#project ⇒ Object
readonly
The Ore project.
-
#release_tasks ⇒ Object
readonly
The tasks to perform when releasing a new version.
Instance Method Summary collapse
-
#define ⇒ Object
Defines the Ore tasks.
-
#define_development_tasks ⇒ Object
Defines tasks used during development.
-
#define_release_tasks ⇒ Object
Defines the tasks used for releases.
-
#define_rubygem_tasks ⇒ Object
Defines the RubyGems specific tasks.
-
#dirty_files ⇒ Hash{String => String}
Lists the modified files within the project.
-
#gem(*arguments) ⇒ true
Runs a RubyGems command.
-
#initialize(options = {}) {|tasks| ... } ⇒ Tasks
constructor
Initializes the Ore tasks.
-
#install_dependency(dep) ⇒ true
Installs a dependency.
-
#run(program, *arguments) ⇒ true
Runs a program with optional arguments.
Constructor Details
#initialize(options = {}) {|tasks| ... } ⇒ Tasks
Initializes the Ore tasks.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ore/tasks.rb', line 47 def initialize(={}) root = .fetch(:root,Dir.pwd) @project = Project.find(root) @release_tasks = [] @gemcutter = .fetch(:gemcutter,true) yield self if block_given? define end |
Instance Attribute Details
#gemcutter ⇒ Object
Specifies the gemcutter host or if pushing gems to rubygems.org is enabled.
22 23 24 |
# File 'lib/ore/tasks.rb', line 22 def gemcutter @gemcutter end |
#project ⇒ Object (readonly)
The Ore project.
17 18 19 |
# File 'lib/ore/tasks.rb', line 17 def project @project end |
#release_tasks ⇒ Object (readonly)
The tasks to perform when releasing a new version
14 15 16 |
# File 'lib/ore/tasks.rb', line 14 def release_tasks @release_tasks end |
Instance Method Details
#define ⇒ Object
Defines the Ore tasks.
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ore/tasks.rb', line 185 def define define_development_tasks define_release_tasks if (scm_tasks = SCM::Tasks::SUPPORTED[@project.scm]) extend scm_tasks define_scm_tasks end unless @project.bundler? define_rubygem_tasks end end |
#define_development_tasks ⇒ Object
Defines tasks used during development.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/ore/tasks.rb', line 64 def define_development_tasks task :status do changes = dirty_files unless changes.empty? puts "The following files were modified:" changes.each { |path,status| puts "#{status}\t#{path}" } puts abort "The project has uncommitted changes!" end end desc 'Displays the current version' task :version do puts @project.version end desc "Start IRB with all runtime dependencies loaded" task :console, [:script] do |t,args| original_load_path = $LOAD_PATH if @project.bundler? require 'bundler' Bundler.setup(:default) end # add the project code directories to the $LOAD_PATH @project.require_paths.each do |dir| $LOAD_PATH.unshift(File.join(@project.root,dir)) end # clear ARGV so IRB is not confused ARGV.clear require 'irb' # set the optional script to run IRB.conf[:SCRIPT] = args.script IRB.start # return the $LOAD_PATH to it's original state $LOAD_PATH.reject! do |path| !(original_load_path.include?(path)) end end desc "Only builds a Gem" task :build => :status do @project.build! end desc "Alias to the 'build' task" task :gem => :build desc "Builds and installs a Gem" task :install => :build do pkg = @project.pkg_file if File.file?(pkg) gem 'install', pkg else abort "Could not find #{pkg}!" end end end |
#define_release_tasks ⇒ Object
Defines the tasks used for releases.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ore/tasks.rb', line 136 def define_release_tasks if @gemcutter desc "Builds and pushes a Gem" task :push => :build do pkg = @project.pkg_file unless File.file?(pkg) abort "Could not find #{pkg}!" end arguments = [] if @gemcutter.kind_of?(String) arguments << '--host' << @gemcutter end gem('push',pkg,*arguments) end @release_tasks.push('push') end desc "Builds and Pushes a new Gem" task :release do @release_tasks.each { |task| Rake::Task[task].invoke } end end |
#define_rubygem_tasks ⇒ Object
Defines the RubyGems specific tasks.
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ore/tasks.rb', line 167 def define_rubygem_tasks namespace :install do desc 'Installs dependencies of the Gem' task :deps do install_missing_dependency = lambda { |dep| install_dependency(dep) unless Gem.available?(dep) } @project.dependencies.each(&install_missing_dependency) @project.runtime_dependencies.each(&install_missing_dependency) @project.development_dependencies.each(&install_missing_dependency) end end end |
#dirty_files ⇒ Hash{String => String}
Lists the modified files within the project.
269 270 271 |
# File 'lib/ore/tasks.rb', line 269 def dirty_files {} end |
#gem(*arguments) ⇒ true
Runs a RubyGems command.
234 235 236 |
# File 'lib/ore/tasks.rb', line 234 def gem(*arguments) run(RUBY,'-S','gem',*arguments) end |
#install_dependency(dep) ⇒ true
Installs a dependency.
249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/ore/tasks.rb', line 249 def install_dependency(dep) arguments = [] # enable install pre-releases arguments << '--prerelease' if dep.prerelease? # specify the version requirements dep.versions.each { |v| arguments << '--version' << v } gem('install',dep.name,*arguments) end |
#run(program, *arguments) ⇒ true
Runs a program with optional arguments.
211 212 213 214 215 216 217 218 219 |
# File 'lib/ore/tasks.rb', line 211 def run(program,*arguments) show_command = ([program] + arguments).join(' ') unless rake_system(program,*arguments) abort "Command failed: #{show_command}" end return true end |