Skip to content

Commit

Permalink
allows the rake ib and rake ib:open commands to use a default ins…
Browse files Browse the repository at this point in the history
…tance of IB::RakeTask
  • Loading branch information
colinta committed Dec 12, 2014
1 parent c27fcc2 commit 87d0c19
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ Bundler.require
require 'rubygems'
require 'ib'

IB::RakeTask.new do |project|
# ...
end

Motion::Project::App.setup do |app|
# ...
end

```

## Upgrading to 0.7.0
## Customizing `IB::Project`

If you want to customize the `IB::Project` instance that creates `ib.xcodeproj`, you
should create an instance of `IB::RakeTask` and pass it a block. That block will be handed
an instance of `IB::Project` that you can modify:

Previous versons of `ib` automatically registered the `rake ib:open` command,
but offered no way to customize the `IB::Project` that was created. As of
0.7.0, you will need to create a `IB::RakeTask` instance in your Rakefile, then
you can use `rake ib` as before.
###### Rakefile
```ruby
IB::RakeTask.new do |project|
end
```

## Usage

Expand Down
44 changes: 37 additions & 7 deletions lib/ib/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

module IB
class RakeTask
class << self
attr_writer :created
def created?
@@created ||= false
end
end
include Rake::DSL

def initialize
require 'ib/project'
@@created = true

@project = IB::Project.new
yield @project if block_given?
define_tasks
Expand All @@ -18,14 +26,36 @@ def define_tasks
task :project do
@project.write
end

desc "Generates ib.xcodeproj and opens it in XCode"
task :open => :project do
system "open ib.xcodeproj"
end
end
desc "Same as 'ib:open'"
task :ib => "ib:open"
end
end
end


namespace :ib do
desc "Generates ib.xcodeproj and opens it in XCode"
task :open do
if ! IB::RakeTask.created?
# create a default instance of IB::RakeTask
IB::RakeTask.new
end
Rake::Task['ib:project'].invoke
system "open ib.xcodeproj"
end

# if this task is invoked
task :project do
if ! IB::RakeTask.created?
puts "You haven't created an instance of IB::RakeTask in your Rakefile"
puts
puts "Add this somewhere in your Rakefile:"
puts
puts " IB::RakeTask.new do |project|"
puts " # you can customize the IB::Project here"
puts " end"
end
end
end

desc "Same as 'ib:open'"
task :ib => 'ib:open'

0 comments on commit 87d0c19

Please sign in to comment.