snfoil 0.8.4 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +201 -0
- data/README.md +95 -505
- data/docs/build-context.md +56 -0
- data/docs/create-context.md +109 -0
- data/docs/destroy-context.md +102 -0
- data/docs/index-context.md +70 -0
- data/docs/show-context.md +71 -0
- data/docs/update-context.md +107 -0
- data/lib/{sn_foil → snfoil}/adapters/orms/active_record.rb +14 -0
- data/lib/{sn_foil → snfoil}/adapters/orms/base_adapter.rb +14 -0
- data/lib/snfoil/crud/build_context.rb +49 -0
- data/lib/snfoil/crud/change_context.rb +48 -0
- data/lib/snfoil/crud/context.rb +41 -0
- data/lib/snfoil/crud/create_context.rb +45 -0
- data/lib/snfoil/crud/destroy_context.rb +57 -0
- data/lib/snfoil/crud/index_context.rb +46 -0
- data/lib/snfoil/crud/setup_context.rb +90 -0
- data/lib/snfoil/crud/show_context.rb +52 -0
- data/lib/snfoil/crud/update_context.rb +60 -0
- data/lib/snfoil/version.rb +19 -0
- data/lib/snfoil.rb +69 -0
- data/snfoil.gemspec +47 -0
- metadata +124 -39
- data/Rakefile +0 -4
- data/lib/sn_foil/context.rb +0 -24
- data/lib/sn_foil/contexts/build_context.rb +0 -68
- data/lib/sn_foil/contexts/change_context.rb +0 -101
- data/lib/sn_foil/contexts/create_context.rb +0 -158
- data/lib/sn_foil/contexts/destroy_context.rb +0 -165
- data/lib/sn_foil/contexts/index_context.rb +0 -64
- data/lib/sn_foil/contexts/setup_context.rb +0 -120
- data/lib/sn_foil/contexts/show_context.rb +0 -62
- data/lib/sn_foil/contexts/update_context.rb +0 -169
- data/lib/sn_foil/policy.rb +0 -55
- data/lib/sn_foil/searcher.rb +0 -123
- data/lib/sn_foil/version.rb +0 -5
- data/lib/sn_foil.rb +0 -49
@@ -0,0 +1,56 @@
|
|
1
|
+
# Build Context
|
2
|
+
|
3
|
+
Build is meant to setup an object, but not to actually save it (that is handled by Create).
|
4
|
+
|
5
|
+
Build does the following:
|
6
|
+
|
7
|
+
- Creates a new model object
|
8
|
+
- Assigns Attributes
|
9
|
+
|
10
|
+
Since build's usage is pretty straight forward it only adds a single interval for you to hook into.
|
11
|
+
|
12
|
+
##### Example
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
class PeopleContext
|
16
|
+
include SnFoil::CRUD::BuildContext
|
17
|
+
|
18
|
+
model Person
|
19
|
+
end
|
20
|
+
```
|
21
|
+
### Required Class Definitions
|
22
|
+
- Model
|
23
|
+
|
24
|
+
### Primary Action
|
25
|
+
Does nothing
|
26
|
+
### Intervals (in order)
|
27
|
+
|
28
|
+
<table>
|
29
|
+
<thead>
|
30
|
+
<th>name</th>
|
31
|
+
<th>description</th>
|
32
|
+
<th>pre-defined functions</th>
|
33
|
+
</thead>
|
34
|
+
|
35
|
+
<tbody>
|
36
|
+
<tr>
|
37
|
+
<td>setup</td>
|
38
|
+
<td>Shared by all CRUD actions</td>
|
39
|
+
<td></td>
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
<td>setup_build</td>
|
43
|
+
<td>Shared by Build and Create actions</td>
|
44
|
+
<td>
|
45
|
+
Creates a new model object, Assigns Attributes
|
46
|
+
</td>
|
47
|
+
</tr>
|
48
|
+
</tbody>
|
49
|
+
</table>
|
50
|
+
|
51
|
+
### ORM Adapter Requirements
|
52
|
+
|
53
|
+
The following methods must be defined on the ORM adapter to use the build context
|
54
|
+
|
55
|
+
- `new`
|
56
|
+
- `attributes=`
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Create Context
|
2
|
+
|
3
|
+
Create sets up an object using the build functionality, and then attempts to save it to the data source.
|
4
|
+
|
5
|
+
Create does the following:
|
6
|
+
|
7
|
+
- Creates a new model
|
8
|
+
- Assigns attributes
|
9
|
+
- Saves Object
|
10
|
+
|
11
|
+
##### Example
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class PeopleContext
|
15
|
+
include SnFoil::CRUD::CreateContext
|
16
|
+
|
17
|
+
policy PersonPolicy
|
18
|
+
model Person
|
19
|
+
end
|
20
|
+
```
|
21
|
+
#### Required Class Definitions
|
22
|
+
|
23
|
+
- Policy
|
24
|
+
- Model
|
25
|
+
|
26
|
+
### Primary Action
|
27
|
+
Saves the model.
|
28
|
+
### Intervals (in order)
|
29
|
+
|
30
|
+
<table>
|
31
|
+
<thead>
|
32
|
+
<th>name</th>
|
33
|
+
<th>description</th>
|
34
|
+
<th>pre-defined functions</th>
|
35
|
+
</thead>
|
36
|
+
|
37
|
+
<tbody>
|
38
|
+
<tr>
|
39
|
+
<td>setup</td>
|
40
|
+
<td>Shared by all CRUD actions</td>
|
41
|
+
<td></td>
|
42
|
+
</tr>
|
43
|
+
<tr>
|
44
|
+
<td>setup_build</td>
|
45
|
+
<td>Shared by Build and Create actions</td>
|
46
|
+
<td>
|
47
|
+
Creates a new model, Assigns attributes
|
48
|
+
</td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<td>setup_change</td>
|
52
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
53
|
+
<td></td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>setup_create</td>
|
57
|
+
<td></td>
|
58
|
+
<td></td>
|
59
|
+
</tr>
|
60
|
+
<tr>
|
61
|
+
<td>before_change</td>
|
62
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
63
|
+
<td></td>
|
64
|
+
</tr>
|
65
|
+
<tr>
|
66
|
+
<td>before_create</td>
|
67
|
+
<td></td>
|
68
|
+
<td></td>
|
69
|
+
</tr>
|
70
|
+
<tr>
|
71
|
+
<td>after_change_success</td>
|
72
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
73
|
+
<td></td>
|
74
|
+
</tr>
|
75
|
+
<tr>
|
76
|
+
<td>after_create_success</td>
|
77
|
+
<td></td>
|
78
|
+
<td></td>
|
79
|
+
</tr>
|
80
|
+
<tr>
|
81
|
+
<td>after_change_failure</td>
|
82
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
83
|
+
<td></td>
|
84
|
+
</tr>
|
85
|
+
<tr>
|
86
|
+
<td>after_create_failure</td>
|
87
|
+
<td></td>
|
88
|
+
<td></td>
|
89
|
+
</tr>
|
90
|
+
<tr>
|
91
|
+
<td>after_change</td>
|
92
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
93
|
+
<td></td>
|
94
|
+
</tr>
|
95
|
+
<tr>
|
96
|
+
<td>after_create</td>
|
97
|
+
<td></td>
|
98
|
+
<td></td>
|
99
|
+
</tr>
|
100
|
+
</tbody>
|
101
|
+
</table>
|
102
|
+
|
103
|
+
### ORM Adapter Requirements
|
104
|
+
|
105
|
+
The following methods must be defined on the ORM adapter to use the create context
|
106
|
+
|
107
|
+
- `new`
|
108
|
+
- `attributes=`
|
109
|
+
- `save`
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# Destroy Context
|
2
|
+
|
3
|
+
Destroy sets up an object using the build functionality, and then attempts to save it to the data source.
|
4
|
+
|
5
|
+
Destroy does the following:
|
6
|
+
|
7
|
+
- Find a model
|
8
|
+
- Destroy the model
|
9
|
+
|
10
|
+
##### Example
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
class PeopleContext
|
14
|
+
include SnFoil::CRUD::DestroyContext
|
15
|
+
|
16
|
+
searcher PeopleSearcher
|
17
|
+
policy PersonPolicy
|
18
|
+
model Person
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
### Required Class Definitions
|
23
|
+
|
24
|
+
- Searcher
|
25
|
+
- Policy
|
26
|
+
- Model
|
27
|
+
|
28
|
+
### Primary Action
|
29
|
+
Destroys the model.
|
30
|
+
### Intervals (in order)
|
31
|
+
|
32
|
+
<table>
|
33
|
+
<thead>
|
34
|
+
<th>name</th>
|
35
|
+
<th>description</th>
|
36
|
+
<th>pre-defined functions</th>
|
37
|
+
</thead>
|
38
|
+
|
39
|
+
<tbody>
|
40
|
+
<tr>
|
41
|
+
<td>setup</td>
|
42
|
+
<td>Shared by all CRUD actions</td>
|
43
|
+
<td></td>
|
44
|
+
</tr>
|
45
|
+
<tr>
|
46
|
+
<td>setup_change</td>
|
47
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
48
|
+
<td></td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<td>setup_destroy</td>
|
52
|
+
<td></td>
|
53
|
+
<td>Finds the model</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>before_change</td>
|
57
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
58
|
+
<td></td>
|
59
|
+
</tr>
|
60
|
+
<tr>
|
61
|
+
<td>before_destroy</td>
|
62
|
+
<td></td>
|
63
|
+
<td></td>
|
64
|
+
</tr>
|
65
|
+
<tr>
|
66
|
+
<td>after_change_success</td>
|
67
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
68
|
+
<td></td>
|
69
|
+
</tr>
|
70
|
+
<tr>
|
71
|
+
<td>after_destroy_success</td>
|
72
|
+
<td></td>
|
73
|
+
<td></td>
|
74
|
+
</tr>
|
75
|
+
<tr>
|
76
|
+
<td>after_change_failure</td>
|
77
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
78
|
+
<td></td>
|
79
|
+
</tr>
|
80
|
+
<tr>
|
81
|
+
<td>after_destroy_failure</td>
|
82
|
+
<td></td>
|
83
|
+
<td></td>
|
84
|
+
</tr>
|
85
|
+
<tr>
|
86
|
+
<td>after_change</td>
|
87
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
88
|
+
<td></td>
|
89
|
+
</tr>
|
90
|
+
<tr>
|
91
|
+
<td>after_destroy</td>
|
92
|
+
<td></td>
|
93
|
+
<td></td>
|
94
|
+
</tr>
|
95
|
+
</tbody>
|
96
|
+
</table>
|
97
|
+
|
98
|
+
### ORM Adapter Requirements
|
99
|
+
|
100
|
+
The following methods must be defined on the ORM adapter to use the destroy context
|
101
|
+
|
102
|
+
- `destroy`
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Index Context
|
2
|
+
|
3
|
+
Index sets up an object using the build functionality, and then attempts to save it to the data source.
|
4
|
+
|
5
|
+
Index does the following:
|
6
|
+
|
7
|
+
- Queries for models
|
8
|
+
|
9
|
+
##### Example
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class PeopleContext
|
13
|
+
include SnFoil::CRUD::IndexContext
|
14
|
+
|
15
|
+
searcher PeopleSearcher
|
16
|
+
policy PersonPolicy
|
17
|
+
model Person
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
### Required Class Definitions
|
22
|
+
|
23
|
+
- Searcher
|
24
|
+
- Policy
|
25
|
+
- Model
|
26
|
+
|
27
|
+
### Primary Action
|
28
|
+
Does nothing
|
29
|
+
### Intervals (in order)
|
30
|
+
|
31
|
+
<table>
|
32
|
+
<thead>
|
33
|
+
<th>name</th>
|
34
|
+
<th>description</th>
|
35
|
+
<th>pre-defined functions</th>
|
36
|
+
</thead>
|
37
|
+
|
38
|
+
<tbody>
|
39
|
+
<tr>
|
40
|
+
<td>setup</td>
|
41
|
+
<td>Shared by all CRUD actions</td>
|
42
|
+
<td></td>
|
43
|
+
</tr>
|
44
|
+
<tr>
|
45
|
+
<td>setup_index</td>
|
46
|
+
<td></td>
|
47
|
+
<td></td>
|
48
|
+
</tr>
|
49
|
+
<tr>
|
50
|
+
<td>before_index</td>
|
51
|
+
<td></td>
|
52
|
+
<td>Queries for models</td>
|
53
|
+
</tr>
|
54
|
+
<tr>
|
55
|
+
<td>after_index_success</td>
|
56
|
+
<td></td>
|
57
|
+
<td></td>
|
58
|
+
</tr>
|
59
|
+
<tr>
|
60
|
+
<td>after_index_failure</td>
|
61
|
+
<td></td>
|
62
|
+
<td></td>
|
63
|
+
</tr>
|
64
|
+
<tr>
|
65
|
+
<td>after_index</td>
|
66
|
+
<td></td>
|
67
|
+
<td></td>
|
68
|
+
</tr>
|
69
|
+
</tbody>
|
70
|
+
</table>
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Show Context
|
2
|
+
|
3
|
+
Show sets up an object using the build functionality, and then attempts to save it to the data source.
|
4
|
+
|
5
|
+
Show does the following:
|
6
|
+
|
7
|
+
- Finds the model
|
8
|
+
|
9
|
+
##### Example
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
class PeopleContext
|
13
|
+
include SnFoil::CRUD::ShowContext
|
14
|
+
|
15
|
+
searcher PeopleSearcher
|
16
|
+
policy PersonPolicy
|
17
|
+
model Person
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
### Required Class Definitions
|
22
|
+
|
23
|
+
- Searcher
|
24
|
+
- Policy
|
25
|
+
- Model
|
26
|
+
|
27
|
+
### Primary Action
|
28
|
+
Does nothing
|
29
|
+
|
30
|
+
### Intervals (in order)
|
31
|
+
|
32
|
+
<table>
|
33
|
+
<thead>
|
34
|
+
<th>name</th>
|
35
|
+
<th>description</th>
|
36
|
+
<th>pre-defined functions</th>
|
37
|
+
</thead>
|
38
|
+
|
39
|
+
<tbody>
|
40
|
+
<tr>
|
41
|
+
<td>setup</td>
|
42
|
+
<td></td>
|
43
|
+
<td></td>
|
44
|
+
</tr>
|
45
|
+
<tr>
|
46
|
+
<td>setup_show</td>
|
47
|
+
<td>Shared by all CRUD actions</td>
|
48
|
+
<td></td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<td>before_show</td>
|
52
|
+
<td></td>
|
53
|
+
<td>Finds the model</td>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>after_show_success</td>
|
57
|
+
<td></td>
|
58
|
+
<td></td>
|
59
|
+
</tr>
|
60
|
+
<tr>
|
61
|
+
<td>after_show_failure</td>
|
62
|
+
<td></td>
|
63
|
+
<td></td>
|
64
|
+
</tr>
|
65
|
+
<tr>
|
66
|
+
<td>after_show</td>
|
67
|
+
<td></td>
|
68
|
+
<td></td>
|
69
|
+
</tr>
|
70
|
+
</tbody>
|
71
|
+
</table>
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Update Context
|
2
|
+
|
3
|
+
Update sets up an object using the build functionality, and then attempts to save it to the data source.
|
4
|
+
|
5
|
+
Update does the following:
|
6
|
+
|
7
|
+
- Find a model
|
8
|
+
- Assigns attributes
|
9
|
+
- Saves object
|
10
|
+
|
11
|
+
##### Example
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class PeopleContext
|
15
|
+
include SnFoil::CRUD::UpdateContext
|
16
|
+
|
17
|
+
searcher PeopleSearcher
|
18
|
+
policy PersonPolicy
|
19
|
+
model Person
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
### Required Class Definitions
|
24
|
+
|
25
|
+
- Searcher
|
26
|
+
- Policy
|
27
|
+
- Model
|
28
|
+
|
29
|
+
### Primary Action
|
30
|
+
Saves the model
|
31
|
+
|
32
|
+
### Intervals (in order)
|
33
|
+
|
34
|
+
<table>
|
35
|
+
<thead>
|
36
|
+
<th>name</th>
|
37
|
+
<th>description</th>
|
38
|
+
<th>pre-defined functions</th>
|
39
|
+
</thead>
|
40
|
+
|
41
|
+
<tbody>
|
42
|
+
<tr>
|
43
|
+
<td>setup</td>
|
44
|
+
<td>Shared by all CRUD actions</td>
|
45
|
+
<td></td>
|
46
|
+
</tr>
|
47
|
+
<tr>
|
48
|
+
<td>setup_change</td>
|
49
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
50
|
+
<td></td>
|
51
|
+
</tr>
|
52
|
+
<tr>
|
53
|
+
<td>setup_update</td>
|
54
|
+
<td></td>
|
55
|
+
<td>
|
56
|
+
Finds the model, Assigns attributes
|
57
|
+
</td>
|
58
|
+
</tr>
|
59
|
+
<tr>
|
60
|
+
<td>before_change</td>
|
61
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
62
|
+
<td></td>
|
63
|
+
</tr>
|
64
|
+
<tr>
|
65
|
+
<td>before_update</td>
|
66
|
+
<td></td>
|
67
|
+
<td></td>
|
68
|
+
</tr>
|
69
|
+
<tr>
|
70
|
+
<td>after_change_success</td>
|
71
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
72
|
+
<td></td>
|
73
|
+
</tr>
|
74
|
+
<tr>
|
75
|
+
<td>after_update_success</td>
|
76
|
+
<td></td>
|
77
|
+
<td></td>
|
78
|
+
</tr>
|
79
|
+
<tr>
|
80
|
+
<td>after_change_failure</td>
|
81
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
82
|
+
<td></td>
|
83
|
+
</tr>
|
84
|
+
<tr>
|
85
|
+
<td>after_update_failure</td>
|
86
|
+
<td></td>
|
87
|
+
<td></td>
|
88
|
+
</tr>
|
89
|
+
<tr>
|
90
|
+
<td>after_change</td>
|
91
|
+
<td>Shared by Create, Update, and Destroy actions</td>
|
92
|
+
<td></td>
|
93
|
+
</tr>
|
94
|
+
<tr>
|
95
|
+
<td>after_update</td>
|
96
|
+
<td></td>
|
97
|
+
<td></td>
|
98
|
+
</tr>
|
99
|
+
</tbody>
|
100
|
+
</table>
|
101
|
+
|
102
|
+
### ORM Adapter Requirements
|
103
|
+
|
104
|
+
The following methods must be defined on the ORM adapter to use the update context
|
105
|
+
|
106
|
+
- `attributes=`
|
107
|
+
- `save`
|
@@ -1,5 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Copyright 2021 Matthew Howes
|
4
|
+
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
3
17
|
require_relative 'base_adapter'
|
4
18
|
|
5
19
|
module SnFoil
|
@@ -1,5 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Copyright 2021 Matthew Howes
|
4
|
+
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
3
17
|
require 'delegate'
|
4
18
|
|
5
19
|
module SnFoil
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2021 Matthew Howes
|
4
|
+
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'active_support/concern'
|
18
|
+
require 'snfoil/context'
|
19
|
+
require_relative './setup_context'
|
20
|
+
|
21
|
+
module SnFoil
|
22
|
+
module CRUD
|
23
|
+
module BuildContext
|
24
|
+
extend ActiveSupport::Concern
|
25
|
+
|
26
|
+
included do
|
27
|
+
include SetupContext
|
28
|
+
|
29
|
+
interval :setup_build
|
30
|
+
|
31
|
+
setup_build do |**options|
|
32
|
+
params = options.fetch(:params) { {} }
|
33
|
+
options[:object] ||= options.fetch(:model) { model }.new
|
34
|
+
|
35
|
+
wrap_object(options[:object]).attributes = params
|
36
|
+
|
37
|
+
options
|
38
|
+
end
|
39
|
+
|
40
|
+
def build(**options)
|
41
|
+
options[:action] = :build
|
42
|
+
options = run_interval(:setup, **options)
|
43
|
+
options = run_interval(:setup_build, **options)
|
44
|
+
options[:object]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2021 Matthew Howes
|
4
|
+
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'active_support/concern'
|
18
|
+
require_relative './setup_context'
|
19
|
+
|
20
|
+
module SnFoil
|
21
|
+
module CRUD
|
22
|
+
module ChangeContext
|
23
|
+
extend ActiveSupport::Concern
|
24
|
+
|
25
|
+
included do
|
26
|
+
include SetupContext
|
27
|
+
|
28
|
+
intervals :setup_change, :before_change, :after_change, :after_change_success, :after_change_failure
|
29
|
+
|
30
|
+
setup_change do |options|
|
31
|
+
options[:pre_change_context_params] ||= options[:params]
|
32
|
+
options[:params] = options[:params].select { |params| self.class.i_params.include?(params) } if self.class.i_params
|
33
|
+
|
34
|
+
options
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class_methods do
|
39
|
+
attr_reader :i_params
|
40
|
+
|
41
|
+
def params(*permitted_params)
|
42
|
+
@i_params ||= []
|
43
|
+
@i_params |= permitted_params
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2021 Matthew Howes
|
4
|
+
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'active_support/concern'
|
18
|
+
|
19
|
+
require_relative 'build_context'
|
20
|
+
require_relative 'index_context'
|
21
|
+
require_relative 'show_context'
|
22
|
+
require_relative 'create_context'
|
23
|
+
require_relative 'update_context'
|
24
|
+
require_relative 'destroy_context'
|
25
|
+
|
26
|
+
module SnFoil
|
27
|
+
module CRUD
|
28
|
+
module Context
|
29
|
+
extend ActiveSupport::Concern
|
30
|
+
|
31
|
+
included do
|
32
|
+
include ::SnFoil::CRUD::BuildContext
|
33
|
+
include ::SnFoil::CRUD::IndexContext
|
34
|
+
include ::SnFoil::CRUD::ShowContext
|
35
|
+
include ::SnFoil::CRUD::CreateContext
|
36
|
+
include ::SnFoil::CRUD::UpdateContext
|
37
|
+
include ::SnFoil::CRUD::DestroyContext
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|