geminstaller 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/COPYING +1 -0
  2. data/History.txt +4 -0
  3. data/LICENSE +21 -0
  4. data/Manifest.txt +62 -0
  5. data/README.txt +60 -0
  6. data/Rakefile +92 -0
  7. data/TODO.txt +88 -0
  8. data/bin/geminstaller +30 -0
  9. data/geminstaller.yml +34 -0
  10. data/lib/geminstaller/application.rb +105 -0
  11. data/lib/geminstaller/arg_parser.rb +162 -0
  12. data/lib/geminstaller/autogem.rb +43 -0
  13. data/lib/geminstaller/config.rb +69 -0
  14. data/lib/geminstaller/config_builder.rb +40 -0
  15. data/lib/geminstaller/dependency_injector.rb +129 -0
  16. data/lib/geminstaller/enhanced_stream_ui.rb +57 -0
  17. data/lib/geminstaller/exact_match_list_command.rb +16 -0
  18. data/lib/geminstaller/file_reader.rb +31 -0
  19. data/lib/geminstaller/gem_arg_processor.rb +44 -0
  20. data/lib/geminstaller/gem_command_line_proxy.rb +32 -0
  21. data/lib/geminstaller/gem_command_manager.rb +62 -0
  22. data/lib/geminstaller/gem_interaction_handler.rb +30 -0
  23. data/lib/geminstaller/gem_list_checker.rb +55 -0
  24. data/lib/geminstaller/gem_runner_proxy.rb +43 -0
  25. data/lib/geminstaller/gem_source_index_proxy.rb +21 -0
  26. data/lib/geminstaller/gem_spec_manager.rb +42 -0
  27. data/lib/geminstaller/geminstaller_error.rb +13 -0
  28. data/lib/geminstaller/hoe_extensions.rb +5 -0
  29. data/lib/geminstaller/install_processor.rb +56 -0
  30. data/lib/geminstaller/missing_dependency_finder.rb +41 -0
  31. data/lib/geminstaller/missing_file_error.rb +4 -0
  32. data/lib/geminstaller/noninteractive_chooser.rb +107 -0
  33. data/lib/geminstaller/output_filter.rb +49 -0
  34. data/lib/geminstaller/output_listener.rb +33 -0
  35. data/lib/geminstaller/output_observer.rb +32 -0
  36. data/lib/geminstaller/output_proxy.rb +36 -0
  37. data/lib/geminstaller/requires.rb +59 -0
  38. data/lib/geminstaller/rogue_gem_finder.rb +195 -0
  39. data/lib/geminstaller/ruby_gem.rb +44 -0
  40. data/lib/geminstaller/rubygems_exit.rb +5 -0
  41. data/lib/geminstaller/rubygems_extensions.rb +5 -0
  42. data/lib/geminstaller/unauthorized_dependency_prompt_error.rb +4 -0
  43. data/lib/geminstaller/unexpected_prompt_error.rb +4 -0
  44. data/lib/geminstaller/valid_platform_selector.rb +44 -0
  45. data/lib/geminstaller/version_specifier.rb +24 -0
  46. data/lib/geminstaller/yaml_loader.rb +22 -0
  47. data/lib/geminstaller.rb +102 -0
  48. data/start_local_gem_server.sh +1 -0
  49. data/test/test_all.rb +31 -0
  50. data/website/config.yaml +2 -0
  51. data/website/metainfo.yaml +72 -0
  52. data/website/src/code/index.page +25 -0
  53. data/website/src/community/index.page +14 -0
  54. data/website/src/community/links.page +9 -0
  55. data/website/src/default.css +168 -0
  56. data/website/src/default.template +41 -0
  57. data/website/src/documentation/documentation.page +417 -0
  58. data/website/src/documentation/index.page +88 -0
  59. data/website/src/documentation/tutorials.page +94 -0
  60. data/website/src/download.page +12 -0
  61. data/website/src/faq.page +7 -0
  62. data/website/src/index.page +38 -0
  63. metadata +107 -0
