gardener 1.1.4 → 1.1.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.
Files changed (2) hide show
  1. data/lib/gardener.rb +26 -8
  2. metadata +3 -3
data/lib/gardener.rb CHANGED
@@ -8,7 +8,11 @@ module Gardener
8
8
  module ClassMethods
9
9
 
10
10
  attr_accessor :infinite_choice
11
-
11
+
12
+ # Deletes the file associated with this class, so you can plant new seeds. Should be done once per growing season.
13
+ def harrow
14
+ File.delete(garden_path)
15
+ end
12
16
 
13
17
  # Dump every instance of a class (every record in the database for a model) into a file
14
18
  # to be reconstituted later.
@@ -54,7 +58,6 @@ module Gardener
54
58
  sprout(str) unless str.blank?
55
59
  end
56
60
 
57
-
58
61
  # Helper function to reconstitute a record from it's yaml representation.
59
62
  def sprout(str)
60
63
  return false if str.blank?
@@ -88,6 +91,7 @@ module Gardener
88
91
 
89
92
  if res.match(/y/i)
90
93
  scott = bob
94
+ scott.instance_variable_set("@new_record", false) # Want to do an update, not an insert
91
95
  scott.save
92
96
  elsif res.match(/a/i)
93
97
  raise "Salting the earth. Nothing will grow here for some time ..."
@@ -104,9 +108,6 @@ module Gardener
104
108
 
105
109
  end # End ClassMethods
106
110
 
107
-
108
-
109
-
110
111
  ##### Instance Methods #####
111
112
 
112
113
  def diff(obj)
@@ -138,7 +139,6 @@ module Gardener
138
139
  dir = File.join [Rails.root, 'db', 'garden']
139
140
  Dir.mkdir(dir) unless File.exists?(dir)
140
141
 
141
-
142
142
  File.open(File.join([Rails.root, 'db', 'garden', "#{c}.yml"] ), 'a') do |file|
143
143
  file << self.to_yaml
144
144
  end
@@ -149,10 +149,9 @@ module Gardener
149
149
  tom = self.send(k) if self.respond_to?(k)
150
150
  [*tom].each{|y| y.plant_seed({:include => v})}
151
151
  end
152
-
152
+ true
153
153
  end
154
154
 
155
-
156
155
  def things_to_include(options)
157
156
  # [*THING] is so that THING can be an array or a single instance of a class.
158
157
  # .each will blow up if THING is just an instance, not an array, unless we explode and re-array it.
@@ -169,6 +168,25 @@ module Gardener
169
168
  {"#{self.class.to_s.underscore}_#{self.id}" => self.attributes}.to_yaml
170
169
  end
171
170
 
171
+ # Workaround for DelayedJob which has kind of an unfriendly monkey patch on ActiveRecord::Base
172
+ # This in itself is kind of rude, since I don't know if anyone besides DelayedJob has a (legitimate) reason
173
+ # for hanging :yaml_new on AR::Base. If you notice that my patch to unfuck the DJ patch is fucking you,
174
+ # please let me know, I want us all to get along. Hopefully we'll all get the refinements thing working soon
175
+ # and stop stepping on each others toes.
176
+ if ActiveRecord::Base.respond_to? :yaml_new
177
+ class ActiveRecord::Base
178
+ def self.yaml_new(klass, tag, val)
179
+ foo = klass.find(val['attributes']['id'])
180
+ rescue ActiveRecord::RecordNotFound
181
+ foo = klass.new
182
+ val['attributes'].each do |k, v|
183
+ meth = "#{k}="
184
+ foo.send(meth, v) if foo.respond_to?(meth)
185
+ end
186
+ foo
187
+ end
188
+ end
189
+ end
172
190
 
173
191
 
174
192
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 1
8
- - 4
9
- version: 1.1.4
8
+ - 5
9
+ version: 1.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bob Larrick
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-10 00:00:00 -05:00
17
+ date: 2011-03-14 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20