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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 043b4e70db7b252237396cdce71a46a27f698cc189d462010df9c2a96897f543
4
- data.tar.gz: b94a9218a79961ae09a39adc554ba600692dcf52cef2c472f525e1adef05106a
3
+ metadata.gz: 22e6c8a3b50e9c18bbbf2270046d351d7434a5b7b89540617b0f0977cc0f32d3
4
+ data.tar.gz: 754eb2e34972631fc17ba811ae5ef4744214ac44afa7a32fc5a0388c071a9aae
5
5
  SHA512:
6
- metadata.gz: 34f7c7a88a14af1ab7072c108abaa4c1ab6d40f576c5cd70cd3afa1ec398f2b9a81fa4ce1e812281806298223b174942075dbe1f869f2b3f5c8c319706217d94
7
- data.tar.gz: ee42af4f46cd8d7a75c37cdf474147255f5c16c3683e5ea206e379efa753cd78b682ebd6cff0d0d262b1c6814a0f01ba2d9c873ec3d7a958327268df1b081651
6
+ metadata.gz: 63b27faffef9e09e06b740a0fab74dcfab7e020b9b61497554d2ccb29a7bfeae3d43086a9d40c4178aaf47745e3ca7efbde07daadbced62941f32ad497b2a373
7
+ data.tar.gz: f066d6c4df5da61da95cc4c85f797fd9465c5df9b7a7e1f99d299f59cd50737cff07c6e91c8c36dc4351de8aaa1a721a475a1181345cb978325348801f0b071f
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.8
4
- - 2.4.6
5
- - 2.5.5
6
- - 2.6.3
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.6
18
+ - rvm: 2.4.9
19
19
  gemfile: gemfiles/rails_4_1.gemfile
20
- - rvm: 2.4.6
20
+ - rvm: 2.4.9
21
21
  gemfile: gemfiles/rails_6_0.gemfile
22
- - rvm: 2.5.5
22
+ - rvm: 2.5.7
23
23
  gemfile: gemfiles/rails_4_1.gemfile
24
- - rvm: 2.6.3
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
@@ -1,5 +1,5 @@
1
1
  appraise "rails-6-0" do
2
- gem "activerecord", "~> 6.0.0"
2
+ gem "activerecord", "~> 6.0.1"
3
3
  gem "sqlite3", "~> 1.4"
4
4
  end
5
5
 
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.
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "coveralls"
31
31
  spec.add_development_dependency "simplecov"
32
32
  spec.add_development_dependency "appraisal"
33
+ spec.add_development_dependency "generator_spec"
33
34
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 6.0.0"
5
+ gem "activerecord", "~> 6.0.1"
6
6
  gem "sqlite3", "~> 1.4"
7
7
 
8
8
  gemspec path: "../"
@@ -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(user: user, parent: self)
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(user: user, parent_type: self.base_class.name)
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
@@ -1,5 +1,5 @@
1
1
  class Draft < ActiveRecord::Base
2
- belongs_to :user
2
+ belongs_to :user, polymorphic: true
3
3
  belongs_to :parent, polymorphic: true
4
4
 
5
5
  validates_presence_of :data, :target_type
@@ -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.user = user
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
@@ -1,3 +1,3 @@
1
1
  module Drafting
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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.2
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-25 00:00:00.000000000 Z
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.6
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