Class: Ore::Tasks

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

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ Tasks

Returns a new instance of Tasks.



8
9
10
11
12
# File 'lib/ore/tasks.rb', line 8

def initialize(root=Dir.pwd)
  @project = Project.find(root)

  define
end

Instance Method Details

#defineObject



90
91
92
93
94
95
96
97
# File 'lib/ore/tasks.rb', line 90

def define
  define_core_tasks

  case @project.scm
  when :git
    define_git_tasks
  end
end

#define_core_tasksObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/ore/tasks.rb', line 14

def define_core_tasks
  desc "Only builds a Gem"
  task :build 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)
      run "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)
      run "gem push #{pkg}"
    else
      abort "Could not find #{pkg}!"
    end
  end

  desc "Builds and Pushes a new Gem"
  task :release => [:build, :push]

  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_git_tasksObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ore/tasks.rb', line 78

def define_git_tasks
  desc 'Tags a release and pushes the tag'
  task :tag => :build do
    run "git push"
    run "git tag v#{@project.version}"
    run "git push --tags"
  end

  desc "Build, Tags and Pushes a new Gem"
  task :release => [:build, :tag, :push]
end

#run(program, *arguments) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/ore/tasks.rb', line 99

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

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

  return true
end