soc_med 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +148 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/soc_med_manifest.js +1 -0
  6. data/app/assets/stylesheets/soc_med/application.css +15 -0
  7. data/app/blueprints/base_blueprint.rb +6 -0
  8. data/app/blueprints/blocks/overview_blueprint.rb +7 -0
  9. data/app/blueprints/follows/overview_blueprint.rb +7 -0
  10. data/app/blueprints/likes/overview_blueprint.rb +7 -0
  11. data/app/blueprints/reports/overview_blueprint.rb +7 -0
  12. data/app/controllers/soc_med/application_controller.rb +24 -0
  13. data/app/controllers/soc_med/blocks_controller.rb +28 -0
  14. data/app/controllers/soc_med/follows_controller.rb +28 -0
  15. data/app/controllers/soc_med/likes_controller.rb +28 -0
  16. data/app/controllers/soc_med/reports_controller.rb +29 -0
  17. data/app/errors/soc_med/base.rb +4 -0
  18. data/app/errors/soc_med/blocks/already_exists_error.rb +7 -0
  19. data/app/errors/soc_med/follows/already_exists_error.rb +7 -0
  20. data/app/errors/soc_med/likes/already_exists_error.rb +7 -0
  21. data/app/helpers/soc_med/application_helper.rb +4 -0
  22. data/app/jobs/soc_med/application_job.rb +4 -0
  23. data/app/mailers/soc_med/application_mailer.rb +6 -0
  24. data/app/models/soc_med/application_record.rb +5 -0
  25. data/app/models/soc_med/block.rb +16 -0
  26. data/app/models/soc_med/concerns/soc_med_helper.rb +17 -0
  27. data/app/models/soc_med/follow.rb +35 -0
  28. data/app/models/soc_med/like.rb +38 -0
  29. data/app/models/soc_med/report.rb +16 -0
  30. data/app/views/layouts/soc_med/application.html.erb +15 -0
  31. data/config/routes.rb +6 -0
  32. data/db/migrate/20200605151411_create_soc_med_likes.rb +12 -0
  33. data/db/migrate/20200605151423_create_soc_med_follows.rb +12 -0
  34. data/db/migrate/20200605151437_create_soc_med_blocks.rb +12 -0
  35. data/db/migrate/20200605151450_create_soc_med_reports.rb +12 -0
  36. data/lib/soc_med.rb +21 -0
  37. data/lib/soc_med/concerns/blockable.rb +34 -0
  38. data/lib/soc_med/concerns/followable.rb +34 -0
  39. data/lib/soc_med/concerns/likeable.rb +34 -0
  40. data/lib/soc_med/concerns/reportable.rb +33 -0
  41. data/lib/soc_med/engine.rb +5 -0
  42. data/lib/soc_med/services/base_service.rb +37 -0
  43. data/lib/soc_med/services/blocks/block_base.rb +46 -0
  44. data/lib/soc_med/services/blocks/create.rb +27 -0
  45. data/lib/soc_med/services/blocks/destroy.rb +27 -0
  46. data/lib/soc_med/services/failure.rb +16 -0
  47. data/lib/soc_med/services/follows/create.rb +27 -0
  48. data/lib/soc_med/services/follows/destroy.rb +27 -0
  49. data/lib/soc_med/services/follows/follow_base.rb +46 -0
  50. data/lib/soc_med/services/likes/create.rb +25 -0
  51. data/lib/soc_med/services/likes/destroy.rb +26 -0
  52. data/lib/soc_med/services/likes/like_base.rb +46 -0
  53. data/lib/soc_med/services/no_trigger.rb +10 -0
  54. data/lib/soc_med/services/reports/base_report.rb +46 -0
  55. data/lib/soc_med/services/reports/create.rb +27 -0
  56. data/lib/soc_med/services/reports/destroy.rb +27 -0
  57. data/lib/soc_med/services/success.rb +16 -0
  58. data/lib/soc_med/version.rb +3 -0
  59. data/lib/tasks/soc_med_tasks.rake +4 -0
  60. metadata +180 -0
