action-draft 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +23 -1
- data/lib/action-draft/attribute.rb +18 -6
- data/lib/action-draft/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fde164f418f2264692ee13820be77814869782461b521635871c132946f4e74
|
4
|
+
data.tar.gz: 206426857fa67eac4317bf72747a7517c8fe15097308c1620b790c044fbd1a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f39f613f05c12f53448f5e17ed92bc68866db93840e937390384b52b86ec5895509a0a0d626e341ae13642fcad182f9866ca85091ab0710fd60ba64a8627c64
|
7
|
+
data.tar.gz: 596647366cde77653b62189c50bb86ce12aa462ddc2e06b840882e12e36382c1620f96fe7ffe31ca6255202a6bfaceb688b979382ed1717bbfcb79600d191e19
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
# Action Draft
|
2
2
|
|
3
|
-
Action Draft brings your ActiveRecord model to storage multiple draft attributes without add
|
3
|
+
Action Draft brings your ActiveRecord model to storage multiple draft attributes without add columns to the business table.
|
4
4
|
|
5
5
|
[](https://rubygems.org/gems/action-draft) [](https://travis-ci.org/rails-engine/action-draft)
|
6
6
|
|
7
|
+
## Features
|
8
|
+
|
9
|
+
- Save drafts without add columns to the business table.
|
10
|
+
- Work any ActiveRecord model, just add `has_draft :field_name`.
|
11
|
+
- A `publish` method for assignment the draft values to actual attributes.
|
12
|
+
- Fallback to actual attribute value when draft is nil.
|
13
|
+
|
7
14
|
## Installation
|
8
15
|
|
9
16
|
```ruby
|
@@ -67,6 +74,21 @@ irb> message.draft_content.to_s
|
|
67
74
|
"Draft message content"
|
68
75
|
```
|
69
76
|
|
77
|
+
Publish draft content:
|
78
|
+
|
79
|
+
```rb
|
80
|
+
irb> message = Message.new
|
81
|
+
irb> message.draft_title = "Message title"
|
82
|
+
irb> message.publish
|
83
|
+
|
84
|
+
irb> message.new_record?
|
85
|
+
false
|
86
|
+
irb> message.title
|
87
|
+
"Message title"
|
88
|
+
irb> message.draft_title
|
89
|
+
"Message title"
|
90
|
+
```
|
91
|
+
|
70
92
|
## License
|
71
93
|
|
72
94
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -5,7 +5,19 @@ module ActionDraft
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
included do
|
8
|
-
|
8
|
+
mattr_accessor :action_draft_attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
def publish
|
12
|
+
self.action_draft_attributes ||= []
|
13
|
+
self.action_draft_attributes.each do |_name|
|
14
|
+
self.send("#{_name}=", self.send("draft_#{_name}").to_s)
|
15
|
+
end
|
16
|
+
self.save
|
17
|
+
end
|
18
|
+
|
19
|
+
def publish!
|
20
|
+
publish ? true : raise_validation_error
|
9
21
|
end
|
10
22
|
|
11
23
|
class_methods do
|
@@ -24,14 +36,14 @@ module ActionDraft
|
|
24
36
|
#
|
25
37
|
# Message.all.with_draft_title # Avoids N+1 queries when you just want the draft fields.
|
26
38
|
def has_draft(*names)
|
27
|
-
|
39
|
+
self.action_draft_attributes ||= []
|
28
40
|
names = Array(names)
|
29
41
|
names.each do |name|
|
30
|
-
|
42
|
+
self.action_draft_attributes << name.to_sym
|
31
43
|
|
32
44
|
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
33
45
|
def draft_#{name}
|
34
|
-
self.draft_#{name}_content ||= ActionDraft::Content.new(name: "#{name}", record: self)
|
46
|
+
self.draft_#{name}_content ||= ActionDraft::Content.new(name: "#{name}", record: self, content: self.send("#{name}"))
|
35
47
|
end
|
36
48
|
|
37
49
|
def draft_#{name}=(content)
|
@@ -43,12 +55,12 @@ module ActionDraft
|
|
43
55
|
end
|
44
56
|
|
45
57
|
scope :with_drafts, -> do
|
46
|
-
names =
|
58
|
+
names = self.action_draft_attributes.map { |name| "draft_#{name}_content" }
|
47
59
|
includes(*names)
|
48
60
|
end
|
49
61
|
|
50
62
|
after_save do
|
51
|
-
|
63
|
+
self.action_draft_attributes.each do |name|
|
52
64
|
public_send("draft_#{name}").save if public_send("draft_#{name}").changed?
|
53
65
|
end
|
54
66
|
end
|
data/lib/action-draft/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-draft
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,7 +38,8 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
41
|
+
description: Action Draft brings your ActiveRecord model to storage multiple draft
|
42
|
+
attributes without add columns to the business table.
|
42
43
|
email:
|
43
44
|
- huacnlee@gmail.com
|
44
45
|
executables: []
|
@@ -78,5 +79,6 @@ requirements: []
|
|
78
79
|
rubygems_version: 3.0.3
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
|
-
summary:
|
82
|
+
summary: Action Draft brings your ActiveRecord model to storage multiple draft attributes
|
83
|
+
without add columns to the business table.
|
82
84
|
test_files: []
|