markbates-gemtronics 0.0.1.20090812182507 → 0.1.0.20090813140240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,3 +1,118 @@
1
- README
2
- ========================================================================
3
- gemtronics was developed by: markbates
1
+ =Gemtronics - Simple and Smart Gem Management
2
+
3
+ Gemtronics is designed to mitigate the pain of gem management for your Ruby applications. It can be used with standalone Ruby libraries or in Rails applications, it doesn't much matter to Gemtronics.
4
+
5
+ ===Installation
6
+
7
+ Gemtronics is, itself, a RubyGem. So yes, there is on dependency you have to have on your machine before you can use it to manage your other gems for your projects.
8
+
9
+ $ sudo gem install gemtronics
10
+
11
+ Or, if you prefer to live on the edge:
12
+
13
+ $ sudo gem install markbates-gemtronics --source=http://gems.github.com
14
+
15
+ ==Usage
16
+
17
+ Gemtronics comes bundled with a binary that can help make life a little nicer. The binary has three different options, generate, convert, and install.
18
+
19
+ ===Generate
20
+
21
+ Gemtronics will generate a sample file for you by using the binary, like such:
22
+
23
+ $ gemtronics generate
24
+
25
+ That will output the following into a file called <code>config/gemtronics.rb</code>:
26
+
27
+ group(:default) do |g|
28
+ # g.add('gem name here')
29
+ # g.add('gem name here', :version => '1.2.3')
30
+ # g.add('gem name here', :version => '1.2.3', :source => 'http://gems.example.com')
31
+ # g.add('gem name here', :version => '1.2.3', :source => 'http://gems.example.com', :require => ['file1', 'file2'])
32
+ end
33
+
34
+ group(:production, :dependencies => :default) do |g|
35
+ end
36
+
37
+ group(:development, :dependencies => :default) do |g|
38
+ end
39
+
40
+ group(:test, :dependencies => :development) do |g|
41
+ end
42
+
43
+ If you don't like that file path you can tell it where to generate the file for you:
44
+
45
+ $ gemtronics generate path/to/my/file.rb
46
+
47
+ It is encouraged that you use the default path for your file, as it will make it easier for Gemtronics to find it later.
48
+
49
+ ===Convert
50
+
51
+ On the off chance you are using the old Gemtools project for managing your gems, Gemtronics can easily convert that old school YAML file to the Gemtronics format:
52
+
53
+ $ gemtronics convert path/to/my/gems.yml
54
+
55
+ ===Install
56
+
57
+ Once you have setup your Gemtronics file, more on that in a minute, you can use it to easily install your gems from it:
58
+
59
+ $ gemtronics install
60
+
61
+ Gemtronics will read the <code>config/gemtronics.rb</code> and install all the gems in the <code>:default</code> group. If you would like to specify a different group you can do that like so:
62
+
63
+ $ gemtronics install production
64
+
65
+ If you did not put your file in <code>config/gemtronics.rb</code> you will need to specify the path:
66
+
67
+ $ gemtronics install default path/to/my/file.rb
68
+
69
+ Gemtronics will not install gems again if they already exist on your machine. This makes installation fast and easy!
70
+
71
+ ==Configuring Your Gems
72
+
73
+ Gemtronics has the concept that gems can be grouped. Why would you want to group your gems? Great question. Perhaps you have a default set of gems that you want to use with your application, you would put them in the <code>default</code> group. In testing and development you might want to include other gems, such as <code>ruby-debug</code>, that you wouldn't want running/installed on your production machines. In this case you would group them in another group that depends on the <code>default</code> group.
74
+
75
+ Defining a group is very easy:
76
+
77
+ group(:default) do |g|
78
+ g.add('gem1')
79
+ end
80
+
81
+ When you add gems to a group you can set all the necessary gem options, or just inherit the default options. See the sample file below, or the rest of the RDOC for more information.
82
+
83
+ ===Rails
84
+
85
+ Right about now you're saying to yourself, I use the Rails gem management system, why should I use this? Well, because the Rails gem management system is flawed at it's very core. You define your gems in the environment, which means the environment must be loaded to load/install your gems. However, this cause blow up if a gem is not installed when it loads the environment. Plus, why would you want to load the environment just to install gems?
86
+
87
+ Gemtronics also has the advantage of being an independent system to Rails, which means that you can use it to install Rails for you!
88
+
89
+ ==Sample:
90
+
91
+ group(:default) do |g|
92
+ g.add('gem1')
93
+ g.add('gem2', :version => '1.2.3')
94
+ g.add('gem3', :source => 'http://gems.github.com')
95
+ g.add('gem4', :require => 'gem-four')
96
+ g.add('gem5', :require => ['gem-five', 'gemfive'])
97
+ g.add('gem6', :load => false)
98
+ end
99
+
100
+ group(:production, :dependencies => :default) do |g|
101
+ g.add('gem3', :load => false)
102
+ g.remove('gem1')
103
+ g.add('gem4', :source => 'http://gems.example.org')
104
+ end
105
+
106
+ group(:development, :dependencies => :default) do |g|
107
+ g.add('gem7', :version => '>=1.2.3.4', :load => false, :require => 'gemseven')
108
+ end
109
+
110
+ group(:test, :dependencies => :development, :source => 'http://gems.example.com') do |g|
111
+ g.add('gem8')
112
+ end
113
+
114
+ group(:staging) do |g|
115
+ g.add('gem2', :version => '3.2.1')
116
+ g.dependency(:development)
117
+ g.add('gem7', :load => true)
118
+ end
@@ -1,8 +1,8 @@
1
- module Gemtronics
1
+ module Gemtronics # :nodoc:
2
2
 
