archivable 0.0.3 → 1.0.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 +5 -4
- data/LICENSE.txt +1 -1
- data/README.md +93 -6
- data/lib/archivable/version.rb +1 -1
- data/spec/archivable_controller_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -4
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fc7307d09a886e09d22380e036677cde86d644b
|
4
|
+
data.tar.gz: 96fea8d4bf70912f24cdb699ffd51af2d7541b11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ae7cebf05e9fda03dd208fddadd4b399d54392e33a742fcea648b83867367d4c0bc1d22142693166ed4593e127d329ec6f66bffa5277842627281d0caac2d91
|
7
|
+
data.tar.gz: 474d8a2c42be8be8a7b78cc547fc55fffdace91f486f8e8bcc01fb2de1443240cb41448e9862a4dbb0fd16e456a6dbabaf902c4ecf2933b88b4e57dcfcc2c5c5
|
data/.travis.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,27 +2,114 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/johnotander/archivable.svg?branch=master)](https://travis-ci.org/johnotander/archivable)
|
4
4
|
|
5
|
-
|
5
|
+
Archive your Rails models rather than delete them. This provides the archiving functionality app so you can do the following:
|
6
6
|
|
7
|
-
|
7
|
+
##### In your models:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
user.archived? #=> false
|
11
|
+
user.archive! #=> true
|
12
|
+
user.archived? #=> true
|
13
|
+
user.unarchive! #=> true
|
14
|
+
user.archived? #=> false
|
15
|
+
|
16
|
+
# With scopes available:
|
17
|
+
User.archived
|
18
|
+
User.unarchived
|
19
|
+
```
|
20
|
+
|
21
|
+
##### In your views:
|
22
|
+
|
23
|
+
_This would typically be added to a view helper._
|
24
|
+
|
25
|
+
```html+erb
|
26
|
+
<% if user.archived? %>
|
27
|
+
<%= link_to :Archive, archive_user_path(user) %>
|
28
|
+
<% else %>
|
29
|
+
<%= link_to :Unarchive, archive_user_path(user) %>
|
30
|
+
<% end %>
|
31
|
+
```
|
8
32
|
|
9
33
|
## Installation
|
10
34
|
|
11
35
|
Add this line to your application's Gemfile:
|
12
36
|
|
13
|
-
|
37
|
+
```ruby
|
38
|
+
gem 'archivable'
|
39
|
+
```
|
14
40
|
|
15
41
|
And then execute:
|
16
42
|
|
17
|
-
|
43
|
+
```
|
44
|
+
$ bundle
|
45
|
+
```
|
18
46
|
|
19
47
|
Or install it yourself as:
|
20
48
|
|
21
|
-
|
49
|
+
```
|
50
|
+
$ gem install archivable
|
51
|
+
```
|
22
52
|
|
23
53
|
## Usage
|
24
54
|
|
25
|
-
|
55
|
+
### Database Migration
|
56
|
+
|
57
|
+
First, you need to add the `archived` column to your model (which we we call `User` for this example):
|
58
|
+
|
59
|
+
```
|
60
|
+
$ rails g migration add_archived_to_users archived:boolean
|
61
|
+
$ rake db:migrate
|
62
|
+
```
|
63
|
+
|
64
|
+
### Application Routes
|
65
|
+
|
66
|
+
In your routes file (`config/routes.rb`):
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
My::Application.routes.draw do
|
70
|
+
resources :users do
|
71
|
+
get archive, on: :member
|
72
|
+
get archived, on: :collection
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
### The Model
|
78
|
+
|
79
|
+
Next, you need to include the model concern to gain access to some handy methods.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class User < ActiveRecord::Base
|
83
|
+
include Archivable::Model
|
84
|
+
|
85
|
+
# ...
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
### The Controller
|
90
|
+
|
91
|
+
Lastly, you need to include the controller concern to handle the controller actions.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class UsersController < ApplicationController
|
95
|
+
include Archivable::Controller
|
96
|
+
|
97
|
+
def index
|
98
|
+
@users = User.where(archived: false)
|
99
|
+
end
|
100
|
+
|
101
|
+
# ...
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
### That's it.
|
106
|
+
|
107
|
+
Now, instead of a delete link, you can do the following:
|
108
|
+
|
109
|
+
```html+erb
|
110
|
+
<%= link_to user.archived? ? :Unarchive : :Archive, archive_user_path(user) %>
|
111
|
+
<%= link_to 'See Archived Users', archived_users_path %>
|
112
|
+
```
|
26
113
|
|
27
114
|
## Contributing
|
28
115
|
|
data/lib/archivable/version.rb
CHANGED
@@ -12,7 +12,7 @@ describe Archivable::Controller do
|
|
12
12
|
|
13
13
|
it 'should set the instance variable' do
|
14
14
|
subject.archive
|
15
|
-
|
15
|
+
expect.get_model_instance_variable).to eq(subject.fake)
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'when successfully archived' do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: archivable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Otander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
requirements: []
|
138
138
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.4.5
|
140
140
|
signing_key:
|
141
141
|
specification_version: 4
|
142
142
|
summary: Archive your Rails models rather than delete them.
|
@@ -144,4 +144,3 @@ test_files:
|
|
144
144
|
- spec/archivable_controller_spec.rb
|
145
145
|
- spec/archivable_model_spec.rb
|
146
146
|
- spec/spec_helper.rb
|
147
|
-
has_rdoc:
|