drafting 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -4
- data/README.md +4 -1
- data/Rakefile +1 -1
- data/drafting.gemspec +1 -1
- data/gemfiles/rails_4_2.gemfile +1 -1
- data/gemfiles/rails_5_0.gemfile +1 -1
- data/gemfiles/rails_5_1.gemfile +1 -1
- data/lib/drafting/base_class_methods.rb +2 -2
- data/lib/drafting/class_methods.rb +1 -1
- data/lib/drafting/draft.rb +5 -1
- data/lib/drafting/version.rb +1 -1
- data/lib/generators/drafting/migration/templates/migration.rb +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51d1c3d502674eec9428f13ab49b4bb409d167a29fa7b2394d201122c5f52d3b
|
4
|
+
data.tar.gz: 9484a9e2dd0a4105323d892f0df8c5a29e324cb54503e3bd9bd36f5b5c604db1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ca6ad79074647ff654c65c32df1ae9e78e003e0cf477c43c2b91c6c3a03d9936160fec32953b4c26d5ce0234a1568149bf8d990f396c82f2bf21a876086b183
|
7
|
+
data.tar.gz: 8b59432d40b880c1ee74666f2e4c9be2cdd5b642323ad257fa9f3cb2fd189c67c2792a5ec9412d8eda00a6301faab2a2d04b6f1d662dfe9f8458b2c60e199f0d
|
data/.travis.yml
CHANGED
@@ -2,9 +2,9 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 2.0.0
|
4
4
|
- 2.1.10
|
5
|
-
- 2.2.
|
6
|
-
- 2.3.
|
7
|
-
- 2.4.
|
5
|
+
- 2.2.8
|
6
|
+
- 2.3.5
|
7
|
+
- 2.4.2
|
8
8
|
gemfile:
|
9
9
|
- gemfiles/rails_5_1.gemfile
|
10
10
|
- gemfiles/rails_5_0.gemfile
|
@@ -20,7 +20,7 @@ matrix:
|
|
20
20
|
gemfile: gemfiles/rails_5_0.gemfile
|
21
21
|
- rvm: 2.1.10
|
22
22
|
gemfile: gemfiles/rails_5_0.gemfile
|
23
|
-
- rvm: 2.4.
|
23
|
+
- rvm: 2.4.2
|
24
24
|
gemfile: gemfiles/rails_4_1.gemfile
|
25
25
|
before_install: gem update bundler
|
26
26
|
sudo: false
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ This Ruby gem enhances `ActiveRecord::Base` to save a draft version of the curre
|
|
14
14
|
* A draft stores associations and virtual attributes, too
|
15
15
|
* A draft is optionally linked to a given user, so every user can manage his own drafts (invisible for the other users)
|
16
16
|
* A draft is optionally linked to a parent instance. This helps showing existing drafts in a context (e.g. message drafts for a given topic)
|
17
|
-
* Only
|
17
|
+
* Only 90 lines of code
|
18
18
|
|
19
19
|
## Requirements
|
20
20
|
|
@@ -61,6 +61,9 @@ message.save_draft(current_user)
|
|
61
61
|
draft = Message.drafts(current_user).first
|
62
62
|
message = draft.restore
|
63
63
|
message.save!
|
64
|
+
|
65
|
+
drafts = Message.drafts(current_user)
|
66
|
+
messages = drafts.restore_all
|
64
67
|
```
|
65
68
|
|
66
69
|
### Linking to parent instance
|
data/Rakefile
CHANGED
data/drafting.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "rake"
|
27
27
|
spec.add_development_dependency "rspec"
|
28
28
|
spec.add_development_dependency "sqlite3"
|
29
|
-
spec.add_development_dependency "
|
29
|
+
spec.add_development_dependency "factory_bot"
|
30
30
|
spec.add_development_dependency "coveralls"
|
31
31
|
spec.add_development_dependency "simplecov"
|
32
32
|
spec.add_development_dependency "appraisal"
|
data/gemfiles/rails_4_2.gemfile
CHANGED
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
@@ -15,11 +15,11 @@ module Drafting
|
|
15
15
|
unless parent_class.method_defined? :drafts
|
16
16
|
parent_class.class_eval do
|
17
17
|
def drafts(user)
|
18
|
-
Draft.where(:
|
18
|
+
Draft.where(user: user, parent: self)
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.child_drafts(user)
|
22
|
-
Draft.where(:
|
22
|
+
Draft.where(user: user, parent_type: self.base_class.name)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/drafting/draft.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
class Draft < ActiveRecord::Base
|
2
2
|
belongs_to :user
|
3
|
-
belongs_to :parent, :
|
3
|
+
belongs_to :parent, polymorphic: true
|
4
4
|
|
5
5
|
validates_presence_of :data, :target_type
|
6
6
|
|
7
7
|
def restore
|
8
8
|
target_type.constantize.from_draft(self)
|
9
9
|
end
|
10
|
+
|
11
|
+
def self.restore_all
|
12
|
+
find_each.map(&:restore)
|
13
|
+
end
|
10
14
|
end
|
data/lib/drafting/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class DraftingMigration < Drafting::MIGRATION_BASE_CLASS
|
2
2
|
def self.up
|
3
3
|
create_table :drafts do |t|
|
4
|
-
t.string :target_type, :
|
4
|
+
t.string :target_type, null: false
|
5
5
|
t.references :user
|
6
|
-
t.references :parent, :
|
7
|
-
t.binary :data, :
|
8
|
-
t.datetime :updated_at, :
|
6
|
+
t.references :parent, polymorphic: true, index: true
|
7
|
+
t.binary :data, limit: 16777215, null: false
|
8
|
+
t.datetime :updated_at, null: false
|
9
9
|
end
|
10
10
|
|
11
11
|
add_index :drafts, [:user_id, :target_type]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drafting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: factory_bot
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
187
|
version: '0'
|
188
188
|
requirements: []
|
189
189
|
rubyforge_project:
|
190
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.7.2
|
191
191
|
signing_key:
|
192
192
|
specification_version: 4
|
193
193
|
summary: Save draft version of any ActiveRecord object
|