not_yet_active_record 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/not_yet_active_record/version.rb +1 -1
- data/lib/not_yet_active_record.rb +2 -4
- data/spec/not_yet.sqlite3 +0 -0
- data/spec/support/models.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ec85494c47d00e50cec3985b1151f3b03b17fe2
|
4
|
+
data.tar.gz: 1f34b172ccd9ed4bdadd35a6fba6387f9fc828bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65cead476572ff0208538270abe2d7fcde1f2ede2fff56fd929919807e5e5d97872023a7f630cf6bb77ac328995d306132a6544cfebba12ead17fdb722d79846
|
7
|
+
data.tar.gz: 83ecdbb345d2948deb8e3dad2cf80e9223f6861f4b67f2473709058c3b06817bb8ad7a19fcacd3e3e61928cb63eb9692fd19ec86db5937987183d8e27ba20a5a
|
data/README.md
CHANGED
@@ -10,12 +10,13 @@ any later time to save into the database.
|
|
10
10
|
|
11
11
|
gem install not_yet_active_record
|
12
12
|
|
13
|
-
|
13
|
+
Next to create the UnsavedObject model and table.
|
14
14
|
|
15
15
|
rails generate not_yet_active_record
|
16
16
|
rake db:migrate
|
17
17
|
|
18
|
-
|
18
|
+
Rails will ask if you want to overwrite `unsaved_object.rb`. Confirm that you
|
19
|
+
do.
|
19
20
|
|
20
21
|
## Usage
|
21
22
|
|
@@ -2,13 +2,11 @@ require "not_yet_active_record/version"
|
|
2
2
|
require 'active_record'
|
3
3
|
|
4
4
|
module NotYetActiveRecord
|
5
|
-
|
6
5
|
|
7
6
|
module ClassMethods
|
8
7
|
def not_yet_saved
|
9
|
-
|
10
|
-
|
11
|
-
unsaved_array << unsaved.item
|
8
|
+
UnsavedObject.find_all_by_model_name(self.name).map do |unsaved|
|
9
|
+
unsaved.item
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
data/spec/not_yet.sqlite3
CHANGED
Binary file
|
data/spec/support/models.rb
CHANGED
@@ -2,4 +2,14 @@ class Post < ActiveRecord::Base
|
|
2
2
|
end
|
3
3
|
|
4
4
|
class UnsavedObjects < ActiveRecord::Base
|
5
|
+
attr_accessible :model_name, :serialized_item
|
6
|
+
|
7
|
+
def item
|
8
|
+
return nil if not serialized_item
|
9
|
+
att_hash = YAML::load(serialized_item)
|
10
|
+
att_hash.delete("id")
|
11
|
+
att_hash.delete("created_at")
|
12
|
+
att_hash.delete("updated_at")
|
13
|
+
model_name.constantize.new(att_hash)
|
14
|
+
end
|
5
15
|
end
|