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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/README.md +216 -175
  4. data/lib/generators/sweet_actions/templates/base_action.rb +4 -0
  5. data/lib/generators/sweet_actions/templates/collect_action.rb +7 -8
  6. data/lib/generators/sweet_actions/templates/create_action.rb +10 -11
  7. data/lib/generators/sweet_actions/templates/destroy_action.rb +10 -11
  8. data/lib/generators/sweet_actions/templates/show_action.rb +7 -8
  9. data/lib/generators/sweet_actions/templates/update_action.rb +11 -12
  10. data/lib/sweet_actions/.DS_Store +0 -0
  11. data/lib/sweet_actions/action.rb +32 -0
  12. data/lib/sweet_actions/action_factory.rb +4 -2
  13. data/lib/sweet_actions/{authorization_concerns.rb → authorization.rb} +2 -2
  14. data/lib/sweet_actions/controller_concerns.rb +0 -1
  15. data/lib/sweet_actions/exceptions.rb +13 -0
  16. data/lib/sweet_actions/json/.DS_Store +0 -0
  17. data/lib/sweet_actions/json/base_action.rb +41 -0
  18. data/lib/sweet_actions/json/collect_action.rb +13 -0
  19. data/lib/sweet_actions/json/create_action.rb +18 -0
  20. data/lib/sweet_actions/json/destroy_action.rb +13 -0
  21. data/lib/sweet_actions/json/show_action.rb +13 -0
  22. data/lib/sweet_actions/json/update_action.rb +18 -0
  23. data/lib/sweet_actions/{rest_concerns.rb → resource.rb} +3 -5
  24. data/lib/sweet_actions/rest/.DS_Store +0 -0
  25. data/lib/sweet_actions/rest/base.rb +8 -0
  26. data/lib/sweet_actions/rest/collect.rb +14 -0
  27. data/lib/sweet_actions/rest/create.rb +14 -0
  28. data/lib/sweet_actions/rest/destroy.rb +25 -0
  29. data/lib/sweet_actions/rest/find.rb +13 -0
  30. data/lib/sweet_actions/rest/multiple.rb +9 -0
  31. data/lib/sweet_actions/rest/read.rb +19 -0
  32. data/lib/sweet_actions/rest/save.rb +54 -0
  33. data/lib/sweet_actions/rest/show.rb +8 -0
  34. data/lib/sweet_actions/rest/singular.rb +9 -0
  35. data/lib/sweet_actions/rest/update.rb +15 -0
  36. data/lib/sweet_actions/{rest_serializer_concerns.rb → serialize.rb} +12 -3
  37. data/lib/sweet_actions/version.rb +1 -1
  38. data/lib/sweet_actions.rb +27 -13
  39. data/sweet_actions.gemspec +3 -0
  40. metadata +55 -14
  41. data/lib/generators/rails/resource_override.rb +0 -10
  42. data/lib/sweet_actions/api_action.rb +0 -63
  43. data/lib/sweet_actions/collect_action.rb +0 -11
  44. data/lib/sweet_actions/create_action.rb +0 -10
  45. data/lib/sweet_actions/destroy_action.rb +0 -19
  46. data/lib/sweet_actions/read_concerns.rb +0 -14
  47. data/lib/sweet_actions/save_concerns.rb +0 -51
  48. data/lib/sweet_actions/show_action.rb +0 -9
  49. 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,14 +0,0 @@
1
- module SweetActions
2
- module ReadConcerns
3
- include RestConcerns
4
- include AuthorizationConcerns
5
-
6
- private
7
-
8
- def action
9
- @resource = set_resource
10
- authorize
11
- serialize
12
- end
13
- end
14
- 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
@@ -1,9 +0,0 @@
1
- module SweetActions
2
- class ShowAction < ApiAction
3
- include ReadConcerns
4
-
5
- def root_key
6
- singular_key
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- module SweetActions
2
- class UpdateAction < ApiAction
3
- include RestConcerns
4
- include SaveConcerns
5
-
6
- def save
7
- resource.attributes = resource_params
8
- resource.save
9
- end
10
- end
11
- end