mm-draft 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 220381bc555c836661398b132bf81d72da0f555c
4
- data.tar.gz: 246c792cc5415c90189e39f57c4b36a4fa05e1f9
3
+ metadata.gz: 3e1db6a6bf3c38fb8e5024fee979f5edd37174b8
4
+ data.tar.gz: 4f1e604160432a5a8ef04efa74fe3f705fb2bd7f
5
5
  SHA512:
6
- metadata.gz: f177e282b70d2073b394ec42db30d6045e17fba04593a0b63797feeb0ddbab4e574f6dd42499a8a4408eb2d4a825515f9dc7f00b7f0847ea7397d35c6c169c3c
7
- data.tar.gz: 98e8501ff1417fd4310b2235d6bf2cc7e1351018cb267f476dd8a247b2dee33aa4bc4f30917e631670b4e0ffa102e76b4e5c852aa12bbcca3f0d8ce6b96d281a
6
+ metadata.gz: f85ba7db6bda0423638745931227cfe3514d05c20d5d24ea348c49f2b70a118a4a46152bbad205f6e3cdc29cd2c7738f496fbcec8d63870891638d56b5531558
7
+ data.tar.gz: ac814e646bddfae8e3b0f9b432f8f0bd0ce0663a55f622a21d55929764fde6da46468216c7b7567f4ecbbee15271454fdd400514132d92479f4a1a8162f0a0b4
data/README.md CHANGED
@@ -7,17 +7,19 @@ Plugin for MongoMapper to have draft/published option on models.
7
7
  NOTE: Can have issues with other plugins...
8
8
 
9
9
  ##Instance methods
10
- <pre>
10
+
11
+ ```
11
12
  .draft? - true/false
12
13
  .published? - true/false
13
14
  .published_record - returns the published record) (or nil, if the document never has been published)
14
15
  .draft_record - returns the draft record for a published record
15
- </pre>
16
+ ```
16
17
 
17
18
  *draft_record* will return self if the draft? returns true
18
19
  *published_record* will return self if draft? returns false
19
20
 
20
21
  ## Usage:
22
+
21
23
  Create record as normal.
22
24
 
23
25
  *.save* - Saves draft (with normal validation)
@@ -33,16 +35,19 @@ Duplicating the records also gives the benefit of working directly on the publis
33
35
  ## Example
34
36
 
35
37
  ### Model
36
- <pre>
38
+
39
+ ```ruby
37
40
  class Monkey
38
41
  include MongoMapper::Document
39
42
  plugin MongoMapper::Draft
40
43
 
41
44
  key :name, String, :default => "test"
42
45
  end
43
- </pre>
46
+ ```
47
+
44
48
  ### Usage of model
45
- <pre>
49
+
50
+ ```ruby
46
51
  m = Monkey.new
47
52
  m.name = "Leif"
48
53
  m.save
@@ -56,7 +61,7 @@ m.save
56
61
  m.name # returns "Artn"
57
62
 
58
63
  m.published_model.name # returns "Leif"
59
- </pre>
64
+ ```
60
65
 
61
66
 
62
67
  Copyright (c) 2011 Leif Ringstad, released under the MIT license
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ namespace :test do
10
10
  test.libs << 'test'
11
11
  test.ruby_opts << '-rubygems'
12
12
  test.pattern = 'test/unit/**/test_*.rb'
13
- test.verbose = true
13
+ test.verbose = true
14
14
  end
15
15
 
16
16
  #TODO Add performance
@@ -18,7 +18,7 @@ namespace :test do
18
18
  test.libs << 'test'
19
19
  test.ruby_opts << '-rubygems'
20
20
  test.pattern = 'test/performance/test/**/*.rb'
21
- test.verbose = true
21
+ test.verbose = true
22
22
  end
23
23
  end
24
24
 
@@ -33,9 +33,9 @@ module MongoMapper
33
33
  end
34
34
 
35
35
 
36
- # if already published, keep some old data to update instead of insert
36
+ # if already published, update the record
37
37
  if (self.published?)
38
- old_published_record = self.published_record
38
+ # old_published_record = self.published_record
39
39
  # support for mm-tree
40
40
  # remove parents from previous published record
41
41
  # TREE Support disabled for now
@@ -44,19 +44,31 @@ module MongoMapper
44
44
  # old_published_record.save
45
45
  # end
46
46
  # destroy old published record... Not ideal, but should work
47
- self.published_record.destroy if self.published_record != nil
48
- live_record = self.clone
49
- live_record.created_at = old_published_record.created_at if self.respond_to?("created_at")
50
- else
47
+ # self.published_record.destroy if self.published_record != nil
48
+ # live_record = self.clone
49
+ # live_record.created_at = old_published_record.created_at if self.respond_to?("created_at")
50
+ update_attribs = self.attributes.clone
51
+ ["_id", "created_at", "updated_at"].each do |rmkey|
52
+ update_attribs.delete(rmkey)
53
+ end
54
+ update_attribs["draft"] = false
55
+ update_attribs["draft_record_published_id"] = nil
56
+ live_record = self.published_record
57
+ live_record.update_attributes!(update_attribs)
58
+ else # clone the record
59
+
51
60
  live_record = self.clone
52
- live_record.created_at = Time.now.utc if self.respond_to?("created_at")
61
+ if self.respond_to?("created_at")
62
+ time_proc = lambda { Time.now.utc }
63
+ live_record.created_at = time_proc.call
64
+ end
65
+ live_record.draft_record_published_id = nil
66
+ live_record.draft = false
67
+ live_record.save!
53
68
  end
54
69
 
55
- self.draft_record_published_id = live_record._id
56
- self.class.skip_callback(:save, :before, :update_timestamps ) if self.respond_to?("updated_at")
57
- self.save!
58
- self.class.set_callback(:save, :before, :update_timestamps ) if self.respond_to?("updated_at")
59
-
70
+ self.set(draft_record_published_id: live_record._id)
71
+ self.reload
60
72
 
61
73
  # TREE Support disabled for now
62
74
  # if (self.respond_to?("parent_id_field") && self.respond_to?("path_field") && self.respond_to?("depth_field"))
@@ -75,9 +87,6 @@ module MongoMapper
75
87
  # end
76
88
  # end
77
89
 
78
- live_record.draft = false;
79
- live_record.updated_at = Time.now.utc if self.respond_to?("updated_at")
80
- live_record.save!
81
90
  return true
82
91
  end
83
92
 
@@ -1,5 +1,5 @@
1
1
  module MongoMapper
2
2
  module Draft
3
- VERSION = '0.1.8'
3
+ VERSION = '0.1.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mm-draft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leif Ringstad
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n