3
3
  class << self
4
4
 
5
- def method_missing(sym, *args)
5
+ def method_missing(sym, *args) # :nodoc:
6
6
  Gemtronics::Manager.instance.send(sym, *args)
7
7
  end
8
8
 
@@ -1,26 +1,95 @@
1
1
  module Gemtronics
2
+ # This class is yielded up when you create/modify a group.
3
+ # This class holds all the relevant information about the gems
4
+ # for the defined group.
5
+ #
6
+ # See Gemtronics::Manager for more details on creating a group.
2
7
  class Grouper
8
+ # The Array of gems belonging to this group.
3
9
  attr_accessor :gems
10
+ # A Hash representing the default options for this group.
4
11
  attr_accessor :group_options
5
12
 
13
+ # Creates a new Gemtronics::Grouper class. It takes a Hash
14
+ # of options that will be applied to all gems added to the group.
15
+ # These options will be merged with Gemtronics::Manager::GLOBAL_DEFAULT_OPTIONS
16
+ #
17
+ # This also takes a special option <tt>:dependencies</tt> which can
18
+ # be an Array of other groups to inherit gems from.
19
+ #
20
+ # Example:
21
+ # group(:development) do |g|
22
+ # g.add('gem1')
23
+ # end
24
+ #
25
+ # group(:test, :dependencies => :development) do |g|
26
+ # g.add('gem2')
27
+ # g.add('gem3')
28
+ # end
29
+ #
30
+ # In this example the <tt>:test</tt> group would
31
+ # now have the following gems: <tt>gem1, gem2, gem3</tt>
6
32
  def initialize(options = {})
7
33
  self.gems = []
34
+ options = {} if options.nil?
8
35
  deps = options.delete(:dependencies)
9
36
  if deps
10
37
  [deps].flatten.each do |dep|
11
38
  self.dependency(dep)
12
39
  end
13
40
  end
14
- self.group_options = options
41
+ self.group_options = Gemtronics::Manager::GLOBAL_DEFAULT_OPTIONS.merge(options)
15
42
  self
16
43
  end
17
44
 
