Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load subcommand plug-ins at runtime #1

Merged
merged 1 commit into from
Nov 6, 2013
Merged

Conversation

leshill
Copy link
Contributor

@leshill leshill commented Nov 2, 2013

We use rubygems to load a subcommand plug-in gem with a file that can be loaded at

<command-path>/plugin.rb

The command-path is the namespace of the command converted to a path. For example Pod::Command becomes pod/command.

The plugin.rb file should either define the subcommand(s) directly or require the files for the subcommand(s). For example, the first working plugin, open_pod_bay, provides an open subcommand and has the following plugin.rb

require 'pod/command/open'

gem install open_pod_bay to try it with this PR.

@orta
Copy link
Member

orta commented Nov 4, 2013

You sir. Are my hero.

http://i.imgur.com/JncYyD9.gif

@fabiopelosin
Copy link
Member

Rocking on! This is a nice implementation for the problem however there is a feature which I was interested on: the ability of inspecting the available gems and require the commands on initialization. In this way the subcommands and their description would be available on the help.

Thoughts?

@fabiopelosin
Copy link
Member

@orta Lol!

@leshill
Copy link
Contributor Author

leshill commented Nov 5, 2013

Hi @irrationalfab,

TIL rubygems has a method that makes this even easier. Please check the updated PR description and the commit. This should change to Gem.find_latest_files once 2.2 is released.

@alloy
Copy link
Member

alloy commented Nov 5, 2013

This is looking perfect! I haven’t had time to test it yet, I will try to do that this afternoon.

@fabiopelosin
Copy link
Member

Just tested the open_pod_bay and read the patch, outstanding implementation! 🍻

Do you mind sending a pull request in CocoaPods/CocoaPods (sorry for the dance) to add the relative entry to the changelog crediting yourself?

@alloy
Copy link
Member

alloy commented Nov 5, 2013

Quick question before you merge it, @irrationalfab. Does this work with MRI 1.8.7 and the RubyGems version that come installed on stock OS X 10.8? (And 10.9, but I assume it does there.)

@fabiopelosin
Copy link
Member

I don't have 10.8 available anymore. Now I tested it with Ruby 1.9.3-p385 and it works, I didn't test it with Ruby 1.8.7 because I would need to install gcc, however the pull requests passes the validation on 1.8.7 (linux box) so I think that there should not be issues about that.

@alloy
Copy link
Member

alloy commented Nov 5, 2013

Just tested it on a clean 10.8 system and it works! As a side-note, the RubyGems version that comes with 10.8 is 1.3.6, for the time being this should be our baseline.

@leshill I assume that Gem.find_latest_files will be better/faster? If so, then it’s probably a good idea to already support this, but with a fallback so that it will keep on working on RubyGems 1.3.6 as well. E.g.

filename = "#{underscore(name)}/plugin"
files = Gem.respond_to?(:find_latest_files) ? Gem.find_latest_files(filename) : Gem.find_files(filename, true)

@load_plugins = true
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make underscore private and add a link to ActiveSupport’s LICENSE file?

@leshill
Copy link
Contributor Author

leshill commented Nov 6, 2013

Hi @alloy @irrationalfab,

Changes made. I removed the memoization as it was not necessary. I will make a PR on CocoaPods as well.

We use rubygems to load a subcommand plug-in gem with a file that can be
loaded at

    <command-path>/plugin.rb

The `command-path` is the namespace of the command converted to a path. For
example `Pod::Command` becomes `pod/command`.

The `plugin.rb` file should either define the subcommand(s) directly or
require the files for the subcommand(s). For example
[open_pod_bay](https://github.com/leshill/open_pod_bay) has the following
`plugin.rb`

    require 'pod/command/open'
@alloy
Copy link
Member

alloy commented Nov 6, 2013

Thanks for the changes, it looks good! Time to merge and play with it a bit before releasing (either tomorrow or Friday).

alloy added a commit that referenced this pull request Nov 6, 2013
Load subcommand plug-ins at runtime
@alloy alloy merged commit 7fae7e8 into CocoaPods:master Nov 6, 2013
@fabiopelosin
Copy link
Member

Really excited about this being merged!

@orta
Copy link
Member

orta commented Nov 6, 2013

http://i.imgur.com/Dn1MB.gif

@leshill
Copy link
Contributor Author

leshill commented Nov 8, 2013

Hi @irrationalfab,

Done. Take a look at #3 .

@fabiopelosin
Copy link
Member

👍 Looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants