drafter 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -3
- data/VERSION +1 -1
- data/drafter.gemspec +5 -3
- data/lib/drafter/apply.rb +46 -0
- data/lib/drafter/draft.rb +11 -45
- data/lib/drafter.rb +3 -1
- data/test/drafter/test_apply.rb +36 -0
- data/test/drafter/test_draft.rb +2 -2
- metadata +76 -24
data/README.rdoc
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
=
|
1
|
+
= Drafter
|
2
2
|
|
3
|
-
|
3
|
+
This is an experimental gem designed to version ActiveRecord objects with
|
4
|
+
attached CarrierWave uploads.
|
5
|
+
|
6
|
+
Don't use it yet, it's not ready for prime time.
|
4
7
|
|
5
8
|
== Contributing to drafter
|
6
9
|
|
@@ -14,6 +17,6 @@ Description goes here.
|
|
14
17
|
|
15
18
|
== Copyright
|
16
19
|
|
17
|
-
Copyright (c) 2012
|
20
|
+
Copyright (c) 2012 Dave Hrycyszyn. See LICENSE.txt for
|
18
21
|
further details.
|
19
22
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/drafter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "drafter"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["futurechimp"]
|
12
|
-
s.date = "2012-08-
|
12
|
+
s.date = "2012-08-19"
|
13
13
|
s.description = "A"
|
14
14
|
s.email = "dave.hrycyszyn@headlondon.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,11 +26,13 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"drafter.gemspec",
|
28
28
|
"lib/drafter.rb",
|
29
|
+
"lib/drafter/apply.rb",
|
29
30
|
"lib/drafter/creation.rb",
|
30
31
|
"lib/drafter/draft.rb",
|
31
32
|
"lib/drafter/draft_upload.rb",
|
32
33
|
"lib/drafter/draft_uploader.rb",
|
33
34
|
"lib/drafter/draftable.rb",
|
35
|
+
"test/drafter/test_apply.rb",
|
34
36
|
"test/drafter/test_creation.rb",
|
35
37
|
"test/drafter/test_draft.rb",
|
36
38
|
"test/drafter/test_draft_upload.rb",
|
@@ -48,7 +50,7 @@ Gem::Specification.new do |s|
|
|
48
50
|
s.homepage = "http://github.com/futurechimp/drafter"
|
49
51
|
s.licenses = ["MIT"]
|
50
52
|
s.require_paths = ["lib"]
|
51
|
-
s.rubygems_version = "1.8.
|
53
|
+
s.rubygems_version = "1.8.24"
|
52
54
|
s.summary = "Simple"
|
53
55
|
|
54
56
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Drafter
|
2
|
+
|
3
|
+
# Takes care of associating and creating Draft objects for the draftable
|
4
|
+
# class.
|
5
|
+
module Apply
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
# Apply the draft data to the draftable, without saving it..
|
9
|
+
def apply_draft
|
10
|
+
restore_attrs
|
11
|
+
restore_files
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# Whack the draft data onto the real object.
|
18
|
+
#
|
19
|
+
# @return [Draftable] the draftable object populated with the draft attrs.
|
20
|
+
def restore_attrs
|
21
|
+
draftable_columns.each do |key|
|
22
|
+
self.raw_write_attribute key, self.draft.data[key]
|
23
|
+
end
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Attach draft files to the real object.
|
28
|
+
#
|
29
|
+
# @return [Draftable] the draftable object where CarrierWave uploads
|
30
|
+
# on the object have been replaced with their draft equivalents.
|
31
|
+
def restore_files
|
32
|
+
draft.draft_uploads.each do |draft_upload|
|
33
|
+
self.send(draft_upload.draftable_mount_column + "=", draft_upload.file_data)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# We don't want to copy all the draft's columns into the draftable
|
38
|
+
# objects attributes.
|
39
|
+
#
|
40
|
+
# @return [Array] the draft's columns minus :id, :created_at, :updated_at
|
41
|
+
def draftable_columns
|
42
|
+
self.draft.data.keys - ['id', 'created_at', 'updated_at']
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/drafter/draft.rb
CHANGED
@@ -45,48 +45,14 @@ class Draft < ActiveRecord::Base
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
dr
|
60
|
-
end
|
61
|
-
|
62
|
-
# Whack the draft data onto the real object.
|
63
|
-
#
|
64
|
-
# @param [Draftable] dr a new or existing draftable to restore from the
|
65
|
-
# draft attributes.
|
66
|
-
# @return [Draftable] the draftable object populated with the draft attrs.
|
67
|
-
def restore_attrs_on(dr)
|
68
|
-
draftable_columns.each do |key|
|
69
|
-
dr.raw_write_attribute key, self.data[key]
|
70
|
-
end
|
71
|
-
dr
|
72
|
-
end
|
73
|
-
|
74
|
-
# Attach draft files to the real object.
|
75
|
-
#
|
76
|
-
# @param [Draftable] dr a new or existing draftable.
|
77
|
-
# @return [Draftable] the draftable object where CarrierWave uploads
|
78
|
-
# on the object have been replaced with their draft equivalents.
|
79
|
-
def restore_files_on(dr)
|
80
|
-
draft_uploads.each do |draft_upload|
|
81
|
-
dr.send(draft_upload.draftable_mount_column + "=", draft_upload.file_data)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# We don't want to copy all the draft's columns into the draftable
|
86
|
-
# objects attributes.
|
87
|
-
#
|
88
|
-
# @return [Array] the draft's columns minus :id, :created_at, :updated_at
|
89
|
-
def draftable_columns
|
90
|
-
self.data.keys - ['id', 'created_at', 'updated_at']
|
91
|
-
end
|
92
|
-
end
|
48
|
+
# Find the existing draftable, or build a new one, and set it up.
|
49
|
+
#
|
50
|
+
# @return the existing draftable object, or a new one of the proper
|
51
|
+
# type, with attributes and files hanging off it.
|
52
|
+
def build_draftable
|
53
|
+
draftabl = draftable.nil? ? self.draftable_type.constantize.new(:draft => self) : draftable
|
54
|
+
draftabl.apply_draft
|
55
|
+
draftabl
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/drafter.rb
CHANGED
@@ -3,12 +3,13 @@ require 'active_support/dependencies/autoload'
|
|
3
3
|
require 'active_support/core_ext/module/delegation'
|
4
4
|
require 'active_record'
|
5
5
|
|
6
|
-
require '
|
6
|
+
require File.dirname(__FILE__) + '/drafter/draft_uploader'
|
7
7
|
|
8
8
|
module Drafter
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
extend ActiveSupport::Autoload
|
11
11
|
|
12
|
+
autoload :Apply
|
12
13
|
autoload :Creation
|
13
14
|
autoload :Draft
|
14
15
|
autoload :Draftable
|
@@ -20,6 +21,7 @@ module Drafter
|
|
20
21
|
end
|
21
22
|
|
22
23
|
included do
|
24
|
+
include Apply
|
23
25
|
include Creation
|
24
26
|
include Draftable
|
25
27
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestCreation < Minitest::Unit::TestCase
|
4
|
+
|
5
|
+
describe "Applying a draft" do
|
6
|
+
before do
|
7
|
+
@article = Article.new(
|
8
|
+
:text => "initial text",
|
9
|
+
:upload => file_upload)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "to an existing article" do
|
13
|
+
before do
|
14
|
+
@article.save!
|
15
|
+
@article.text = "changed"
|
16
|
+
@article.upload = file_upload("bar.txt")
|
17
|
+
@article.save_draft
|
18
|
+
@article.reload
|
19
|
+
@article.apply_draft
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should change the article without saving it" do
|
23
|
+
assert @article.changed?
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should apply the text change" do
|
27
|
+
assert_equal("changed", @article.text)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should restore the draft upload" do
|
31
|
+
assert_equal("bar.txt", @article.upload.filename)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/test/drafter/test_draft.rb
CHANGED
@@ -66,7 +66,7 @@ class TestDraft < Minitest::Unit::TestCase
|
|
66
66
|
|
67
67
|
it "should delete the article's draft" do
|
68
68
|
assert_equal(@draft_count - 1, Draft.count)
|
69
|
-
refute @article.draft
|
69
|
+
refute @article.reload.draft
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -101,4 +101,4 @@ class TestDraft < Minitest::Unit::TestCase
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
end
|
104
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drafter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: sqlite3
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: debugger
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: minitest
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: bundler
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ~>
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: 1.0.0
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: jeweler
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ~>
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: 1.6.4
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.6.4
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: rcov
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: turn
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ! '>='
|
@@ -98,10 +133,15 @@ dependencies:
|
|
98
133
|
version: '0'
|
99
134
|
type: :development
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
- !ruby/object:Gem::Dependency
|
103
143
|
name: carrierwave
|
104
|
-
requirement:
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
105
145
|
none: false
|
106
146
|
requirements:
|
107
147
|
- - ! '>='
|
@@ -109,10 +149,15 @@ dependencies:
|
|
109
149
|
version: '0'
|
110
150
|
type: :development
|
111
151
|
prerelease: false
|
112
|
-
version_requirements:
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
113
158
|
- !ruby/object:Gem::Dependency
|
114
159
|
name: minitest-rails-shoulda
|
115
|
-
requirement:
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
116
161
|
none: false
|
117
162
|
requirements:
|
118
163
|
- - ! '>='
|
@@ -120,7 +165,12 @@ dependencies:
|
|
120
165
|
version: '0'
|
121
166
|
type: :development
|
122
167
|
prerelease: false
|
123
|
-
version_requirements:
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
124
174
|
description: A
|
125
175
|
email: dave.hrycyszyn@headlondon.com
|
126
176
|
executables: []
|
@@ -138,11 +188,13 @@ files:
|
|
138
188
|
- VERSION
|
139
189
|
- drafter.gemspec
|
140
190
|
- lib/drafter.rb
|
191
|
+
- lib/drafter/apply.rb
|
141
192
|
- lib/drafter/creation.rb
|
142
193
|
- lib/drafter/draft.rb
|
143
194
|
- lib/drafter/draft_upload.rb
|
144
195
|
- lib/drafter/draft_uploader.rb
|
145
196
|
- lib/drafter/draftable.rb
|
197
|
+
- test/drafter/test_apply.rb
|
146
198
|
- test/drafter/test_creation.rb
|
147
199
|
- test/drafter/test_draft.rb
|
148
200
|
- test/drafter/test_draft_upload.rb
|
@@ -171,7 +223,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
223
|
version: '0'
|
172
224
|
segments:
|
173
225
|
- 0
|
174
|
-
hash:
|
226
|
+
hash: 3926558565189411274
|
175
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
228
|
none: false
|
177
229
|
requirements:
|
@@ -180,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
232
|
version: '0'
|
181
233
|
requirements: []
|
182
234
|
rubyforge_project:
|
183
|
-
rubygems_version: 1.8.
|
235
|
+
rubygems_version: 1.8.24
|
184
236
|
signing_key:
|
185
237
|
specification_version: 3
|
186
238
|
summary: Simple
|