45
+ # Adds a gem to the group. All that is required is the name of the gem.
46
+ #
47
+ # The following is a list of the options that can be passed in:
48
+ # :require # a String or Array of file(s) to be required by the system
49
+ # :version # a String representing the version number of the gem.
50
+ # :source # a String representing the source URL of where the gem lives
51
+ # :load # true/false the files specified by the :require option should be loaded
52
+ #
53
+ # These options get merged with the group options and the global options.
54
+ #
55
+ # Example:
56
+ # group(:default, :version => '>=1.0.0') do |g|
57
+ # g.add('gem1', :source => 'http://gems.example.com')
58
+ # g.add('gem2', :version => '0.9.8')
59
+ # g.add('gem3', :require => ['gem-three', 'gem3'], :version => '>2.0.0')
60
+ # g.add('gem4', :require => 'gemfour', :load => false)
61
+ # end
62
+ #
63
+ # # => [{:name => 'gem1', :version => '>=1.0.0', :source => 'http://gems.example.com',
64
+ # :require => ['gem1'], :load => true},
65
+ # {:name => 'gem2', :version => '0.9.8', :source => 'http://gems.rubyforge.org',
66
+ # :require => ['gem2'], :load => true},
67
+ # {:name => 'gem3', :version => '>2.0.0', :source => 'http://gems.rubyforge.org',
68
+ # :require => ['gem-three', 'gem3'], :load => true},
69
+ # {:name => 'gem4', :version => '>=1.0.0', :source => 'http://gems.rubyforge.org',
70
+ # :require => ['gemfour']}, :load => false]
18
71
  def add(name, options = {})
19
- g = Gemtronics::Manager::GLOBAL_DEFAULT_OPTIONS.merge(self.group_options.merge({:name => name.to_s, :require => [name.to_s]}.merge(options)))
72
+ g = self.group_options.merge({:name => name.to_s, :require => [name.to_s]}.merge(options))
20
73
  g[:require] = [g[:require]].flatten
21
74
  self.gems << g
22
75
  end
23
76
 
77
+ # Removes a gem from the group.
78
+ #
79
+ # Example:
80
+ # group(:development) do |g|
81
+ # g.add('gem1')
82
+ # g.add('gem2')
83
+ # end
84
+ #
85
+ # group(:test, :dependencies => :development) do |g|
86
+ # g.add('gem3')
87
+ # g.remove('gem2')
88
+ # g.add('gem4')
89
+ # end
90
+ #
91
+ # In this example the <tt>:test</tt> group would
92
+ # now have the following gems: <tt>gem1, gem3, gem4</tt>
24
93
  def remove(name)
25
94
  self.gems.each do |g|
26
95
  if g[:name] = name.to_s
@@ -30,6 +99,21 @@ module Gemtronics
30
99
  end
31
100
  end
32
101
 
102
+ # Injects another groups gems into this group.
103
+ #
104
+ # Example:
105
+ # group(:development) do |g|
106
+ # g.add('gem1')
107
+ # end
108
+ #
109
+ # group(:test) do |g|
110
+ # g.add('gem2')
111
+ # g.dependency(:development)
112
+ # g.add('gem3')
113
+ # end
114
+ #
115
+ # In this example the <tt>:test</tt> group would
116
+ # now have the following gems: <tt>gem2, gem1, gem3</tt>
33
117
  def dependency(name)
34
118
  group = Gemtronics::Manager.instance.groups[name.to_sym]
35
119
  if group
@@ -2,14 +2,29 @@ module Gemtronics
2
2
  class Manager
3
3
  include Singleton
4
4
 
5
+ # A Hash of the default options that are applied to all the gems.
6
+ # These options can be overidden at both the group and the individual
7
+ # gem level.
5
8
  GLOBAL_DEFAULT_OPTIONS = {:load => true, :version => '>=0.0.0', :source => 'http://gems.rubyforge.org'}
6
9
 
10
+ # A Hash of all the groups that have been defined.
7
11
  attr_accessor :groups
8
12
 
9
- def initialize
13
+ def initialize # :nodoc:
10
14
  reset!
11
15
  end
12
16
 
17
+ # Creates, or reopens a new group of gems. It takes the name of the
18
+ # group, and any options you would like all of the gems in that group
19
+ # to inherit.
20
+ #
21
+ # Example:
22
+ # group(:development, :source => 'http://gems.example.com') do |g|
23
+ # g.add('gem1')
24
+ # g.add('gem2')
25
+ # end
26
+ #
27
+ # For more information see Gemtronics::Grouper
13
28
  def group(name, options = {})
14
29
  name = name.to_sym
15
30
  options = GLOBAL_DEFAULT_OPTIONS.merge(options)
@@ -17,14 +32,63 @@ module Gemtronics
17
32
  yield g if block_given?
18
33
  end
19
34
 
