draftsman 0.1.1 → 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/.ruby-version +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/README.md +12 -2
- data/draftsman.gemspec +2 -2
- data/lib/draftsman/model.rb +39 -4
- data/lib/draftsman/version.rb +1 -1
- data/spec/models/vanilla_spec.rb +4 -16
- metadata +34 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ecc44a2da54f76db70765c3faf9e515c3aba215
|
4
|
+
data.tar.gz: e54643b21e29a16872f83ca756592c2901220db7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ec70e969b6bf40a9a8f69c87e504d2cd1fd0aa215757f022798b53d9d6d55ecc46d4282459058c277467d0eb47f397470432ab7c08e4d0641c7baf21396ec22
|
7
|
+
data.tar.gz: 6bcef513664f7de84d96ec42996a8d4130a37794446b0a8ff8df39866fc556d6dbeb24b2d2f8543c67bd9fdaddb9daadb177c2df475bed0ed7ea6af74a484171
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.1.2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## v0.2 - June 3, 2014
|
4
|
+
|
5
|
+
- Fixed [#4](https://github.com/live-editor/draftsman/issues/4) - Added `referenced_table_name` argument to scopes.
|
6
|
+
|
3
7
|
## v0.1.1 - March 7, 2014
|
4
8
|
|
5
9
|
- Fixed [#3](https://github.com/minimalorange/draftsman/issues/3) - draft_publication_dependencies not honoring drafts
|
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2013 Minimal Orange, LLC
|
3
|
+
Copyright (c) 2013-2014 Minimal Orange, LLC
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Draftsman v0.
|
1
|
+
# Draftsman v0.2 (alpha)
|
2
2
|
|
3
3
|
Draftsman is a Ruby gem that lets you create draft versions of your database records. If you're developing a system in
|
4
4
|
need of simple drafts or a publishing approval queue, then Draftsman just might be what you need.
|
@@ -50,7 +50,7 @@ Works well with Rails, Sinatra, or any other application that depends on ActiveR
|
|
50
50
|
Add Draftsman to your `Gemfile`.
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
gem 'draftsman', '0.
|
53
|
+
gem 'draftsman', '0.2'
|
54
54
|
```
|
55
55
|
|
56
56
|
Or if you want to grab the latest from `master`:
|
@@ -223,6 +223,14 @@ Widget.trashed # Limits to items that have been drafted for deletion (but not
|
|
223
223
|
Widget.live # Limits to items that have not been drafted for deletion. Best used in an "admin" area in your application.
|
224
224
|
```
|
225
225
|
|
226
|
+
These scopes optionally take a `referenced_table_name` argument for constructing more advanced queries using `includes`
|
227
|
+
eager loading or `joins`. This reduces ambiguity both for SQL queries and for your Ruby code.
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
# Query live widgets and gears without ambiguity.
|
231
|
+
Widget.live.includes(:gears, :sprockets).live(:gears)
|
232
|
+
```
|
233
|
+
|
226
234
|
### Draft Class Methods
|
227
235
|
|
228
236
|
The `Draftsman::Draft` class has the following methods:
|
@@ -498,6 +506,8 @@ work on features or find bugs!
|
|
498
506
|
|
499
507
|
## License
|
500
508
|
|
509
|
+
Copyright 2013-2014 Minimal Orange, LLC.
|
510
|
+
|
501
511
|
Draftsman is released under the [MIT License][9].
|
502
512
|
|
503
513
|
|
data/draftsman.gemspec
CHANGED
@@ -4,9 +4,9 @@ require 'draftsman/version'
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'draftsman'
|
6
6
|
s.version = Draftsman::VERSION
|
7
|
-
s.summary = "Create draft versions of your ActiveRecord models' data."
|
7
|
+
s.summary = "Create draft versions of your ActiveRecord models' data. Works with Ruby on Rails and Sinatra."
|
8
8
|
s.description = s.summary
|
9
|
-
s.homepage = 'https://github.com/
|
9
|
+
s.homepage = 'https://github.com/live-editor/draftsman'
|
10
10
|
s.authors = ['Chris Peters']
|
11
11
|
s.email = 'chris@minimalorange.com'
|
12
12
|
s.license = 'MIT'
|
data/lib/draftsman/model.rb
CHANGED
@@ -74,10 +74,40 @@ module Draftsman
|
|
74
74
|
belongs_to self.draft_association_name, :class_name => self.draft_class_name, :dependent => :destroy
|
75
75
|
|
76
76
|
# Scopes
|
77
|
-
scope :drafted,
|
78
|
-
|
79
|
-
|
80
|
-
|
77
|
+
scope :drafted, (lambda do |referenced_table_name = nil|
|
78
|
+
referenced_table_name = referenced_table_name.present? ? referenced_table_name : table_name
|
79
|
+
|
80
|
+
if where_not?
|
81
|
+
where.not(referenced_table_name => { "#{self.draft_association_name}_id" => nil })
|
82
|
+
else
|
83
|
+
where("#{referenced_table_name}.#{self.draft_association_name}_id IS NOT NULL")
|
84
|
+
end
|
85
|
+
end)
|
86
|
+
|
87
|
+
scope :published, (lambda do |referenced_table_name = nil|
|
88
|
+
referenced_table_name = referenced_table_name.present? ? referenced_table_name : table_name
|
89
|
+
|
90
|
+
if where_not?
|
91
|
+
where.not(referenced_table_name => { self.published_at_attribute_name => nil })
|
92
|
+
else
|
93
|
+
where("#{self.published_at_attribute_name} IS NOT NULL")
|
94
|
+
end
|
95
|
+
end)
|
96
|
+
|
97
|
+
scope :trashed, (lambda do |referenced_table_name = nil|
|
98
|
+
referenced_table_name = referenced_table_name.present? ? referenced_table_name : table_name
|
99
|
+
|
100
|
+
if where_not?
|
101
|
+
where.not(referenced_table_name => { self.trashed_at_attribute_name => nil })
|
102
|
+
else
|
103
|
+
where("#{self.trashed_at_attribute_name} IS NOT NULL")
|
104
|
+
end
|
105
|
+
end)
|
106
|
+
|
107
|
+
scope :live, (lambda do |referenced_table_name = nil|
|
108
|
+
referenced_table_name = referenced_table_name.present? ? referenced_table_name : table_name
|
109
|
+
where(referenced_table_name => { self.trashed_at_attribute_name => nil })
|
110
|
+
end)
|
81
111
|
end
|
82
112
|
|
83
113
|
# Returns whether or not `has_drafts` has been called on this model.
|
@@ -85,6 +115,11 @@ module Draftsman
|
|
85
115
|
method_defined?(:draftsman_options)
|
86
116
|
end
|
87
117
|
|
118
|
+
# Returns whether or not the included ActiveRecord can do `where.not(...)` style queries.
|
119
|
+
def where_not?
|
120
|
+
ActiveRecord::VERSION::STRING.to_f >= 4.0
|
121
|
+
end
|
122
|
+
|
88
123
|
# Serializes attribute changes for `Draft#object_changes` attribute.
|
89
124
|
def serialize_draft_attribute_changes(changes)
|
90
125
|
serialized_attributes.each do |key, coder|
|
data/lib/draftsman/version.rb
CHANGED
data/spec/models/vanilla_spec.rb
CHANGED
@@ -159,14 +159,8 @@ describe Vanilla do
|
|
159
159
|
describe :drafted do
|
160
160
|
subject { Vanilla.drafted }
|
161
161
|
its(:count) { should eql 1 }
|
162
|
-
|
163
|
-
it
|
164
|
-
subject.should include drafted_vanilla
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'does not include the published item' do
|
168
|
-
subject.should_not include published_vanilla
|
169
|
-
end
|
162
|
+
it { should include drafted_vanilla }
|
163
|
+
it { should_not include published_vanilla }
|
170
164
|
end
|
171
165
|
|
172
166
|
describe :live do
|
@@ -180,14 +174,8 @@ describe Vanilla do
|
|
180
174
|
describe :published do
|
181
175
|
subject { Vanilla.published }
|
182
176
|
its(:count) { should eql 1 }
|
183
|
-
|
184
|
-
it
|
185
|
-
subject.should_not include drafted_vanilla
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'includes the published item' do
|
189
|
-
subject.should include published_vanilla
|
190
|
-
end
|
177
|
+
it { should_not include drafted_vanilla }
|
178
|
+
it { subject.should include published_vanilla }
|
191
179
|
end
|
192
180
|
|
193
181
|
describe :trashed do
|
metadata
CHANGED
@@ -1,149 +1,150 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draftsman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Peters
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
- - <
|
20
|
+
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
|
-
- - <
|
30
|
+
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: capybara
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: railties
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '3.0'
|
68
|
-
- - <
|
68
|
+
- - "<"
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '5.0'
|
71
71
|
type: :development
|
72
72
|
prerelease: false
|
73
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '3.0'
|
78
|
-
- - <
|
78
|
+
- - "<"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '5.0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: sinatra
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - ~>
|
85
|
+
- - "~>"
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '1.0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- - ~>
|
92
|
+
- - "~>"
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '1.0'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
96
|
name: rspec-rails
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- -
|
99
|
+
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
101
|
version: '0'
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- -
|
106
|
+
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
name: shoulda-matchers
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
|
-
- -
|
113
|
+
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
type: :development
|
117
117
|
prerelease: false
|
118
118
|
version_requirements: !ruby/object:Gem::Requirement
|
119
119
|
requirements:
|
120
|
-
- -
|
120
|
+
- - ">="
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
123
|
- !ruby/object:Gem::Dependency
|
124
124
|
name: sqlite3
|
125
125
|
requirement: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- - ~>
|
127
|
+
- - "~>"
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '1.2'
|
130
130
|
type: :development
|
131
131
|
prerelease: false
|
132
132
|
version_requirements: !ruby/object:Gem::Requirement
|
133
133
|
requirements:
|
134
|
-
- - ~>
|
134
|
+
- - "~>"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '1.2'
|
137
|
-
description: Create draft versions of your ActiveRecord models' data.
|
137
|
+
description: Create draft versions of your ActiveRecord models' data. Works with Ruby
|
138
|
+
on Rails and Sinatra.
|
138
139
|
email: chris@minimalorange.com
|
139
140
|
executables: []
|
140
141
|
extensions: []
|
141
142
|
extra_rdoc_files: []
|
142
143
|
files:
|
143
|
-
- .gitignore
|
144
|
-
- .rspec
|
145
|
-
- .ruby-gemset
|
146
|
-
- .ruby-version
|
144
|
+
- ".gitignore"
|
145
|
+
- ".rspec"
|
146
|
+
- ".ruby-gemset"
|
147
|
+
- ".ruby-version"
|
147
148
|
- CHANGELOG.md
|
148
149
|
- Gemfile
|
149
150
|
- Gemfile.lock
|
@@ -222,7 +223,7 @@ files:
|
|
222
223
|
- spec/models/vanilla_spec.rb
|
223
224
|
- spec/models/whitelister_spec.rb
|
224
225
|
- spec/spec_helper.rb
|
225
|
-
homepage: https://github.com/
|
226
|
+
homepage: https://github.com/live-editor/draftsman
|
226
227
|
licenses:
|
227
228
|
- MIT
|
228
229
|
metadata: {}
|
@@ -232,20 +233,21 @@ require_paths:
|
|
232
233
|
- lib
|
233
234
|
required_ruby_version: !ruby/object:Gem::Requirement
|
234
235
|
requirements:
|
235
|
-
- -
|
236
|
+
- - ">="
|
236
237
|
- !ruby/object:Gem::Version
|
237
238
|
version: '0'
|
238
239
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
240
|
requirements:
|
240
|
-
- -
|
241
|
+
- - ">="
|
241
242
|
- !ruby/object:Gem::Version
|
242
243
|
version: '0'
|
243
244
|
requirements: []
|
244
245
|
rubyforge_project:
|
245
|
-
rubygems_version: 2.
|
246
|
+
rubygems_version: 2.2.2
|
246
247
|
signing_key:
|
247
248
|
specification_version: 4
|
248
|
-
summary: Create draft versions of your ActiveRecord models' data.
|
249
|
+
summary: Create draft versions of your ActiveRecord models' data. Works with Ruby
|
250
|
+
on Rails and Sinatra.
|
249
251
|
test_files:
|
250
252
|
- spec/controllers/informants_controller_spec.rb
|
251
253
|
- spec/controllers/users_controller_spec.rb
|