@@ -0,0 +1,417 @@
1
+ h1. Detailed Documentation
2
+
3
+ h2. Table of Contents
4
+
5
+ * "Setup":#setup
6
+ ** "Requirements":#requirements
7
+ ** "Installation":#installation
8
+ * "Command Line Options":#command_line_options
9
+ ** "Command Line Options Summary":#command_line_options_summary
10
+ ** "<code>--config</code> option":#config_option
11
+ ** "<code>--exceptions</code> option":#exceptions_option
12
+ ** "<code>--redirect-stderr-to-stdout</code> option":#redirect_stderr_to_stdout_option
13
+ ** "<code>--geminstaller-output</code> option":#geminstaller_output_option
14
+ ** "<code>--rubygems-output</code> option":#rubygems_output_option
15
+ ** "<code>--print-rogue-gems</code> option":#print_rogue_gems_option
16
+ ** "<code>--sudo</code> option":#sudo_option
17
+ ** "<code>--silent</code> option":#silent_option
18
+ ** "Unsuppressible Output":#unsuppressible_output
19
+ * "Config File":#config_file
20
+ ** "Config File Syntax Summary":#config_file_syntax_summary
21
+ ** "<code>name</code> config property":#name_config_property
22
+ ** "<code>version</code> config property":#version_config_property
23
+ ** "<code>platform</code> config property":#platform_config_property
24
+ ** "<code>install_options</code> config property":#install_options_config_property
25
+ ** "<code>check_for_upgrade</code> config property":#check_for_upgrade_config_property
26
+ ** "<code>fix_dependencies</code> config property":#fix_dependencies_config_property
27
+ ** "<code>no_autogem</code> config property":#no_autogem_config_property
28
+ ** "<code>prefer_binary_platform</code> config property":#prefer_binary_platform_config_property
29
+ * "Using GemInstaller with Ruby on Rails or Other Ruby Apps":#using_geminstaller_with_ruby_on_rails_or_other_ruby_apps
30
+ ** "Invoking <code>GemInstaller</code> from Rails":#invoking_geminstaller_from_rails
31
+ ** "Bootstrapping Rails with GemInstaller":#bootstrapping_rails_with_geminstaller
32
+ ** "Using GemInstaller from Other Ruby Apps":#using_geminstaller_from_other_ruby_apps
33
+ * "Using <code>erb</code> in config files":#using_erb_in_config_files
34
+ * "Automatic Platform Detection":#automatic_platform_detection
35
+ * "Dealing with sudo and root-owned RubyGem installations":#dealing_with_sudo
36
+ ** "Option 1 - Use the <code>-s</code> or <code>--sudo</code> option on the <code>geminstaller</code> executable":#option_1
37
+ ** "Option 2 - Run <code>sudo</code> or log in as root yourself":#option_2
38
+ ** "Option 3 - Make everything owned by the local user that runs geminstaller":#option_3
39
+ ** "Tips on configuring sudo":#tips_on_configuring_sudo
40
+ * "Automatically Requiring Gems with the <code>autogem</code> Method":#automatically_requiring_gems_with_the_autogem_method
41
+
42
+ h2(#setup). Setup
43
+
44
+ h3(#requirements). Requirements
45
+
46
+ Runtime Requirements:
47
+ * None. There are no dependencies required to run GemInstaller, other than an installation of RubyGems itself
48
+
49
+ Build/Test requirements:
50
+ * GemInstaller has a *geminstaller.yml* file to specify it's own dependencies. After installing the geminstaller gem (via 'gem install geminstaller'), change to the root of the geminstaller source tree, and run 'geminstaller' to auto-install the dependencies.
51
+
52
+ h3(#installation). Installation
53
+
54
+ *Installing Latest Release:* Run <code>'gem install geminstaller'</code> to install GemInstaller from RubyForge. Run it via <code>'sudo'</code> if necessary, but first read the section on "Dealing with sudo and root-owned RubyGem installations":#dealing_with_sudo.
55
+
56
+ *Installing Source Distribution:* Run <code>'rake install_gem'</code> from the root of the GemInstaller source tree. This assumes that Hoe and other required build/test dependencies are installed. Note this currently won't work on windows because Hoe always tries to run sudo. It will generate a pkg/geminstaller-version.gem file, though, which you can install with the <code>'gem install <pkgfile>'</code> command.
57
+
58
+ h2(#command_line_options). Command Line Options
59
+
60
+ h3(#command_line_options_summary). Command Line Options Summary
61
+
62
+ <pre>
63
+ $ geminstaller --help
64
+ Usage: geminstaller [options]
65
+
66
+ -c, --config=CONFIGPATHS Comma-delimited path(s) to GemInstaller config file(s).
67
+ -e, --exceptions Raise any exceptions, rather than just printing them and exiting
68
+ with a non-zero return code.
69
+ -d, --redirect-stderr-to-stdout Redirect all STDERR output to STDOUT. Useful to get all output when
70
+ invoking GemInstaller via system().
71
+ -g, --geminstaller-output=TYPES Comma-delimited list of output types to show from GemInstaller.
72
+ Examples:
73
+ --gall
74
+ --geminstaller-output=error,install,commandecho
75
+ Default: error,install,info
76
+ Valid types:
77
+ - none: print only fatal errors
78
+ - error: print error messages
79
+ - install: print install messages
80
+ - info: print informational messages
81
+ - commandecho: print rubygems commands as they are invoked
82
+ - debug: print debug messages
83
+ - all: print all messages
84
+ -h, --help Show this message.
85
+ -p, --print-rogue-gems Print a report of all locally installed gems which are not specified
86
+ in the geminstaller config file.
87
+ -r, --rubygems-output=TYPES Comma-delimited list of output types to show from internal:
88
+ RubyGems command invocation.
89
+ Examples:
90
+ --rall
91
+ --rubygems-output=stderr
92
+ Default: stderr
93
+ Valid types:
94
+ - none: print no output
95
+ - stdout: print standard output stream
96
+ - stderr: print standard error stream
97
+ - all: print all output
98
+ -s, --sudo Perform all gem operations under sudo (as root). Will only work on
99
+ correctly configured, supported systems. See docs for more info.
100
+ -t, --silent Suppress all output except fatal exceptions, and output from
101
+ rogue-gems option.
102
+ -v, --version Show GemInstaller version and exit.
103
+ </pre>
104
+
105
+ h3(#config_option). <code>--config</code> option
106
+
107
+ By default, GemInstaller will look for a config file named <code>geminstaller.yml</code> in the working directory. The <code>'--config'</code> option allows you to override this with a different file name or path. You can also have multiple comma-delimited paths to custom-named config files. This is useful if you have multiple projects, and want them to share a common config file, but still have project-specific overrides. You could also have a standard set of gems across multiple systems, with additional custom gems specified by individual projects. The last entries in the list will override the first ones. For example:
108
+
109
+ <pre>
110
+ geminstaller --config=../common-config/geminstaller-common-across-projects.yml,geminstaller-custom-for-myproject.yml
111
+ </pre>
112
+
113
+ h3(#exceptions_option). <code>--exceptions</code> option
114
+
115
+ By default, GemInstaller will not throw exceptions for errors when invoked via <code>GemInstaller.run</code> or <code>GemInstaller.autogem</code>. This is so that any GemInstaller errors will not abort startup of Rails or any other app other apps. However, if you do want errors to abort startup of Rails or your app, you can set this option.
116
+
117
+ h3(#redirect_stderr_to_stdout_option). <code>--redirect-stderr-to-stdout</code> option
118
+
119
+ Currently, the GemInstaller <code>--sudo</code> option works by recursively re-invoking the <code>geminstaller</code> executable via <code>system()</code>. This option is automatically added in this case to ensure that errors that would normally go to <code>stderr</code> are printed to <code>stdout</code>. There are other solutions to this problem, but as of Ruby 1.8.5, there is no _easy_ way to make a system call which will give a return code AND show both stderr and stdout _synchronously_. GemInstaller does not have and will not have any third-party runtime dependencies, so I needed to roll my own solution, and this was The Simplest Thing That Could Possibly Work.
120
+
121
+ When RubyGems supports platform specification from the command line, I won't have to select platforms programatically via stdin, and I'll be able to invoke <code>gem</code> directly via sudo. Until then, though, there must be this recursive hackishness to handle sudo.
122
+
123
+ h3(#geminstaller_output_option). <code>--geminstaller-output</code> option
124
+
125
+ The <code>--geminstaller-output</code> option controls what GemInstaller prints out about it's internal activity. It is a comma-delimited list (no spaces), which can specify any of these output types:
126
+
127
+ * none: Prints only fatal errors/exceptions which cause geminstaller to fail. The same as specifying none of the other types.
128
+ * error: Prints error messages.
129
+ * install: Prints messages indicating when gems are going to be installed. This may be gems which are directly specified in a GemInstaller config file, or dependency gems which are automatically installed to meet the requirments of a dependent gem.
130
+ * info: Prints informational messages.
131
+ * commandecho: Print rubygems commands as they are automatically invoked by GemInstaller.
132
+ * debug: Prints debug messages
133
+ * all: Prints all messages. This is the same as specifying all of the other types (except 'none')
134
+
135
+ This option works in conjuntion the <code>--rubygems-output</code>, which is used similarly, but controls output which is generated by RubyGems itself.
136
+
137
+ h3(#rubygems_output_option). <code>--rubygems-output</code> option
138
+
139
+ GemInstaller works by automatically invoking RubyGems commands. The <code>--rubygems-output</code> option controls what types of output from RubyGems is printed out. It is a comma-delimited list (no spaces), which can specify any of these output types:
140
+
141
+ * none: Prints no output from RubyGems.
142
+ * stdout: Prints standard output stream from RubyGems.
143
+ * stderr: Prints standard error stream from RubyGems.
144
+ * all: Prints all messages. This is the same as specifying all of the other types (except 'none')
145
+
146
+ h3(#print_rogue_gems_option). <code>--print-rogue-gems</code> option
147
+
148
+ The <code>--print-rogue-gems</code> option prints a report of all locally installed gems which are not specified in the active loaded GemInstaller config file(s). GemInstaller, being "Narcissistic Software" (tm), considers these "rogue gems". The output format is in YAML, so it can be cut and pasted or piped directly into a new or existing config file. This allows you to bootstrap a new system, by creating an empty config file with no gems specified, and running geminstaller with the <code>--print-rogue-gems</code> option to identify all gems which are currently installed on the system. It can also be used to identify gems which were manually installed without being entered into a GemInstaller config.
149
+
150
+ Some gems are automatically installed with RubyGems itself. The 'sources' gem always exists, and the Ruby Windows One Click Installer installs several windows-specific gems. The <code>--print-rogue-gems</code> option will include these gems, but will mark them with a comment indicating that they may have been automatically installed by RubyGems.
151
+
152
+ h3(#sudo_option). <code>--sudo</code> option
153
+
154
+ The <code>--sudo</code> option runs GemInstaller as root by using the <code>sudo</code> command. This command is neither valid nor necessary on Windows platforms. See the "Dealing with sudo and root-owned RubyGem installations":#dealing_with_sudo section for more details.
155
+
156
+ h3(#silent_option). <code>--silent</code> option
157
+
158
+ The <code>--silent</code> option suppresses all RubyGems output except fatal errors/exceptions. It overrides the <code>--geminstaller-output</code> and <code>--rubygems-output</code> options.
159
+
160
+ h3(#unsuppressible_output). Unsuppressible Output
161
+
162
+ Sometimes, errors from RubyGems activity will still be printed even if the <code>'--geminstaller-output=none'</code> or <code>--silent</code> options are specified. This usually due to some failure when building gem docs, or on a windows platform. This is probably due to a gem directly printing to stderr or stdout. GemInstaller does not currently capture this type of output, only messages which are directly generated by RubyGems itself. This may be fixed in a later release.
163
+
164
+ h2(#config_file). Config File
165
+
166
+ The GemInstaller config file is simple YAML file. It contains a section specifying all the gems you want to install, and their associated options/properties, and another section which contains defaults to apply to all gems. By default, GemInstaller will look for a config file named *<code>geminstaller.yml</code>* in the working directory, but you can override this file name (and specify multiple config files) with the "<code>--config</code> option":#config_option.
167
+
168
+ GemInstaller offers a great deal of flexibility in configuration. By creatively using multiple config files, defaults within single config files, "<code>erb</code> in config files":#using_erb_in_config_files, and the features of YAML itself, you should be able to come up with a unified GemInstaller config approach that works for multiple applications across multiple machines, platforms, and environments, with a minimum of duplication.
169
+
170
+ NOTE: Currently, the order of gems in the config file matters. It will install them, and any dependencies, in the order listed. This means if you have a gem listed explicitly, but it is a dependency of an earlier gem, it won't use the options you set - it will use default/inherited options from it's dependent gem. Perhaps a future version of GemInstaller will be smart enough to handle this better.
171
+
172
+ h3(#config_file_syntax_summary). Config File Syntax Summary
173
+
174
+ This is an example config file template showing all the valid properties (boolean defaults capitalized):
175
+
176
+ <pre>
177
+ \---
178
+ defaults:
179
+ install_options: [ any valid option for the RubyGems 'gem install' command ]
180
+ check_for_upgrade: [ true | FALSE ]
181
+ fix_dependencies: [ true | FALSE ]
182
+ no_autogem: [ true | FALSE ]
183
+ prefer_binary_platform: [ TRUE | false ]
184
+ gems:
185
+ - name: [ gem name ]
186
+ version: '[ any valid version specification for this gem, e.g. >= 1.0.0 ]'
187
+ platform: [ any valid platform for this Gem and version specification ]
188
+ install_options: [ any valid option for the RubyGems 'gem' command ]
189
+ check_for_upgrade: [ true | FALSE ]
190
+ fix_dependencies: [ true | FALSE ]
191
+ no_autogem: [ true | FALSE ]
192
+ prefer_binary_platform: [ TRUE | false ]
193
+ - name: [ another gem name ]
194
+ - name: [ yet another gem name ]
195
+ (etc...)
196
+ </pre>
197
+
198
+ All properties are optional, except for the gem name. If a default is specified, it will be used unless the gem specifically overrides it.
199
+
200
+ h3(#name_config_property). <code>name</code> config property
201
+
202
+ Required, no default. This is the name of the gem to install. GemInstaller always does an exact match on the name, a substring will not match.
203
+
204
+ h3(#version_config_property). <code>version</code> config property
205
+
206
+ Defaults to '> 0'. This is the version specification used to select a gem. The highest version which meets the specification will be installed. GemInstaller always does an exact match on the name, a substring will not match.
207
+
208
+ You should enclose the version specification in single quotes. This is not always necessary, but sometimes YAML will have trouble parsing it if you don't, so it's best to always use quotes.
209
+
210
+ There are many different options for version specifications. For more info, see the section on "Specifying Versions":http://rubygems.org/read/chapter/16 in the RubyGems User Guide.
211
+
212
+ h3(#platform_config_property). <code>platform</code> config property
213
+
214
+ Defaults to 'ruby'. This is the platform for the gem. This must match a platform which is valid and available for the gem name and version specification. See the sections on "Automatic Platform Detection":#automatic_platform_detection and the "<code>prefer_binary_platform</code> config property":#prefer_binary_platform for more info on how platforms are handled.
215
+
216
+ h3(#install_options_config_property). <code>install_options</code> config property
217
+
218
+ Defaults to empty string. The <code>install_options</code> config property can contain any option which is valid to pass to the RubyGems <code>'gem install'</code> command. These options will be passed on when GemInstaller internally invokes RubyGems. Type <code>gem install --help</code> to list the options.
219
+
220
+ h3(#check_for_upgrade_config_property). <code>check_for_upgrade</code> config property
221
+
222
+ Defaults to false. By default, GemInstaller will not perform any remote operations unless they are necessary to install a required gem. In other words, if there is a local gem which meets the specs, nothing will be done. This allows GemInstaller to still run normally when you are not connected to a network.
223
+
224
+ However, if you are using a non-specific version spec (for example, '>= 1.0.0), there COULD be a higher version available on the remote gem server. If set to true, <code>check_for_upgrade</code> will force GemInstaller to check for a higher-versioned gem on the server which still matches the version specification, and install it if one is found.
225
+
226
+ h3(#fix_dependencies_config_property). <code>fix_dependencies</code> config property
227
+
228
+ Defaults to false. Ruby Gems can depend on other gems, but the other gem might still get manually uninstalled (by using the <code>gem uninstall --ignore-dependencies GEMNAME</code>) option. The <code>--fix_dependencies</code> option will detect these missing dependencies, and automatically fix them. You shouldn't need this unless you go around uninstalling gems with the <code>--ignore-dependencies</code> option. WARNING: This option can GREATLY increase the time it takes to run GemInstaller, especially if you have a lot of gems in your config, and especially on Windows. You probably always want it left as the default of false unless you suspect that some dependencies have been uninstalled.
229
+
230
+ h3(#no_autogem_config_property). <code>no_autogem</code> config property
231
+
232
+ Defaults to false. This option will prevent the <code>autogem</code> command from automatically requiring a gem. If you only want to require a few gems, you could set the default for this property to true, and only enable it (by setting a false value) for specific gems. For more details see "Automatically Requiring Gems with the <code>autogem</code> Method":#automatically_requiring_gems_with_the_autogem_method.
233
+
234
+ h3(#prefer_binary_platform_config_property). <code>prefer_binary_platform</code> config property
235
+
236
+ Defaults to true. GemInstaller automatically guesses at the correct platform for gem which have no platform specified. Any platform which is not 'ruby' is considered a 'binary' platform.
237
+
238
+ This option determines whether the 'ruby' platform, or a 'binary' platform will be chosen first. By default, binary platforms will be chosen if there is one available which seems to match the platform of the current machine. In practice, this usually only applies to windows, since (hopefully) most gems which need to be compiled distribute a windows-specific precompiled gem version. See "Automatic Platform Detection":#automatic_platform_detection for more info.
239
+
240
+ h2(#using_geminstaller_with_ruby_on_rails_or_other_ruby_apps). Using GemInstaller with Ruby on Rails or Other Ruby Apps
241
+
242
+ GemInstaller can also be embedded in another application, such as a Rails app. This is done by invoking the GemInstaller class or the geminstaller executable directly from Ruby. This section only contains a brief explanation, see the tutorial on "Integrating GemInstaller into Ruby on Rails":#integrating_geminstaller_into_ruby_on_rails for detailed explanation.
243
+
244
+ IMPORTANT NOTE: You need to know whether you run on unix and need root/sudo access to install gems and/or gem executables. See "Dealing with sudo and root-owned RubyGem installations":#dealing_with_sudo section for more details.
245
+
246
+ First, you need to create <code>geminstaller.yml</code> in the <code>RAILS_ROOT/config</code> directory (See also "Bootstrapping your GemInstaller Config with the <code>--print-rogue-gems</code> option":#bootstrapping_your_geminstaller_config). Here's an example config file which will install (an old version of) Rails and Mongrel:
247
+
248
+ <pre>
249
+ \---
250
+ defaults:
251
+ install_options: --include-dependencies
252
+ gems:
253
+ - name: rails
254
+ version: '= 1.1.6'
255
+ - name: mongrel
256
+ version: '= 1.0.1'
257
+ platform: <%= RUBY_PLATFORM =~ /mswin/ ? 'mswin32' : 'ruby'%>
258
+ </pre>
259
+
260
+ h3(#invoking_geminstaller_from_rails). Invoking <code>GemInstaller</code> from Rails
261
+
262
+ Once you have your *<code>geminstaller.yml</code>* created, invoke the GemInstaller on app startup in your boot.rb. It should be placed right after the block which defines the RAILS_ROOT constant, as shown below ("..." indicates omitted lines):
263
+
264
+
265
+ *RAILS_ROOT/config/boot.rb*:
266
+ <pre>
267
+ ...
268
+ unless defined?(RAILS_ROOT)
269
+ ...
270
+ end
271
+
272
+ ############# Begin GemInstaller config - see http://geminstaller.rubyforge.org
273
+ require "rubygems"
274
+ require "geminstaller"
275
+
276
+ # Path(s) to your GemInstaller config file(s)
277
+ config_paths = "#{File.expand_path(RAILS_ROOT)}/config/geminstaller.yml"
278
+
279
+ # Arguments which will be passed to GemInstaller (you can add any extra ones)
280
+ args = "--config #{config_paths}"
281
+
282
+ # The 'exceptions' flag determines whether errors encountered while running GemInstaller
283
+ # should raise exceptions (and abort Rails), or just return a nonzero return code
284
+ args += " --exceptions"
285
+
286
+ # This will use sudo by default on all non-windows platforms, but requires an entry in your
287
+ # sudoers file to avoid having to type a password. It can be omitted if you don't want to use sudo.
288
+ # See http://geminstaller.rubyforge.org/documentation/documentation.html#dealing_with_sudo
289
+ args += " --sudo" unless RUBY_PLATFORM =~ /mswin/
290
+
291
+ # The 'install' method will auto-install gems as specified by the args and config
292
+ GemInstaller.run(args)
293
+
294
+ # The 'autogem' method will automatically add all gems in the GemInstaller config to your load path, using the 'gem'
295
+ # or 'require_gem' command. Note that only the *first* version of any given gem will be loaded.
296
+ GemInstaller.autogem(args)
297
+ ############# End GemInstaller config
298
+
299
+ unless defined?(Rails::Initializer)
300
+ ...
301
+ </pre>
302
+
303
+ As you can see, this example contains several comments which are hopefully self-explanatory. See the "Command Line Options Summary":#command_line_options_summary, especially the "<code>--config</code>":#config_option, "<code>--exceptions</code>":#exceptions_option, and "<code>--sudo</code>":#sudo_option options for more details, as well as the "Integrating GemInstaller into Ruby on Rails":#integrating_geminstaller_into_ruby_on_rails tutorial.
304
+
305
+ h3(#bootstrapping_rails_with_geminstaller). Bootstrapping Rails with GemInstaller
306
+
307
+ If you don't already have Rails or Mongrel installed (you've just checked your app out or deployed onto a new machine), you obviously can't use the above boot.rb method to run GemInstaller. In this case, you just need to run GemInstaller from the command line once to "bootstrap" and install the Rails/Mongrel gems. This assumes you already have your <code>geminstaller.yml</code> config file in the Rails <code>config</code> dir:
308
+
309
+ <pre>
310
+ $ cd [RAILS_APP_ROOT]/config
311
+ $ geminstaller --sudo # only use the -sudo option if necessary
312
+ </pre>
313
+
314
+ h3(#using_geminstaller_from_other_ruby_apps). Using GemInstaller from Other Ruby Apps
315
+
316
+ If you want to automatically invoke GemInstaller from some other Ruby application, the approach will be very similar to the Rails approach shown above. Instead of boot.rb, put the GemInstaller invocation into the class or script which is the very first one run when your application starts up. To use it in build scripts such as <code>rake</code>, include it in a task. GemInstaller (obviously) must run before any gems are loaded or referenced.
317
+
318
+ h2(#using_erb_in_config_files). Using <code>erb</code> in config files
319
+
320
+ The GemInstaller config file(s) are also run through erb, so you can embed any custom ruby code to dynamically generate portions of your config. This can be used to have the same config file select gems differently on different platforms or environments. Below is an example of using erb to detect and choose the platform. This is necessary with some gems, even though GemInstaller attempts to guess at the platform. See "Automatic Platform Detection":#automatic_platform_detection for more info.
321
+
322
+ <pre>
323
+ \---
324
+ # geminstaller-detect-platform.yml
325
+ gems:
326
+ - name: x10-cm17a
327
+ version: '> 1.0.0'
328
+ platform: <%= RUBY_PLATFORM =~ /mswin/ ? 'i386-mswin32' : 'ruby'%>
329
+ </pre>
330
+
331
+ h2(#automatic_platform_detection). Automatic Platform Detection
332
+
333
+ Currently (as of version 0.9.2), RubyGems does not provide any way to specify a platform programatically or via the command line. If the specified version of a gem has any binary or platform-specific releases, a list will be presented, and RubyGems will halt until input is provided via stdin. This means that even if you write a script to install your required gems, you still have to deal with parsing the list and providing stdin input to select multi-platform gems. To make it even more confusing, there are enforced requirements for what platforms are valid in a Gem specification file - the gem author can put whatever they want. The RubyGems developers plan to deal with this situation in a future release, but until then...
334
+
335
+ ...GemInstaller solves this problem! If a multi-platform gem version is found, GemInstaller will handle the list prompt, and automatically select the correct platform.
336
+
337
+ The "correct" platform can be determined in a few ways. The easiest way is to let GemInstaller guess at the platform for you. It contains logic which will attempt to determine the correct platform to choose, based on the platform of the current machine.
338
+
339
+ However, GemInstaller may not always guess right, especially for uncommon platforms, or gems which do not have a standard platform string specified. In these cases, the <code>'platform'</code> property for a gems can be specified in the geminstaller config file. If you know what platform you want for a specific gem, and you only run GemInstaller on one platform, you can hardcode this value. Even if you run GemInstaller on multiple platforms (and therefore can't hardcode the platform string), you can use <code>erb</code> to programatically pick the correct platform. See "Using <code>erb</code> in config files":#using_erb_in_config_files for an example.
340
+
341
+ See the section on the "<code>prefer_binary_platform</code> config property":#prefer_binary_platform for more info.
342
+
343
+ h2(#dealing_with_sudo). Dealing with sudo and root-owned RubyGem installations
344
+
345
+ If you only run geminstaller on Windows, you don't have to worry about this section :)
346
+
347
+ On many unix-like systems (Mac, Linux, etc.), the root user will own the local installation of RubyGems (often /usr/local/ruby) and/or the executable directory where gem executables are installed (often /usr/local/bin). If this is the case, then gems must be installed and uninstalled by the root user, or via the sudo command. This presents a problem for geminstaller, which must have this same permission to automatically install gems.
348
+
349
+ There are several different solutions this problem. The solutions that are available are also determined by the way you use geminstaller (whether you call it from the executable, or use the GemInstaller classes directly from Ruby).
350
+
351
+ A transparent solution to this problem is planned for a future release of GemInstaller. For now, however, you will need to pick one of the following approaches below. If you use sudo, you should also read the docs on configuring sudo.
352
+
353
+ h3(#option_1). Option 1 - Use the <code>-s</code> or <code>--sudo</code> option on the <code>geminstaller</code> executable
354
+
355
+ Examples:
356
+ <pre>
357
+ $ geminstaller -s
358
+ $ geminstaller --sudo
359
+ </pre>
360
+
361
+ h3(#option_2). Option 2 - Run <code>sudo</code> or log in as root yourself
362
+
363
+ Example of using sudo:
364
+ <pre>
365
+ $ sudo geminstaller
366
+ </pre>
367
+
368
+ Examples of running geminstaller as root
369
+ <pre>
370
+ $ su - # if you can log in as root on your system, OR
371
+ $ sudo -s # if you must use sudo to log in as root on your system
372
+ # geminstaller
373
+ </pre>
374
+
375
+ h3(#option_3). Option 3 - Make everything owned by the local user that runs geminstaller
376
+
377
+ (replace <code><local user></code> with your username)
378
+ <pre>
379
+ $ cd /usr/local/lib/ruby # or wherever you have ruby installed
380
+ $ sudo chown -R <local user> .
381
+ </pre>
382
+
383
+ h3(#tips_on_configuring_sudo). Tips on configuring sudo
384
+
385
+ Sudo can be configured to not ask for a password for certain commands. This will be useful if you want to run geminstaller against a root-owned gem repository without being prompted (such as a Rails app being deployed via Capistrano).
386
+
387
+ You should consult the man or info pages on sudoers and visudo for more info (<code>man sudoers</code> or <code>info sudoers</code>). _*Make sure you understand the security implications of this approach*_.
388
+
389
+ Here's an example of how <code>sudoers</code> might be configured to allow the local user to run the <code>'gem'</code>, <code>'ruby'</code>, and <code>'geminstaller'</code> commands via <code>sudo</code> without being prompted for a password. Replace <code><local user></code> with your username, and replace '/usr/local/bin/' with the appropriate path if it is different on your system:
390
+
391
+ <pre>
392
+ $ sudo visudo
393
+ add this line:
394
+ <local user> ALL = NOPASSWD: /usr/local/bin/geminstaller, /usr/local/bin/ruby, /usr/local/bin/gem
395
+ </pre>
396
+
397
+ h2(#automatically_requiring_gems_with_the_autogem_method). Automatically Requiring Gems with the <code>autogem</code> Method
398
+
399
+ GemInstaller provides a <code>GemInstaller.autogem</code> class method which will automatically invoke RubyGems' 'gem' method to add all of the gems in your GemInstaller config file(s) to the load path. On RubyGems versions 0.8.x, the 'require_gem' method is used instead.
400
+
401
+ If there are some gems you don't want to auto-require, you can set the '<code>no_autogem: true</code> config config property in the GemInstaller config file. This can be set for individual gems, or as a default.
402
+
403
+ To use it, invoke the <code>autogem</code> method, and pass a string of arguments, just like the GemInstaller command line, but it ignores arguments which are not applicable (such as -r or -s):
404
+
405
+ <pre>
406
+ ...
407
+ GemInstaller.autogem('--config=/path/to/one/geminstaller.yml,/path/to/another/geminstaller.yml')
408
+ ...
409
+ </pre>
410
+
411
+ Alternately, you are not required to pass any args if you invoke the command from a ruby file which is in the same directory as a default-named <code>'geminstaller.yml'</code> file.
412
+
413
+ You can also use the "--exceptions" argument to cause <code>autogem</code> to throw an exception if it encounters any error. This is useful if you want to abort your application startup if any gems failed to load.
414
+
415
+ *IMPORTANT NOTE*: The RubyGems <code>'gem'</code> and <code>'require_gem'</code> commands will only load a single version of any given gem onto the load path. Because of this, the GemInstaller autogem command will only process the first version that it finds of any given gem.
416
+
417
+ For more info on the RubyGems 'gem and 'require_gem' commands, see "Using Explicit Versions":http://docs.rubygems.org/read/chapter/4#page71 in the RubyGems docs.
@@ -0,0 +1,88 @@
1
+ ---
2
+ title: Quick Start
3
+ ---
4
+ h1. Quick Start
5
+
6
+ h2. Basic Usage - "Hello Doom"
7
+
8
+ * Install GemInstaller: <code>[sudo] gem install geminstaller</code>
9
+ * Create a <code>geminstaller.yml</code> file:
10
+
11
+ <pre>
12
+ \---
13
+ # geminstaller.yml sample config
14
+ gems:
15
+ - name: ruby-doom
16
+ version: '>= 0.8'
17
+ </pre>
18
+
19
+ * Run GemInstaller from the directory containing geminstaller.yml: <code>geminstaller</code>. You should see a message indicating that the gem is being installed.
20
+ * Verify that the ruby-doom gem was installed: <code>gem list ruby-doom</code>
21
+
22
+ h2. Using GemInstaller with Ruby on Rails
23
+
24
+ * Create geminstaller.yml in the RAILS_ROOT/config directory. Include entries for your Rails version, and any other gems your app needs (Note: If you are too lazy to make your config file manually, or don't know what gems you need, see the tutorial on "Bootstrapping your GemInstaller Config with the <code>--print-rogue-gems</code> option":tutorials#bootstrapping_your_geminstaller_config):
25
+
26
+ <pre>
27
+ \---
28
+ # geminstaller.yml rails app config
29
+ defaults:
30
+ install_options: --include-dependencies
31
+ gems:
32
+ - name: rails
33
+ version: '= 1.1.6'
34
+ </pre>
35
+
36
+
37
+
38
+ * Determine whether you run on unix and need root/sudo access to install gems. If you do, edit your <code>sudoers</code> file to allow the current user to run the <code>'gem'</code> command via sudo without a password. See the documentation on the GemInstaller "<code>--sudo</code> option":documentation.html#dealing_with_sudo for more details.
39
+
40
+ * Edit your Rails <code>config/boot.rb</code> to invoke GemInstaller on startup to install gems and auto-require them. The following lines should be placed right after the block which defines the RAILS_ROOT constant ("..." indicates omitted lines). If you want to know what the heck this does before sticking it in your app, there are more details in the tutorial "Integrating GemInstaller into Ruby on Rails":#integrating_geminstaller_into_ruby_on_rails
41
+
42
+ <pre>
43
+ \---
44
+ RAILS_ROOT/config/boot.rb:
45
+ ...
46
+ unless defined?(RAILS_ROOT)
47
+ ...
48
+ end
49
+
50
+ ############# Begin GemInstaller config - see http://geminstaller.rubyforge.org
51
+ require "rubygems"
52
+ require "geminstaller"
53
+
54
+ # Path(s) to your GemInstaller config file(s)
55
+ config_paths = "#{File.expand_path(RAILS_ROOT)}/config/geminstaller.yml"
56
+
57
+ # Arguments which will be passed to GemInstaller
58
+ args = "--config #{config_paths}"
59
+
60
+ # The 'exceptions' flag determines whether errors encountered while running GemInstaller
61
+ # should raise exceptions (and abort Rails), or just return a nonzero return code
62
+ exceptions = true
63
+ args += " --exceptions" if exceptions
64
+
65
+ # This will use sudo by default on all non-windows platforms, but requires an entry in your
66
+ # sudoers file to avoid having to type a password. It can be omitted if you don't want to use sudo.
67
+ # See http://geminstaller.rubyforge.org/documentation/documentation.html#dealing_with_sudo
68
+ args += " --sudo" unless RUBY_PLATFORM =~ /mswin/
69
+
70
+ # The 'install' method will auto-install gems as specified by the args and config
71
+ GemInstaller.run(args)
72
+
73
+ # The 'autogem' method will automatically add all gems in the GemInstaller config to your load path, using the 'gem'
74
+ # or 'require_gem' command. If you want to use other config file path(s), pass them as an array or comma-delimited list.
75
+ # Note that only the *first* version of any given gem will be loaded.
76
+ GemInstaller.autogem(config_paths, exceptions)
77
+ ############# End GemInstaller config
78
+
79
+ unless defined?(Rails::Initializer)
80
+ ...
81
+ </pre>
82
+
83
+ * Start your app: <code>ruby script/server</code>. You should see messages indicating the gems (and dependency gems) are being installed and auto-required.
84
+ * Stop the app, and verify the gems are installed: <code>gem list rails</code>
85
+
86
+ h2. Where to go next
87
+
88
+ See the "Tutorials":documentation/tutorials.html or the "Detailed Documentation":documentation/documentation.html for examples of more GemInstaller features.
@@ -0,0 +1,94 @@
1
+ h1. Tutorials
2
+
3
+ These are tutorials which show how to use the various features of GemInstaller. They are mostly brief, only showing the commands you need to type.
4
+
5
+ If anything is unclear, or if you'd like to see a tutorial on a topic, please submit a request on the mailing list.
6
+
7
+ * "Installing GemInstaller":#installing_geminstaller
8
+ * "Bootstrapping your GemInstaller Config with the <code>--print-rogue-gems</code> option":#bootstrapping_your_geminstaller_config
9
+ * "Using the <code>autogem</code> Option to Automatically Require Gems":#using_the_autogem_option_to_automatically_require_gems
10
+ * "Integrating GemInstaller into Ruby on Rails":#integrating_geminstaller_into_ruby_on_rails
11
+ * "Using Common or Shared Config Files":#using_common_or_shared_config_files
12
+ * "Running GemInstaller from Capistrano":#running_geminstaller_from_capistrano
13
+
14
+ h2(#installing_geminstaller). Installing GemInstaller
15
+
16
+ <pre>
17
+ $ gem install geminstaller
18
+ - OR, if you get a permission error -
19
+ $ sudo gem install geminstaller
20
+ </pre>
21
+
22
+ See also: Docs on "installation":documentation.html#installation.
23
+
24
+ h2(#bootstrapping_your_geminstaller_config). Bootstrapping your GemInstaller Config with the <code>--print-rogue-gems</code> option
25
+
26
+ You may have no idea what gems your app uses, or you might just want to create a GemInstaller config file with all the gems currently on your system, in order to install the same gems on a different system. This tutorial will show you how to use the <code>--print-rogue-gems</code> option to automatically create a GemInstaller config file.
27
+
28
+ <pre>
29
+ $ geminstaller --print-rogue-gems > geminstaller.yml
30
+ </pre>
31
+
32
+ That was easy, wasn't it? This config file should specify the exact versions for all of the gems which are currently installed on your system.
33
+
34
+ Gotchas/Notes:
35
+
36
+ # If you generated the file on a unix/mac system with compiled gems and then try to run it on a different platform (like windows) which does not have a compiler, you may get errors. The "<code>prefer_binary_platform</code> config property":documentation.html#prefer_binary_platform_config_property will try to guess at the correct platform, but if a binary version of the gem does not exist for your platform, or if <code>prefer_binary_platform</code> fails to guess the right platform, you may still fail.
37
+ # The <code>--print-rogue-gems</code> option generates *exact* version specifications. This means that you won't ever get any gem upgrades by running GemInstaller with the standard generated file. This may be good (an upgrade can never break your app unexpectedly). However, you may wish to modify some of the version specifications to allow for upgrades. If you do this, remember to set the "<code>check_for_upgrade</code> config property":documentation.html#check_for_upgrade_config_property to true, but be aware that this will cause GemInstaller to check the remote gem server for upgrades each time it runs, and cause it to run slow or fail if the server is unavailable.
38
+
39
+ See also: Docs on "<code>--print-rogue-gems</code> option":documentation.html#print_rogue_gems_option, "<code>prefer_binary_platform</code> config property":documentation.html#prefer_binary_platform_config_property, and "<code>check_for_upgrade</code> config property":documentation.html#check_for_upgrade_config_property
40
+
41
+ h2(#using_the_autogem_option_to_automatically_require_gems). Using the <code>autogem</code> Option to Automatically Require Gems option
42
+
43
+ GemInstaller can automatically run the RubyGems 'gem' or 'require_gem' method to automatically add all of the gems in your GemInstaller config file(s) to the load path. Here's an example.
44
+
45
+ First, create a simple *<code>geminstaller.yml</code>* file:
46
+ <pre>
47
+ \---
48
+ gems:
49
+ - name: ruby-doom
50
+ version: '= 0.8'
51
+ </pre>
52
+
53
+ Now, we'll use <code>irb</code> to test autogem, and verify that it can add the ruby-doom gem to the load path:
54
+ <pre>
55
+ $ irb
56
+ irb(main):001:0> require 'rubygems'
57
+ => true
58
+ irb(main):002:0> require 'geminstaller'
59
+ => true
60
+ irb(main):003:0> GemInstaller.autogem('--config=geminstaller.yml')
61
+ => autogem returns the gem object(s) as it's return value...
62
+ irb(main):004:0> $: # Now verify the gem was added to the load path
63
+ => ["/usr/local/lib/ruby/gems/1.8/gems/ruby-doom-0.8/lib", ...]
64
+ </pre>
65
+
66
+ Note that <code>autogem</code> takes arguments in the same format as the GemInstaller command line and <code>run</code> method, but it ignores arguments which are not applicable (such as -r or -s). You could also specify no argument at all if you wanted to simply use the default <code>geminstaller.yml</code> file in the current directory. If you don't want a certain gem to be loaded, you can set the <code>no-autogem</code> property to true for that gem in your config file.
67
+
68
+ You can also put a call to <code>autogem</code> during your application startup to automatically load all the correct gem versions which are specified by your config file. See "Integrating GemInstaller into Ruby on Rails":#integrating_geminstaller_into_ruby_on_rails for an example.
69
+
70
+ See also: Docs on "Automatically Requiring Gems with the <code>autogem</code> Method":documentation.html#automatically_requiring_gems_with_the_autogem_method
71
+
72
+
73
+
74
+
75
+ h2(#integrating_geminstaller_into_ruby_on_rails). Integrating GemInstaller into Ruby on Rails
76
+
77
+ TODO: Write this, for now see docs on "Using GemInstaller with Ruby on Rails or Other Ruby Apps":documentation.html#using_geminstaller_with_ruby_on_rails_or_other_ruby_apps.
78
+
79
+ See also: Docs on "Using GemInstaller with Ruby on Rails or Other Ruby Apps":documentation.html#using_geminstaller_with_ruby_on_rails_or_other_ruby_apps.
80
+
81
+
82
+ h2(#using_common_or_shared_config_files). Using Common or Shared Config Files
83
+
84
+ TODO: Write this, for now see docs on the "<code>--config</code>":documentation.html#config_option option.
85
+
86
+ See also: Docs on the "<code>--config</code>":documentation.html#config_option option.
87
+
88
+
89
+ h2(#running_geminstaller_from_capistrano). Running GemInstaller from Capistrano
90
+
91
+ TODO: Write this, for now see docs on "Using GemInstaller from Other Ruby Apps":documentation.html#using_geminstaller_from_other_ruby_apps
92
+
93
+ See also: Docs on "Using GemInstaller from Other Ruby Apps":documentation.html#using_geminstaller_from_other_ruby_apps.
94
+
@@ -0,0 +1,12 @@
1
+ ---
2
+ title: Download
3
+ ---
4
+ h1. Installation / Download
5
+
6
+ GemInstaller is a standard RubyGem, and can be installed as usual (prefix with <code>sudo</code> if necessary):
7
+
8
+ <pre>
9
+ gem install geminstaller
10
+ </pre>
11
+
12
+ Alternately, you can download and install the gem file from the GemInstaller RubyForge download page: "http://rubyforge.org/frs/?group_id=1902":http://rubyforge.org/frs/?group_id=1902
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: FAQ
3
+ ---
4
+ h1. Frequently Asked Questions
5
+
6
+ Q: Why don't the tests/specs run on Windows?<br/>
7
+ A: Dunno, something with the process handling on windows for TestGemHome and EmbeddedGemServer. The manual application tests under spec/smoketest/ work on windows, though.