35
+ # Aliases one gem group to another group.
36
+ #
37
+ # Example:
38
+ # group(:development) do |g|
39
+ # g.add('gem1')
40
+ # g.add('gem2')
41
+ # end
42
+ #
43
+ # alias_group :test, :development
44
+ #
45
+ # The result would be the same as if you had done this:
46
+ #
47
+ # group(:development) do |g|
48
+ # g.add('gem1')
49
+ # g.add('gem2')
50
+ # end
51
+ # group(:test, :dependencies => :development) do |g|
52
+ # end
20
53
  def alias_group(name, src)
21
54
  group(name, :dependencies => src)
22
55
  end
23
56
 
57
+ # Reads in a file and sets up the gems appropriately.
58
+ # The default path is <tt>'<pwd>/config/gemtronics.rb'</tt>
59
+ #
60
+ # See README for an example file.
24
61
  def load(file = File.join(FileUtils.pwd, 'config', 'gemtronics.rb'))
25
62
  eval(File.read(file), binding)
26
63
  end
27
64
 
65
+ # Requires all the gems and the specified files for the group.
66
+ # It will not require any gems that have the <tt>:load</tt>
67
+ # options set to <tt>false</tt>
68
+ #
69
+ # Example:
70
+ # group(:default) do |g|
71
+ # g.add('gem1')
72
+ # g.add('gem2', :version => '1.2.3')
73
+ # g.add('gem3', :load => false)
74
+ # g.add('gem4', :require => 'gem-four')
75
+ # g.add('gem5', :require => ['gem-five', 'gemfive'])
76
+ # g.add('gem6', :load => false)
77
+ # end
78
+ #
79
+ # Gemtronics.require_gems(:default)
80
+ #
81
+ # In this example it would do the following:
82
+ #
83
+ # gem('gem1', '>=0.0.0')
84
+ # require 'gem1'
85
+ # gem('gem2', '1.2.3')
86
+ # require 'gem2'
87
+ # gem('gem4', '>=0.0.0')
88
+ # require 'gem-four'
89
+ # gem('gem5', '>=0.0.0')
90
+ # require 'gem-five'
91
+ # require 'gemfive'
28
92
  def require_gems(group = :default, options = {})
29
93
  group = self.groups[group.to_sym]
30
94
  return if group.nil?
@@ -40,6 +104,25 @@ module Gemtronics
40
104
  end
41
105
  end
42
106
 
107
+ # This will install only the gems in the group that
108
+ # are not currently installed in the system.
109
+ #
110
+ # Example:
111
+ # group(:default) do |g|
112
+ # g.add('gem1')
113
+ # g.add('gem2', :version => '1.2.3')
114
+ # g.add('gem3', :load => false)
115
+ # g.add('gem4', :require => 'gem-four')
116
+ # g.add('gem5', :require => ['gem-five', 'gemfive'])
117
+ # g.add('gem6', :load => false, :source => 'http://gems.example.com')
118
+ # end
119
+ #
120
+ # Assuming gems <tt>gem3, gem4, gem5</tt> are previously installed:
121
+ #
122
+ # Gemtronics.install_gems(:default)
123
+ # # gem install gem1 --source=http://gems.rubyforge.org
124
+ # # gem install gem2 --source=http://gems.rubyforge.org --version=1.2.3
125
+ # # gem install gem6 --source=http://gems.example.com
43
126
  def install_gems(group = :default)
44
127
  group = self.groups[group.to_sym]
45
128
  return if group.nil?
@@ -55,17 +138,18 @@ module Gemtronics
55
138
  end
56
139
  end
57
140
 
58
- def install_all_gems
141
+ def install_all_gems # :nodoc:
59
142
  self.groups.each do |name, value|
60
143
  self.install_gems(name)
61
144
  end
62
145
  end
63
146
 
64
- def reset!
147
+ def reset! # :nodoc:
65
148
  self.groups = {}
66
149
  end
67
150
 
68
- def gem_installed?(name, version)
151
+ private
152
+ def gem_installed?(name, version) # :nodoc:
69
153
  begin
70
154
  gem(name, version)
71
155
  return true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markbates-gemtronics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.20090812182507
4
+ version: 0.1.0.20090813140240
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-12 00:00:00 -07:00
12
+ date: 2009-08-13 00:00:00 -07:00
13
13
  default_executable: gemtronics
14
14
  dependencies: []
15
15