Class: Ore::Tasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/ore/tasks.rb

Overview

Defines basic Rake tasks for managing and releasing projects that use Ore.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|tasks| ... } ⇒ Tasks

Initializes the Ore tasks.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options for the tasks.

Options Hash (options):

  • :root (String) — default: Dir.pwd

    The optional root directory for the project.

  • :gemcutter (String, Boolean) — default: true

    Specifies the gemcutter server to push built Gems to. If :gemcutter is a Boolean value, it will enable or disable pushing to rubygems.org.

Yields:

  • (tasks)

    If a block is given, it will be passed the newly created tasks, before they are fully defined.

Yield Parameters:

  • tasks (Tasks)

    The newly created tasks.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ore/tasks.rb', line 47

def initialize(options={})
  root = options.fetch(:root,Dir.pwd)

  @project = Project.find(root)
  @release_tasks = []
  @gemcutter = options.fetch(:gemcutter,true)

  yield self if block_given?

  define
end

Instance Attribute Details

#gemcutterObject

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

#projectObject (readonly)

The Ore project.



17
18
19
# File 'lib/ore/tasks.rb', line 17

def project
  @project
end

#release_tasksObject (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

#defineObject

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_tasksObject

Defines tasks used during development.

Since:

  • 0.5.0



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_tasksObject

Defines the tasks used for releases.

Since:

  • 0.5.0



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_tasksObject

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_filesHash{String => String}

Lists the modified files within the project.

Returns:

  • (Hash{String => String})

    The paths and statuses of the modified files.

Since:

  • 0.4.2



269
270
271
# File 'lib/ore/tasks.rb', line 269

def dirty_files
  {}
end

#gem(*arguments) ⇒ true

Runs a RubyGems command.

Parameters:

  • The (Array<String>)

    arguments to pass to RubyGems.

Returns:

  • (true)

    The command was executed successfully.

See Also:

Since:

  • 0.3.1



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.

Parameters:

  • dep (Gem::Dependency)

    The RubyGems dependency to be installed.

Returns:

  • (true)

    Specifies that the dependency was successfully installed.

Since:

  • 0.4.3



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.

Parameters:

  • program (String)

    The program to run.

  • arguments (Array<String>)

    Optional arguments.

Returns:

  • (true)

    The program was executed successfully.



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