approval 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bbb99b387759960e99f78286cc1e23713392670
4
- data.tar.gz: 2c9336adf5bf81c8380bc16e1fc987c9ff824fa3
3
+ metadata.gz: b11eef9bb8afb6a55fefa35bc8fef5132d1908d0
4
+ data.tar.gz: 628a25ca361506832c1c709902af993c18c43d59
5
5
  SHA512:
6
- metadata.gz: 1f7720b2a2b2f001e97f0c4cc9947966e3e0cd71df41f102fd582694962fb96ce81444ea76178ba0efb5190e2342002d604f23419daf45bc12cb1b1cbd0bc654
7
- data.tar.gz: 8e3688f967f8686bcfe0878dd0de519f8aeb356f7d9de6abcd098670ca0f6bed3da23bac3d9a15842dbe07eb5d3d30264e8d1a98b6bb420d931dbfad1e552363
6
+ metadata.gz: e0a6c2f36e2234bc1c3612f8e6b27886bba1c0bf801ead75bd82c95f8e755ba588641d2107a936b28e5d275ea0d450f2850ebf2e49af7748548769c7b62bc300
7
+ data.tar.gz: 0bbd75b3e3e5dbdbbd7fa22e3dc4837134f19e895867293c51a99d0371e03044918e371d91a05e7b1fd4115c559f4a1267da90a54c64076fa5066b5646909a73
data/README.md CHANGED
@@ -3,61 +3,138 @@
3
3
  [![Build Status](https://travis-ci.org/yhirano55/approval.svg?branch=master)](https://travis-ci.org/yhirano55/approval)
4
4
  [![Gem Version](https://badge.fury.io/rb/approval.svg)](https://badge.fury.io/rb/approval)
5
5
 
6
- :ok_woman::no_good:Approval workflow for Rails
6
+ :ok_woman::no_good:Approval flow for Rails
7
7
 
8
8
  ## Installation
9
9
 
10
- ```ruby
11
- gem 'approval'
12
- ```
10
+ 1. Add approval to your `Gemfile`:
13
11
 
14
- Optionally, you can run the generator, which will set up approval models with some useful defaults for you:
12
+ ```ruby
13
+ gem 'approval'
14
+ ```
15
15
 
16
- ```bash
17
- $ bin/rails g approval:install
18
- ```
16
+ 2. Add approval_requests, approval_comments, approval_items tables to your database and an initializer file for configuration:
17
+
18
+ ```bash
19
+ $ bundle exec rails generate approval:install
20
+ ```
21
+
22
+ 3. Add `acts_as_approval_user` to your user model (`User`, `AdminUser`, `Member` ...etc)::
23
+
24
+ ```ruby
25
+ class User < ApplicationRecord
26
+ acts_as_approval_user
27
+ end
28
+ ```
29
+
30
+ 4. Add `acts_as_approval_resource` to the models you want use approval flow:
19
31
 
20
- ## Usage
32
+ ```ruby
33
+ class Post < ApplicationRecord
34
+ acts_as_approval_resource
35
+ end
36
+ ```
21
37
 
22
- ### Prepare
38
+ ## Approval Flow
23
39
 
24
- Call `acts_as_approval_user` in your resource of user model (`User`, `AdminUser`, `Member` etc):
40
+ ### Make request
41
+
42
+ You send request, but resources aren't created/updated/destroied.
43
+
44
+ #### :pray: Create
25
45
 
26
46
  ```ruby
27
- class User < ApplicationRecord
28
- acts_as_approval_user
29
- end
47
+ staff = User.find_or_create_by(email: "staff@example.com")
48
+
49
+ record = Book.new(name: "Ruby Way", price: 2980)
50
+ request = staff.request_for_create(record, reason: "something")
51
+ request.save # Created Approval::Request record.
52
+
53
+ records = 10.times.map {|n| Book.new(name: "my_book_#{n}", price: 300) }
54
+ request = staff.request_for_create(records, reason: "something")
55
+ request.save!
30
56
  ```
31
57
 
32
- Call `acts_as_approval_resource` in your resource:
58
+ #### :pray: Update
33
59
 
34
60
  ```ruby
35
- class Book < ApplicationRecord
36
- acts_as_approval_resource
37
- end
61
+ staff = User.find_or_create_by(email: "staff@example.com")
62
+
63
+ record = Book.find(1).tap {|record| record.name = "new book title" }
64
+ request = staff.request_for_update(record, reason: "something")
65
+ request.save
66
+
67
+ records = Book.where(id: 1, 2, 3).map {|record| record.price *= 0.5 }
68
+ request = staff.request_for_update(records, reason: "something")
69
+ request.save!
38
70
  ```
39
71
 
40
- ### Request
72
+ #### :pray: Destroy
41
73
 
42
74
  ```ruby
43
75
  staff = User.find_or_create_by(email: "staff@example.com")
44
- book = 10.times.map { |n| Book.new(name: "my_book_#{n}") }
45
- request = staff.request_for_create(records, reason: "something")
76
+
77
+ record = Book.find(1)
78
+ request = staff.request_for_destroy(record, reason: "something")
79
+ request.save
80
+
81
+ records = Book.where(id: 1, 2, 3)
82
+ request = staff.request_for_destroy(records, reason: "something")
46
83
  request.save!
47
84
  ```
48
85
 
49
- You send request, but resources aren't created.
50
-
51
86
  ### Respond
52
87
 
88
+ #### :ok_woman: Approve
89
+
90
+ Then resources are created/updated/destroied, if respond user have approved the request.
91
+
53
92
  ```ruby
54
93
  admin = User.find_or_create_by(email: "admin@example.com")
94
+
55
95
  request = Approval::Request.first
56
96
  respond = admin.approve_request(request, reason: "something")
97
+ respond.save! # Create/Update/Destroy resources
98
+ ```
99
+
100
+ ##### :no_good: Reject
101
+
102
+ Then resources are not created/updated/destroied, if respond user have rejected the request.
103
+
104
+ ```ruby
105
+ admin = User.find_or_create_by(email: "admin@example.com")
106
+
107
+ request = Approval::Request.first
108
+ respond = admin.reject_request(request, reason: "something")
109
+ respond.save!
110
+ ```
111
+
112
+ ##### :wastebasket: Cancel
113
+
114
+ ```ruby
115
+ staff = User.find_or_create_by(email: "staff@example.com")
116
+
117
+ request = Approval::Request.first
118
+ respond = staff.cancel_request(request, reason: "something")
57
119
  respond.save!
58
120
  ```
59
121
 
60
- Then resources are created, if respond user have approved the request.
122
+ ### Configuration
123
+
124
+ ```ruby
125
+ # config/initializers/approval.rb
126
+
127
+ Approval.configure do |config|
128
+ # Your user model name (e.g. User, AdminUser, Member, default: User)
129
+ config.user_class_name = "User"
130
+
131
+ # Maximum characters of comment for reason (default: 2000)
132
+ config.comment_maximum = 2000
133
+
134
+ # Permit to respond to own request? (default: false)
135
+ config.permit_to_respond_to_own_request = false
136
+ end
137
+ ```
61
138
 
62
139
  ## License
63
140
 
@@ -1,3 +1,3 @@
1
1
  module Approval
2
- VERSION = "0.2.2".freeze
2
+ VERSION = "0.2.3".freeze
3
3
  end
@@ -1,4 +1,10 @@
1
1
  Approval.configure do |config|
2
+ # Your user model name (e.g. User, AdminUser, Member, default: User)
2
3
  config.user_class_name = "User"
4
+
5
+ # Maximum characters of comment for reason (default: 2000)
3
6
  config.comment_maximum = 2000
7
+
8
+ # Permit to respond to own request? (default: false)
9
+ config.permit_to_respond_to_own_request = false
4
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: approval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Hirano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-31 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.15'
27
- description: Approval workflow for Rails
27
+ description: Approval flow for Rails
28
28
  email:
29
29
  - yhirano@me.com
30
30
  executables: []
@@ -101,7 +101,7 @@ rubyforge_project:
101
101
  rubygems_version: 2.6.10
102
102
  signing_key:
103
103
  specification_version: 4
104
- summary: Approval workflow for Rails
104
+ summary: Approval flow for Rails
105
105
  test_files:
106
106
  - spec/lib/config_spec.rb
107
107
  - spec/lib/version_spec.rb