Class: Gem::Commands::LocalCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::LocalCommand
- Defined in:
- lib/rubygems/commands/local_command/version.rb,
lib/rubygems/commands/local_command.rb
Defined Under Namespace
Classes: Setting
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
-
#add(name = nil, location = nil, *args) ⇒ Object
(also: #new)
COMMANDS.
- #arguments ⇒ Object
- #description ⇒ Object
- #execute ⇒ Object
-
#full_help ⇒ Object
Shows in ‘gem help local`.
- #help(cmd = nil, *args) ⇒ Object
- #ignore(*names) ⇒ Object (also: #off, #remote, #deactivate, #disable)
-
#initialize ⇒ LocalCommand
constructor
A new instance of LocalCommand.
- #install(*args) ⇒ Object (also: #init)
-
#invoke_with_build_args(args, build_args) ⇒ Object
Override core dispatcher to do our own help.
- #rebuild(*args) ⇒ Object
- #remove(name = nil, *args) ⇒ Object (also: #delete)
- #status(name = nil, *args) ⇒ Object (also: #config, #show)
- #usage ⇒ Object
- #use(*names) ⇒ Object (also: #on, #activate, #enable, #renable, #reactivate)
- #version(*args) ⇒ Object
Constructor Details
#initialize ⇒ LocalCommand
Returns a new instance of LocalCommand.
13 14 15 |
# File 'lib/rubygems/commands/local_command.rb', line 13 def initialize super("local", "A configuration manager for bundler's local gem settings.") end |
Instance Method Details
#add(name = nil, location = nil, *args) ⇒ Object Also known as: new
COMMANDS
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rubygems/commands/local_command.rb', line 72 def add(name = nil, location = nil, *args) if name and location and args.empty? setting = Setting.new(location) if bundler_add name, setting update_configuration(name, location: setting.location, status: setting.status) end else arity_error __method__ end end |
#arguments ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubygems/commands/local_command.rb', line 23 def arguments "add <gem> <path> | Adds or overwrites a local gem configuration.\nstatus [gem] | Displays all or a particular local gem configuration.\nremove <gem> | Removes a local gem from `gem local` configuration.\nuse [gem, ...] | Enables local gem(s).\nignore [gem, ...] | Disables local gem(s).\nrebuild | Regenerates your `.gemlocal` from bundle config state.\ninstall | Adds `.gemlocal` artifact to project `.gitignore`.\nhelp [cmd] | Displays help information.\nversion | Displays gem-local version.\n ARGS\nend\n" |
#description ⇒ Object
17 18 19 20 21 |
# File 'lib/rubygems/commands/local_command.rb', line 17 def description "The `gem local` command allows you to save, toggle, and recall per-project usage of `bundle config local.<gem>` settings.\n DESC\nend\n" |
#execute ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubygems/commands/local_command.rb', line 41 def execute if cmd = [:args].shift if available_cmds.include? cmd public_send cmd, *[:args] else raise "`gem local #{cmd}` is not a valid command, try:\n" + arguments end else help end end |
#full_help ⇒ Object
Shows in ‘gem help local`
202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/rubygems/commands/local_command.rb', line 202 def full_help [ usage, nil, 'Summary:', summary, nil, 'Description:', description, nil, 'Arguments:', arguments, ].join("\n") end |
#help(cmd = nil, *args) ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/rubygems/commands/local_command.rb', line 183 def help(cmd = nil, *args) if not cmd and args.empty? puts description + "\n" + arguments elsif cmd puts info_for(cmd) else arity_error __method__ end end |
#ignore(*names) ⇒ Object Also known as: off, remote, deactivate, disable
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/rubygems/commands/local_command.rb', line 132 def ignore(*names) names = configuration.values if names.empty? names.each do |name| if setting = configuration[name] if bundler_remove name, setting update_configuration(name, status: "off") else raise "Could not deactivate gem, make sure `bundle config --delete local.#{name}` succeeds" end else raise "`gem local #{__method__}` could not find `#{name}` in:\n#{find_configuration}" end end end |
#install(*args) ⇒ Object Also known as: init
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rubygems/commands/local_command.rb', line 168 def install(*args) if args.empty? File.open(find_file('.gitignore'), "a+") do |file| %w[.bundle .gemlocal].each do |ignorable| unless file.each_line.any?{ |line| line.include? ignorable } file.puts ignorable end end end else arity_error __method__ end end |
#invoke_with_build_args(args, build_args) ⇒ Object
Override core dispatcher to do our own help
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubygems/commands/local_command.rb', line 54 def invoke_with_build_args(args, build_args) args [:build_args] = build_args self.ui = Gem::SilentUI.new if [:silent] if [:help] then puts full_help elsif @when_invoked then @when_invoked.call else execute end end |
#rebuild(*args) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rubygems/commands/local_command.rb', line 151 def rebuild(*args) if args.empty? configuration = read_configuration.dup clear_configuration_cache File.open(find_configuration, "w") do |file| configuration.each do |name, old_setting| if setting = bundler_value(name, old_setting) file.puts configuration_for(name, setting.location, setting.status) end end end show else arity_error __method__ end end |
#remove(name = nil, *args) ⇒ Object Also known as: delete
102 103 104 105 106 107 108 109 |
# File 'lib/rubygems/commands/local_command.rb', line 102 def remove(name = nil, *args) if name and args.empty? configuration.delete(name) write_configuration(configuration) else arity_error __method__ end end |
#status(name = nil, *args) ⇒ Object Also known as: config, show
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rubygems/commands/local_command.rb', line 84 def status(name = nil, *args) if not name and args.empty? configuration.each do |name, setting| puts show_setting_for(name, setting) end elsif name if setting = configuration[name] puts show_setting_for(name, setting) else raise "`gem local #{__method__}` could not find `#{name}` in:\n#{find_configuration}" end else arity_error __method__ end end |
#usage ⇒ Object
37 38 39 |
# File 'lib/rubygems/commands/local_command.rb', line 37 def usage "#{program_name} subcommand [args...]" end |
#use(*names) ⇒ Object Also known as: on, activate, enable, renable, reactivate
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/rubygems/commands/local_command.rb', line 112 def use(*names) names = configuration.keys if names.empty? names.each do |name| if setting = configuration[name] if bundler_add name, setting update_configuration(name, status: "on") else raise "Could not activate gem, make sure `bundle config local.#{name}` #{setting.location} succeeds" end else raise "`gem local #{__method__}` could not find `#{name}` in:\n#{find_configuration}" end end end |
#version(*args) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/rubygems/commands/local_command.rb', line 193 def version(*args) if args.empty? puts "v#{Gem::Commands::LocalCommand::VERSION}" else arity_error __method__ end end |