gemtronics 0.4.0 → 0.4.5

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.
@@ -68,6 +68,28 @@ module Gemtronics
68
68
  end
69
69
  end
70
70
 
71
+ # Calls the <tt>gem</tt> method with <tt>name</tt> and <tt>version</tt>.
72
+ # It does NOT do any requiring!
73
+ #
74
+ # Example:
75
+ # gd = Gemtronics::Definition.new
76
+ # gd.name = 'my_gem'
77
+ # gd.version = '1.2.3'
78
+ # gd.load_gem # => gem('my_gem', '1.2.3')
79
+ def load_gem
80
+ gem(self.name, self.version)
81
+ end
82
+
83
+ # Calls the <tt>load_gem</tt> method and then requires each
84
+ # file in the <tt>require_list</tt>
85
+ def require_gem(options = {})
86
+ load_gem
87
+ self.require_list.each do |f|
88
+ puts "require #{f}" if options[:verbose]
89
+ require f
90
+ end
91
+ end
92
+
71
93
  private
72
94
  def self.build_method(name, defval = nil, key = name) # :nodoc:
73
95
  define_method(name) do
@@ -143,5 +143,17 @@ module Gemtronics
143
143
  end
144
144
  end
145
145
 
146
+ # Finds and returns a Gemtronics::Definition for the specified
147
+ # gem, if one exists.
148
+ #
149
+ # Example:
150
+ # Gemtronics.group(:test).search('gem1')
151
+ def search(name, options = {})
152
+ self.gems.each do |g|
153
+ return g if g.name == name
154
+ end
155
+ return nil
156
+ end
157
+
146
158
  end # Grouper
147
159
  end # Gemtronics
@@ -13,7 +13,6 @@ module Gemtronics
13
13
 
14
14
  def initialize # :nodoc:
15
15
  reset!
16
- self.installed_gems = []
17
16
  end
18
17
 
19
18
  # Creates, or reopens a new group of gems. It takes the name of the
@@ -101,11 +100,7 @@ module Gemtronics
101
100
  options = {:verbose => false}.merge(options)
102
101
  group.gems.each do |g|
103
102
  if g.load? == true
104
- gem(g.name, g.version)
105
- g.require_list.each do |f|
106
- puts "require #{f}" if options[:verbose]
107
- require f
108
- end
103
+ g.require_gem
109
104
  end
110
105
  end
111
106
  end
@@ -155,6 +150,62 @@ module Gemtronics
155
150
 
156
151
  def reset! # :nodoc:
157
152
  self.groups = {}
153
+ self.installed_gems = []
154
+ end
155
+
156
+ # Finds and returns a Gemtronics::Definition for the specified
157
+ # gem, if one exists.
158
+ #
159
+ # Search Order:
160
+ # If the option <tt>:group</tt> is passed in it will search
161
+ # only within that group.
162
+ #
163
+ # If <tt>RAILS_ENV</tt> is defined it will search in the group
164
+ # that matches the current Rails environment
165
+ #
166
+ # Finally it will search all gems and return the first one it
167
+ # finds. There is no guarantee as to the order it searches through
168
+ # the groups.
169
+ #
170
+ # Gemtronics.find('gem1')
171
+ # Gemtronics.find('gem1', :group => :production)
172
+ def find(name, options = {})
173
+ group = options[:group]
174
+ if group
175
+ group = self.groups[group.to_sym]
176
+ return nil if group.nil?
177
+ gemdef = group.search(name, options)
178
+ return gemdef unless gemdef.nil?
179
+ elsif defined?(RAILS_ENV)
180
+ return find(name, {:group => RAILS_ENV.to_sym}.merge(options))
181
+ else
182
+ self.groups.each do |key, group|
183
+ gemdef = group.search(name, options)
184
+ return gemdef unless gemdef.nil?
185
+ end
186
+ end
187
+ raise "#{name} has not been defined!"
188
+ end
189
+
190
+ # Allows you to chain method calls together. An important note is
191
+ # that the <tt>*args</tt> are only passed into the first method in
192
+ # the chain.
193
+ #
194
+ # Example:
195
+ # Gemtronics.find_and_require_gem('gem1', :group => :production)
196
+ #
197
+ # This will call the <tt>find</tt> method on Gemtronics::Manager
198
+ # and pass it the arguments <tt>{:group => :production}</tt>. It will then
199
+ # call the <tt>require_gem</tt> method on the Gemtronics::Definition class
200
+ # returned by the <tt>find</tt> method.
201
+ def method_missing(sym, *args)
202
+ chain = sym.to_s.split('_and_')
203
+ raise NoMethodError.new(sym.to_s) if chain.nil? || chain.empty? || chain.size == 1
204
+ res = self.send(chain[0], *args)
205
+ chain[1..chain.size].each do |meth|
206
+ res = res.send(meth)
207
+ end
208
+ return res
158
209
  end
159
210
 
160
211
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemtronics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.5
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-19 00:00:00 -04:00
12
+ date: 2009-08-20 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15