drafting 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -7
- data/Appraisals +1 -1
- data/README.md +11 -1
- data/drafting.gemspec +1 -0
- data/gemfiles/rails_6_0.gemfile +1 -1
- data/lib/drafting/base_class_methods.rb +10 -2
- data/lib/drafting/draft.rb +1 -1
- data/lib/drafting/instance_methods.rb +2 -1
- data/lib/drafting/version.rb +1 -1
- data/lib/generators/drafting/migration/migration_generator.rb +1 -0
- data/lib/generators/drafting/migration/templates/non_user_migration.rb +13 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22e6c8a3b50e9c18bbbf2270046d351d7434a5b7b89540617b0f0977cc0f32d3
|
4
|
+
data.tar.gz: 754eb2e34972631fc17ba811ae5ef4744214ac44afa7a32fc5a0388c071a9aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63b27faffef9e09e06b740a0fab74dcfab7e020b9b61497554d2ccb29a7bfeae3d43086a9d40c4178aaf47745e3ca7efbde07daadbced62941f32ad497b2a373
|
7
|
+
data.tar.gz: f066d6c4df5da61da95cc4c85f797fd9465c5df9b7a7e1f99d299f59cd50737cff07c6e91c8c36dc4351de8aaa1a721a475a1181345cb978325348801f0b071f
|
data/.travis.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
3
|
- 2.3.8
|
4
|
-
- 2.4.
|
5
|
-
- 2.5.
|
6
|
-
- 2.6.
|
4
|
+
- 2.4.9
|
5
|
+
- 2.5.7
|
6
|
+
- 2.6.5
|
7
7
|
gemfile:
|
8
8
|
- gemfiles/rails_6_0.gemfile
|
9
9
|
- gemfiles/rails_5_2.gemfile
|
@@ -15,13 +15,13 @@ matrix:
|
|
15
15
|
exclude:
|
16
16
|
- rvm: 2.3.8
|
17
17
|
gemfile: gemfiles/rails_6_0.gemfile
|
18
|
-
- rvm: 2.4.
|
18
|
+
- rvm: 2.4.9
|
19
19
|
gemfile: gemfiles/rails_4_1.gemfile
|
20
|
-
- rvm: 2.4.
|
20
|
+
- rvm: 2.4.9
|
21
21
|
gemfile: gemfiles/rails_6_0.gemfile
|
22
|
-
- rvm: 2.5.
|
22
|
+
- rvm: 2.5.7
|
23
23
|
gemfile: gemfiles/rails_4_1.gemfile
|
24
|
-
- rvm: 2.6.
|
24
|
+
- rvm: 2.6.5
|
25
25
|
gemfile: gemfiles/rails_4_1.gemfile
|
26
26
|
before_install: gem update bundler
|
27
27
|
sudo: false
|
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -66,6 +66,17 @@ drafts = Message.drafts(current_user)
|
|
66
66
|
messages = drafts.restore_all
|
67
67
|
```
|
68
68
|
|
69
|
+
### Migration
|
70
|
+
|
71
|
+
#### 0.5.x
|
72
|
+
|
73
|
+
Starting from 0.5.x, you will be able to save drafts under a non `User` model as such:
|
74
|
+
```
|
75
|
+
message.save_draft(author)
|
76
|
+
```
|
77
|
+
|
78
|
+
If you are upgrading from previous versions, simply run `rails g drafting:migration` again to generate the mising migration files.
|
79
|
+
|
69
80
|
### Linking to parent instance
|
70
81
|
|
71
82
|
```ruby
|
@@ -100,7 +111,6 @@ message.save!
|
|
100
111
|
* The `user` argument can be nil if you don't want to distinguish between multiple users
|
101
112
|
* Saving draft stores the data via `Marshal.dump` and `Marshal.load`. If you don't like this or need some customization, you can override the instance methods `dump_to_draft` and `load_from_draft` (see source)
|
102
113
|
|
103
|
-
|
104
114
|
## Development
|
105
115
|
|
106
116
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/drafting.gemspec
CHANGED
data/gemfiles/rails_6_0.gemfile
CHANGED
@@ -15,11 +15,19 @@ 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(
|
19
|
+
user: user,
|
20
|
+
user_type: user.try(:class).try(:name),
|
21
|
+
parent: self
|
22
|
+
)
|
19
23
|
end
|
20
24
|
|
21
25
|
def self.child_drafts(user)
|
22
|
-
Draft.where(
|
26
|
+
Draft.where(
|
27
|
+
user: user,
|
28
|
+
user_type: user.try(:class).try(:name),
|
29
|
+
parent_type: self.base_class.name
|
30
|
+
)
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
data/lib/drafting/draft.rb
CHANGED
@@ -7,7 +7,8 @@ module Drafting
|
|
7
7
|
|
8
8
|
draft.data = dump_to_draft
|
9
9
|
draft.target_type = self.class.name
|
10
|
-
draft.
|
10
|
+
draft.user_id = user.try(:id)
|
11
|
+
draft.user_type = user.try(:class).try(:name)
|
11
12
|
draft.parent = self.send(self.class.draft_parent) if self.class.draft_parent
|
12
13
|
|
13
14
|
result = draft.save
|
data/lib/drafting/version.rb
CHANGED
@@ -10,6 +10,7 @@ module Drafting
|
|
10
10
|
|
11
11
|
def create_migration_file
|
12
12
|
migration_template 'migration.rb', 'db/migrate/drafting_migration.rb'
|
13
|
+
migration_template 'non_user_migration.rb', 'db/migrate/non_user_drafting_migration.rb'
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.next_migration_number(dirname)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class NonUserDraftingMigration < Drafting::MIGRATION_BASE_CLASS
|
2
|
+
def self.up
|
3
|
+
add_column :drafts, :user_type, :string, index: true
|
4
|
+
|
5
|
+
# add in user_type for existing drafts table
|
6
|
+
# for migration from old version
|
7
|
+
Draft.update_all(user_type: 'User')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
remove_column :drafts, :user_type
|
12
|
+
end
|
13
|
+
end
|
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.5.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: 2019-08
|
11
|
+
date: 2019-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: generator_spec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: ''
|
140
154
|
email:
|
141
155
|
- mail@georg-ledermann.de
|
@@ -169,6 +183,7 @@ files:
|
|
169
183
|
- lib/drafting/version.rb
|
170
184
|
- lib/generators/drafting/migration/migration_generator.rb
|
171
185
|
- lib/generators/drafting/migration/templates/migration.rb
|
186
|
+
- lib/generators/drafting/migration/templates/non_user_migration.rb
|
172
187
|
homepage: https://github.com/ledermann/drafting
|
173
188
|
licenses:
|
174
189
|
- MIT
|
@@ -188,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
203
|
- !ruby/object:Gem::Version
|
189
204
|
version: '0'
|
190
205
|
requirements: []
|
191
|
-
rubygems_version: 3.0.
|
206
|
+
rubygems_version: 3.0.3
|
192
207
|
signing_key:
|
193
208
|
specification_version: 4
|
194
209
|
summary: Save draft version of any ActiveRecord object
|