@@ -0,0 +1,27 @@
1
+ require_relative './block_base'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Blocks
6
+ class Create < BlockBase
7
+
8
+ def call(&block)
9
+ blocked_object = create_blocked_object
10
+
11
+ yield(Success.new(blocked_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, SocMed::Blocks::AlreadyExistsError, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def create_blocked_object
19
+ blocked_object = owner.blockable_objects.build(target: target)
20
+
21
+ return blocked_object if blocked_object.save!
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../base_service'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Blocks
6
+ class Destroy < BaseService
7
+
8
+ def call(&block)
9
+ blocked_object = destroy_blocked_object
10
+
11
+ yield(Success.new(blocked_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def destroy_blocked_object
19
+ return { destroyed: true } if block.destroy!
20
+
21
+ { destroyed: false }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module SocMed
2
+ module Services
3
+ class Failure
4
+ attr_reader :error
5
+
6
+ def initialize(error)
7
+ @error = error
8
+ end
9
+
10
+ def call(&block)
11
+ yield(error)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ require_relative './follow_base'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Follows
6
+ class Create < BaseService
7
+
8
+ def call(&block)
9
+ followed_object = create_followed_object
10
+
11
+ yield(Success.new(followed_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, SocMed::Follows::AlreadyExistsError, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def create_followed_object
19
+ followed_object = owner.followable_objects.build(target: target)
20
+
21
+ return followed_object if followed_object.save!
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require_relative './follow_base'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Follows
6
+ class Destroy < FollowBase
7
+
8
+ def call(&block)
9
+ followed_object = destroy_followed_object
10
+
11
+ yield(Success.new(followed_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, SocMed::Follows::AlreadyExistsError, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def destroy_followed_object
19
+ return { destroyed: true } if follow.destroy!
20
+
21
+ { destroyed: false }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ require_relative '../base_service'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Follows
6
+ class FollowBase < BaseService
7
+
8
+ private
9
+
10
+ def follow
11
+ follow = owner.followable_objects.find_by(target: target)
12
+ raise ActiveRecord::RecordNotFound unless follow
13
+
14
+ follow
15
+ end
16
+
17
+ def target
18
+ target_type, target_id = target_info
19
+ target = target_type.classify.constantize.find_by(id: target_id)
20
+ raise ActiveRecord::RecordNotFound unless target
21
+
22
+ target
23
+ end
24
+
25
+ def target_info
26
+ return params[:follow][:target_type], params[:follow][:target_id] unless params[:follow].nil?
27
+ return params[:target_type], params[:target_id]
28
+ end
29
+
30
+ def owner
31
+ owner_type, owner_id = owner_info
32
+ owner = SocMed.owner_class.find_by(id: owner_id)
33
+ raise ActiveRecord::RecordNotFound unless owner
34
+
35
+ owner
36
+ end
37
+
38
+ def owner_info
39
+ return params[:follow][:owner_type], params[:follow][:owner_id] unless params[:follow].nil?
40
+ return params[:owner_type], params[:owner_id]
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './like_base'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Likes
6
+ class Create < LikeBase
7
+
8
+ def call(&block)
9
+ like = create_like
10
+
11
+ yield(Success.new(like), NoTrigger)
12
+ rescue SocMed::Likes::AlreadyExistsError, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def create_like
19
+ owner.likeable_objects.create(target: target)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ require_relative './like_base'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Likes
6
+ class Destroy < LikeBase
7
+
8
+ def call(&block)
9
+ liked_object = like_to_be_destroyed
10
+
11
+ yield(Success.new(liked_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def like_to_be_destroyed
19
+ return { destroyed: true } if like.destroy
20
+ { destroyed: false }
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ require_relative '../base_service'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Likes
6
+ class LikeBase < BaseService
7
+
8
+ private
9
+
10
+ def like
11
+ like = owner.likeable_objects.find_by(target: target)
12
+ raise ActiveRecord::RecordNotFound unless like
13
+
14
+ like
15
+ end
16
+
17
+ def target
18
+ target_type, target_id = target_info
19
+ target = target_type.classify.constantize.find_by(id: target_id)
20
+ raise ActiveRecord::RecordNotFound unless target
21
+
22
+ target
23
+ end
24
+
25
+ def target_info
26
+ return params[:like][:target_type], params[:like][:target_id] unless params[:like].nil?
27
+ return params[:target_type], params[:target_id]
28
+ end
29
+
30
+ def owner
31
+ owner_type, owner_id = owner_info
32
+ owner = SocMed.owner_class.find_by(id: owner_id)
33
+ raise ActiveRecord::RecordNotFound unless owner
34
+
35
+ owner
36
+ end
37
+
38
+ def owner_info
39
+ return params[:like][:owner_type], params[:like][:owner_id] unless params[:like].nil?
40
+ return params[:owner_type], params[:owner_id]
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,10 @@
1
+ module SocMed
2
+ module Services
3
+ class NoTrigger
4
+
5
+ def self.call
6
+ end
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ require_relative '../base_service'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Reports
6
+ class BaseReport < BaseService
7
+
8
+ private
9
+
10
+ def report
11
+ report = owner.likeable_objects.find_by(target: target)
12
+ raise ActiveRecord::RecordNotFound unless report
13
+
14
+ report
15
+ end
16
+
17
+ def target
18
+ target_type, target_id = target_info
19
+ target = target_type.classify.constantize.find_by(id: target_id)
20
+ raise ActiveRecord::RecordNotFound unless target
21
+
22
+ target
23
+ end
24
+
25
+ def target_info
26
+ return params[:report][:target_type], params[:report][:target_id] unless params[:report].nil?
27
+ return params[:target_type], params[:target_id]
28
+ end
29
+
30
+ def owner
31
+ owner_type, owner_id = owner_info
32
+ owner = SocMed.owner_class.find_by(id: owner_id)
33
+ raise ActiveRecord::RecordNotFound unless owner
34
+
35
+ owner
36
+ end
37
+
38
+ def owner_info
39
+ return params[:report][:owner_type], params[:report][:owner_id] unless params[:report].nil?
40
+ return params[:owner_type], params[:owner_id]
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ require_relative './base_report'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Reports
6
+ class Create < BaseReport
7
+
8
+ def call(&block)
9
+ reported_object = create_reported_object
10
+
11
+ yield(Success.new(reported_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, SocMed::Reports::AlreadyExistsError, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def create_reported_object
19
+ reported_object = owner.reportable_objects.build(target: target)
20
+
21
+ return reported_object if reported_object.save!
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require_relative './base_report'
2
+
3
+ module SocMed
4
+ module Services
5
+ module Reports
6
+ class Destroy < BaseReport
7
+
8
+ def call(&block)
9
+ reported_object = destroy_reported_object
10
+
11
+ yield(Success.new(reported_object), NoTrigger)
12
+ rescue ActiveRecord::RecordNotFound, StandardError => e
13
+ yield(NoTrigger, Failure.new(e))
14
+ end
15
+
16
+ private
17
+
18
+ def destroy_reported_object
19
+ return { destroyed: true } if report.destroy!
20
+
21
+ { destroyed: false }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ module SocMed
2
+ module Services
3
+ class Success
4
+ attr_reader :object
5
+
6
+ def initialize(object)
7
+ @object = object
8
+ end
9
+
10
+ def call(&block)
11
+ yield(object)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module SocMed
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :soc_med do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soc_med
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mike Heft
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.3
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.3.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.3
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.3.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: dry_serialization
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: blueprinter
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: activerecord
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: Gives the abillity to create likes, follows, blocks, and reporting for
90
+ Rails applications.
91
+ email:
92
+ - mikeheft@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - MIT-LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - app/assets/config/soc_med_manifest.js
101
+ - app/assets/stylesheets/soc_med/application.css
102
+ - app/blueprints/base_blueprint.rb
103
+ - app/blueprints/blocks/overview_blueprint.rb
104
+ - app/blueprints/follows/overview_blueprint.rb
105
+ - app/blueprints/likes/overview_blueprint.rb
106
+ - app/blueprints/reports/overview_blueprint.rb
107
+ - app/controllers/soc_med/application_controller.rb
108
+ - app/controllers/soc_med/blocks_controller.rb
109
+ - app/controllers/soc_med/follows_controller.rb
110
+ - app/controllers/soc_med/likes_controller.rb
111
+ - app/controllers/soc_med/reports_controller.rb
112
+ - app/errors/soc_med/base.rb
113
+ - app/errors/soc_med/blocks/already_exists_error.rb
114
+ - app/errors/soc_med/follows/already_exists_error.rb
115
+ - app/errors/soc_med/likes/already_exists_error.rb
116
+ - app/helpers/soc_med/application_helper.rb
117
+ - app/jobs/soc_med/application_job.rb
118
+ - app/mailers/soc_med/application_mailer.rb
119
+ - app/models/soc_med/application_record.rb
120
+ - app/models/soc_med/block.rb
121
+ - app/models/soc_med/concerns/soc_med_helper.rb
122
+ - app/models/soc_med/follow.rb
123
+ - app/models/soc_med/like.rb
124
+ - app/models/soc_med/report.rb
125
+ - app/views/layouts/soc_med/application.html.erb
126
+ - config/routes.rb
127
+ - db/migrate/20200605151411_create_soc_med_likes.rb
128
+ - db/migrate/20200605151423_create_soc_med_follows.rb
129
+ - db/migrate/20200605151437_create_soc_med_blocks.rb
130
+ - db/migrate/20200605151450_create_soc_med_reports.rb
131
+ - lib/soc_med.rb
132
+ - lib/soc_med/concerns/blockable.rb
133
+ - lib/soc_med/concerns/followable.rb
134
+ - lib/soc_med/concerns/likeable.rb
135
+ - lib/soc_med/concerns/reportable.rb
136
+ - lib/soc_med/engine.rb
137
+ - lib/soc_med/services/base_service.rb
138
+ - lib/soc_med/services/blocks/block_base.rb
139
+ - lib/soc_med/services/blocks/create.rb
140
+ - lib/soc_med/services/blocks/destroy.rb
141
+ - lib/soc_med/services/failure.rb
142
+ - lib/soc_med/services/follows/create.rb
143
+ - lib/soc_med/services/follows/destroy.rb
144
+ - lib/soc_med/services/follows/follow_base.rb
145
+ - lib/soc_med/services/likes/create.rb
146
+ - lib/soc_med/services/likes/destroy.rb
147
+ - lib/soc_med/services/likes/like_base.rb
148
+ - lib/soc_med/services/no_trigger.rb
149
+ - lib/soc_med/services/reports/base_report.rb
150
+ - lib/soc_med/services/reports/create.rb
151
+ - lib/soc_med/services/reports/destroy.rb
152
+ - lib/soc_med/services/success.rb
153
+ - lib/soc_med/version.rb
154
+ - lib/tasks/soc_med_tasks.rake
155
+ homepage: https://github.com/mikeyduece/soc_med
156
+ licenses:
157
+ - MIT
158
+ metadata: {}
159
+ post_install_message: "\n Post Installation Steps:\n 1. Copy migrations with
160
+ 'rails soc_med:install:migrations'\n 2. Include relevant modules in classes
161
+ you wish to take advantage of the engine.\n "
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubygems_version: 3.0.8
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Provides social media functionality to Rails applications
180
+ test_files: []