social_man 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8faa448ec53af875988e037161d8c353f147fa31e65578b9923f5aec922d634a
4
+ data.tar.gz: 647a1f4dbcc311c1261c60db46f8d6698fa0bceeb8e35462d80c6d7ad9234652
5
+ SHA512:
6
+ metadata.gz: c8d7159def702ebd429b93a417c943a1fe2c5116d90679a3bc22593ab08ddead64a7b581a5cee214d105e8110c23520b785425d808e0de7b05733949f7ab7233
7
+ data.tar.gz: f983ac83dcaebdeaacbb79fbc45bceb69795d2b75693ac2d9cf64622392ef4313c766d2a238d18ecfb11bbaf26ab565f0da53899a86217d996097fe4198644a1
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 John Hu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # SocialMan
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'social_man'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install social_man
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'SocialMan'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
File without changes
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # Auto generate with social-man gem.
3
+ class Action < ActiveRecord::Base
4
+ include SocialMan::ActionModel
5
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module SocialMan
3
+ module ActionModel
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ belongs_to :subject, polymorphic: true
8
+ belongs_to :object, polymorphic: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module SocialMan
2
+ module ActionObject
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_action_object
10
+ has_many :passive_actions, class_name: 'Action',
11
+ dependent: :destroy
12
+
13
+ include SocialMan::ActionObject::InstanceMethods
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ def be_taken_action_by(subject)
19
+ Action.create subject: subject, object: self
20
+ end
21
+
22
+ def passive_to?(subject)
23
+ Action.exists? subject: subject, object: self
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ module SocialMan
2
+ module ActionSubject
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_action_subject
10
+ has_many :active_actions, class_name: 'Action',
11
+ dependent: :destroy
12
+ # has_many :action_objects, class_name: 'Action',
13
+ # source: :subject,
14
+ # through: :active_actions
15
+
16
+ include SocialMan::ActionSubject::InstanceMethods
17
+ end
18
+ end
19
+
20
+ module InstanceMethods
21
+ def take_action_on(object)
22
+ Action.create subject: self, object: object
23
+ end
24
+
25
+ def active_to?(object)
26
+ Action.exists? subject: self, object: object
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ module SocialMan
2
+ class Engine < ::Rails::Engine
3
+ initializer "social_man.init_action", after: :load_config_initializers do
4
+ # Ensure eager_load Action model to init methods
5
+ require "action"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails'
2
+
3
+ module ActsAsFollower
4
+ class Railtie < Rails::Railtie
5
+
6
+ initializer "social_man.active_record" do |app|
7
+ ActiveSupport.on_load :active_record do
8
+ include SocialMan::ActionSubject
9
+ include SocialMan::ActionObject
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module SocialMan
2
+ VERSION = '0.1.0'
3
+ end
data/lib/social_man.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "social_man/version"
2
+ require "social_man/engine"
3
+ require 'social_man/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
4
+
5
+ module SocialMan
6
+ autoload :ActionSubject, 'social_man/action_subject'
7
+ autoload :ActionObject, 'social_man/action_object'
8
+ autoload :ActionModel, 'social_man/action_model'
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :social_man do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social_man
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Hu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-09 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: 5.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_bot
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Follow, star, vote, like, social actions all in one.
98
+ email:
99
+ - huziyong@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - app/assets/config/social_man_manifest.js
108
+ - app/models/action.rb
109
+ - config/routes.rb
110
+ - lib/social_man.rb
111
+ - lib/social_man/action_model.rb
112
+ - lib/social_man/action_object.rb
113
+ - lib/social_man/action_subject.rb
114
+ - lib/social_man/engine.rb
115
+ - lib/social_man/railtie.rb
116
+ - lib/social_man/version.rb
117
+ - lib/tasks/social_man_tasks.rake
118
+ homepage: https://github.com/hutusi/social_man/
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.6
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Follow, star, vote, like, social actions all in one.
142
+ test_files: []