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(root = Dir.pwd) ⇒ Tasks

Initializes the Ore tasks.

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The optional root directory for the project.



22
23
24
25
26
27
# File 'lib/ore/tasks.rb', line 22

def initialize(root=Dir.pwd)
  @project = Project.find(root)
  @release_tasks = ['push']

  define
end

Instance Attribute Details

#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.



136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/ore/tasks.rb', line 136

def define
  define_core_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_core_tasksObject

Defines the core Ore tasks.



32
33
34
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
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
# File 'lib/ore/tasks.rb', line 32

def define_core_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 "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

  desc "Builds and pushes a Gem"
  task :push => :build do
    pkg = @project.pkg_file

    if File.file?(pkg)
      gem 'push', pkg
    else
      abort "Could not find #{pkg}!"
    end
  end

  desc "Builds and Pushes a new Gem"
  task :release do
    @release_tasks.each { |task| Rake::Task[task].invoke }
  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
end

#define_rubygem_tasksObject

Defines the RubyGems specific tasks.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/ore/tasks.rb', line 118

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



219
220
221
# File 'lib/ore/tasks.rb', line 219

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



184
185
186
# File 'lib/ore/tasks.rb', line 184

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



199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ore/tasks.rb', line 199

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.



161
162
163
164
165
166
167
168
169
# File 'lib/ore/tasks.rb', line 161

def run(program,*arguments)
  show_command = ([program] + arguments).join(' ')

  unless rake_system(program,*arguments)
    abort "Command failed: #{show_command}"
  end

  return true
end