Module: GitHub
- Extended by:
- GitHub
- Included in:
- GitHub
- Defined in:
- lib/github.rb,
lib/github/helper.rb,
lib/github/command.rb
Overview
Starting simple.
$ github <command> <args>
GitHub.register <command> do |*args|
whatever
end
We’ll probably want to use the ‘choice` gem for concise, tasty DSL arg parsing action.
Defined Under Namespace
Constant Summary collapse
- BasePath =
File.(File.dirname(__FILE__) + '/..')
Instance Method Summary collapse
- #activate(args) ⇒ Object
- #commands ⇒ Object
- #debug(*messages) ⇒ Object
- #debug? ⇒ Boolean
- #describe(hash) ⇒ Object
- #descriptions ⇒ Object
- #helper(command, &block) ⇒ Object
- #invoke(command, *args) ⇒ Object
- #load(file) ⇒ Object
- #options ⇒ Object
- #parse_options(args) ⇒ Object
- #register(command, &block) ⇒ Object
Instance Method Details
#activate(args) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/github.rb', line 37 def activate(args) = (args) load 'helpers.rb' load 'commands.rb' invoke(args.shift, *args) end |
#commands ⇒ Object
50 51 52 |
# File 'lib/github.rb', line 50 def commands @commands ||= {} end |
#debug(*messages) ⇒ Object
81 82 83 |
# File 'lib/github.rb', line 81 def debug(*) puts *.map { |m| "== #{m}" } if debug? end |
#debug? ⇒ Boolean
85 86 87 |
# File 'lib/github.rb', line 85 def debug? !!@debug end |
#describe(hash) ⇒ Object
28 29 30 |
# File 'lib/github.rb', line 28 def describe(hash) descriptions.update hash end |
#descriptions ⇒ Object
54 55 56 |
# File 'lib/github.rb', line 54 def descriptions @descriptions ||= {} end |
#helper(command, &block) ⇒ Object
32 33 34 35 |
# File 'lib/github.rb', line 32 def helper(command, &block) debug "Helper'd `#{command}`" Helper.send :define_method, command, &block end |
#invoke(command, *args) ⇒ Object
44 45 46 47 48 |
# File 'lib/github.rb', line 44 def invoke(command, *args) block = commands[command.to_s] || commands['default'] debug "Invoking `#{command}`" block.call(*args) end |
#load(file) ⇒ Object
77 78 79 |
# File 'lib/github.rb', line 77 def load(file) file[0] == ?/ ? super : super(BasePath + "/commands/#{file}") end |
#options ⇒ Object
58 59 60 |
# File 'lib/github.rb', line 58 def end |
#parse_options(args) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/github.rb', line 62 def (args) @debug = args.delete('--debug') args.inject({}) do |memo, arg| if arg =~ /^--([^=]+)=(.+)/ args.delete(arg) memo.merge($1.to_sym => $2) elsif arg =~ /^--(.+)/ args.delete(arg) memo.merge($1.to_sym => true) else memo end end end |
#register(command, &block) ⇒ Object
23 24 25 26 |
# File 'lib/github.rb', line 23 def register(command, &block) debug "Registered `#{command}`" commands[command.to_s] = Command.new(block) end |