sweet_actions 0.1.5 → 0.2.1
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/.DS_Store +0 -0
- data/README.md +216 -175
- data/lib/generators/sweet_actions/templates/base_action.rb +4 -0
- data/lib/generators/sweet_actions/templates/collect_action.rb +7 -8
- data/lib/generators/sweet_actions/templates/create_action.rb +10 -11
- data/lib/generators/sweet_actions/templates/destroy_action.rb +10 -11
- data/lib/generators/sweet_actions/templates/show_action.rb +7 -8
- data/lib/generators/sweet_actions/templates/update_action.rb +11 -12
- data/lib/sweet_actions/.DS_Store +0 -0
- data/lib/sweet_actions/action.rb +32 -0
- data/lib/sweet_actions/action_factory.rb +4 -2
- data/lib/sweet_actions/{authorization_concerns.rb → authorization.rb} +2 -2
- data/lib/sweet_actions/controller_concerns.rb +0 -1
- data/lib/sweet_actions/exceptions.rb +13 -0
- data/lib/sweet_actions/json/.DS_Store +0 -0
- data/lib/sweet_actions/json/base_action.rb +41 -0
- data/lib/sweet_actions/json/collect_action.rb +13 -0
- data/lib/sweet_actions/json/create_action.rb +18 -0
- data/lib/sweet_actions/json/destroy_action.rb +13 -0
- data/lib/sweet_actions/json/show_action.rb +13 -0
- data/lib/sweet_actions/json/update_action.rb +18 -0
- data/lib/sweet_actions/{rest_concerns.rb → resource.rb} +3 -5
- data/lib/sweet_actions/rest/.DS_Store +0 -0
- data/lib/sweet_actions/rest/base.rb +8 -0
- data/lib/sweet_actions/rest/collect.rb +14 -0
- data/lib/sweet_actions/rest/create.rb +14 -0
- data/lib/sweet_actions/rest/destroy.rb +25 -0
- data/lib/sweet_actions/rest/find.rb +13 -0
- data/lib/sweet_actions/rest/multiple.rb +9 -0
- data/lib/sweet_actions/rest/read.rb +19 -0
- data/lib/sweet_actions/rest/save.rb +54 -0
- data/lib/sweet_actions/rest/show.rb +8 -0
- data/lib/sweet_actions/rest/singular.rb +9 -0
- data/lib/sweet_actions/rest/update.rb +15 -0
- data/lib/sweet_actions/{rest_serializer_concerns.rb → serialize.rb} +12 -3
- data/lib/sweet_actions/version.rb +1 -1
- data/lib/sweet_actions.rb +27 -13
- data/sweet_actions.gemspec +3 -0
- metadata +55 -14
- data/lib/generators/rails/resource_override.rb +0 -10
- data/lib/sweet_actions/api_action.rb +0 -63
- data/lib/sweet_actions/collect_action.rb +0 -11
- data/lib/sweet_actions/create_action.rb +0 -10
- data/lib/sweet_actions/destroy_action.rb +0 -19
- data/lib/sweet_actions/read_concerns.rb +0 -14
- data/lib/sweet_actions/save_concerns.rb +0 -51
- data/lib/sweet_actions/show_action.rb +0 -9
- data/lib/sweet_actions/update_action.rb +0 -11
@@ -1,19 +0,0 @@
|
|
1
|
-
module SweetActions
|
2
|
-
class DestroyAction < ApiAction
|
3
|
-
include RestConcerns
|
4
|
-
include AuthorizationConcerns
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def action
|
9
|
-
@resource = set_resource
|
10
|
-
authorize
|
11
|
-
destroy
|
12
|
-
serialize
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy
|
16
|
-
raise "destroy method must be implemented in #{self.class.name} class since it inherits from DestroyAction"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module SweetActions
|
2
|
-
module SaveConcerns
|
3
|
-
include AuthorizationConcerns
|
4
|
-
|
5
|
-
def action
|
6
|
-
@resource = set_resource
|
7
|
-
authorize
|
8
|
-
validate_and_save ? success : failure
|
9
|
-
end
|
10
|
-
|
11
|
-
def root_key
|
12
|
-
singular_key
|
13
|
-
end
|
14
|
-
|
15
|
-
def validate_and_save
|
16
|
-
valid? && save
|
17
|
-
end
|
18
|
-
|
19
|
-
def valid?
|
20
|
-
true
|
21
|
-
end
|
22
|
-
|
23
|
-
def save
|
24
|
-
raise "save method must be implemented by #{self.class.name} since it includes SaveConcerns"
|
25
|
-
end
|
26
|
-
|
27
|
-
def success
|
28
|
-
after_save
|
29
|
-
serialize
|
30
|
-
end
|
31
|
-
|
32
|
-
def failure
|
33
|
-
after_fail
|
34
|
-
@response_code = '422'
|
35
|
-
serialize_errors
|
36
|
-
end
|
37
|
-
|
38
|
-
def after_save
|
39
|
-
# hook
|
40
|
-
end
|
41
|
-
|
42
|
-
def after_fail
|
43
|
-
# hook
|
44
|
-
end
|
45
|
-
|
46
|
-
def map_base_to__error(error_obj)
|
47
|
-
error_obj[:_error] = error_obj.delete(:base) if error_obj.key? :base
|
48
|
-
error_obj
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|