partisan 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +6 -5
- data/gemfiles/Gemfile.activerecord-4.1 +5 -0
- data/lib/partisan.rb +1 -3
- data/lib/partisan/followable.rb +1 -3
- data/lib/partisan/follower.rb +2 -3
- data/lib/partisan/helper.rb +17 -0
- data/lib/partisan/version.rb +1 -1
- data/partisan.gemspec +2 -2
- data/spec/partisan/followable_spec.rb +4 -4
- data/spec/partisan/follower_spec.rb +4 -4
- data/spec/partisan/helper_spec.rb +43 -0
- data/spec/support/macros/model_macros.rb +2 -1
- data/spec/support/macros/rails_macros.rb +5 -1
- metadata +25 -22
- data/lib/partisan/follow_helper.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 698e3eb571bbe3198a67365ef8be7beb1b37acf2
|
4
|
+
data.tar.gz: 40db91f5461e512580f03d9afcc93391fffcd66d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c02a2514eeb7b5b4249370c57aff22f4a587aa30e628868858b08234dd6b4df2c85eadba4cf4c9afebe1645ab3bc3dbe07f89c1a9e596e303f62be79a280ad4
|
7
|
+
data.tar.gz: 8eeb187a25dcdf319342860348b41408abc85e8baeb5b292cf932d699cf9e7a855b895bd48b1732ed4158391b2e507c7ca77763fc1f49e41e2ea60797eb71d9c
|
data/.travis.yml
CHANGED
@@ -5,7 +5,17 @@ rvm:
|
|
5
5
|
- 1.9.3
|
6
6
|
|
7
7
|
gemfile:
|
8
|
+
- gemfiles/Gemfile.activerecord-4.1
|
8
9
|
- gemfiles/Gemfile.activerecord-4.0
|
9
10
|
- gemfiles/Gemfile.activerecord-3.2.x
|
10
11
|
|
11
12
|
script: "echo 'DO IT' && bundle exec rake spec"
|
13
|
+
|
14
|
+
notifications:
|
15
|
+
hipchat:
|
16
|
+
rooms:
|
17
|
+
secure: "DUZC6Q2b18pEp7W7qNnGRYDgqtZGeWh44ED+hF27OIxjdM6JRx/nOmpvY46/lR6KjiH7DDM+TGPbxAzXo3rECxUZqkMPjMkqfZyfyN4JhccI/dJf1EL0GDUMogPfFUOuLWTqA49Y9GvvXTghK/irlLBhInWcrPJcTIsDG2t4nN4="
|
18
|
+
template:
|
19
|
+
- '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Build</a>/<a href="%{compare_url}">Changes</a>)'
|
20
|
+
format: 'html'
|
21
|
+
|
data/README.md
CHANGED
@@ -5,9 +5,10 @@
|
|
5
5
|
<br />
|
6
6
|
Partisan is a Ruby library that allows ActiveRecord records to follow other records.
|
7
7
|
<br /><br />
|
8
|
-
<a href="https://rubygems.org/gems/partisan"><img src="
|
9
|
-
<a href="https://codeclimate.com/github/mirego/partisan"><img src="
|
10
|
-
<a href="https://
|
8
|
+
<a href="https://rubygems.org/gems/partisan"><img src="http://img.shields.io/gem/v/partisan.svg" /></a>
|
9
|
+
<a href="https://codeclimate.com/github/mirego/partisan"><img src="http://img.shields.io/codeclimate/github/mirego/partisan.svg" /></a>
|
10
|
+
<a href="https://gemnasium.com/mirego/partisan"><img src="http://img.shields.io/gemnasium/mirego/partisan.svg" /></a>
|
11
|
+
<a href="https://travis-ci.org/mirego/partisan"><img src="http://img.shields.io/travis/mirego/partisan.svg" /></a>
|
11
12
|
</p>
|
12
13
|
|
13
14
|
---
|
@@ -145,6 +146,6 @@ The available callbacks are:
|
|
145
146
|
|
146
147
|
## About Mirego
|
147
148
|
|
148
|
-
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We
|
149
|
+
[Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org).
|
149
150
|
|
150
|
-
We also love
|
151
|
+
We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.
|
data/lib/partisan.rb
CHANGED
@@ -2,14 +2,12 @@ require "partisan/version"
|
|
2
2
|
|
3
3
|
require "active_record"
|
4
4
|
|
5
|
+
require "partisan/helper"
|
5
6
|
require "partisan/follow"
|
6
|
-
require "partisan/follow_helper"
|
7
7
|
require "partisan/follower"
|
8
8
|
require "partisan/followable"
|
9
9
|
|
10
10
|
module Partisan
|
11
|
-
include Partisan::FollowHelper
|
12
|
-
|
13
11
|
def self.inject_into_active_record
|
14
12
|
@inject_into_active_record ||= Proc.new do
|
15
13
|
def self.acts_as_follower
|
data/lib/partisan/followable.rb
CHANGED
@@ -3,8 +3,6 @@ module Partisan
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
extend ActiveModel::Callbacks
|
5
5
|
|
6
|
-
include Partisan::FollowHelper
|
7
|
-
|
8
6
|
included do
|
9
7
|
has_many :followings, as: :followable, class_name: 'Follow', dependent: :destroy
|
10
8
|
define_model_callbacks :being_followed
|
@@ -34,7 +32,7 @@ module Partisan
|
|
34
32
|
def followers_by_type(follower_type)
|
35
33
|
opts = {
|
36
34
|
'follows.followable_id' => self.id,
|
37
|
-
'follows.followable_type' => parent_class_name(self)
|
35
|
+
'follows.followable_type' => Partisan::Helper.parent_class_name(self)
|
38
36
|
}
|
39
37
|
|
40
38
|
follower_type.constantize.joins(:follows).where(opts)
|
data/lib/partisan/follower.rb
CHANGED
@@ -2,7 +2,6 @@ module Partisan
|
|
2
2
|
module Follower
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
extend ActiveModel::Callbacks
|
5
|
-
include Partisan::FollowHelper
|
6
5
|
|
7
6
|
included do
|
8
7
|
has_many :follows, as: :follower, class_name: 'Follow', dependent: :destroy
|
@@ -63,7 +62,7 @@ module Partisan
|
|
63
62
|
#
|
64
63
|
# @return [Follow, ...]
|
65
64
|
def fetch_follows(resource)
|
66
|
-
follows.where followable_id: resource.id, followable_type: parent_class_name(resource)
|
65
|
+
follows.where followable_id: resource.id, followable_type: Partisan::Helper.parent_class_name(resource)
|
67
66
|
end
|
68
67
|
|
69
68
|
# Get resource records for a specific type, used by #method_missing
|
@@ -77,7 +76,7 @@ module Partisan
|
|
77
76
|
def following_by_type(followable_type)
|
78
77
|
opts = {
|
79
78
|
'follows.follower_id' => self.id,
|
80
|
-
'follows.follower_type' => parent_class_name(self)
|
79
|
+
'follows.follower_type' => Partisan::Helper.parent_class_name(self)
|
81
80
|
}
|
82
81
|
|
83
82
|
followable_type.constantize.joins(:followings).where(opts)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Partisan
|
2
|
+
class Helper
|
3
|
+
# Retrieves the parent class name
|
4
|
+
def self.parent_class_name(obj)
|
5
|
+
# If the object is an ActiveRecord record
|
6
|
+
klass = obj.class if obj.class < ActiveRecord::Base
|
7
|
+
|
8
|
+
# If the object respond to `object` and the value is an ActiveRecord record
|
9
|
+
klass ||= obj.object.class if obj.respond_to?(:object) && obj.object.class < ActiveRecord::Base
|
10
|
+
|
11
|
+
# In case we’re using STI, loop back until we find the top-level ActiveRecord model
|
12
|
+
klass = klass.superclass while klass.superclass != ActiveRecord::Base
|
13
|
+
|
14
|
+
klass.name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/partisan/version.rb
CHANGED
data/partisan.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Partisan::VERSION
|
9
9
|
spec.authors = ['Simon Prévost', 'Rémi Prévost']
|
10
10
|
spec.email = ['sprevost@mirego.com', 'Rémi Prévost']
|
11
|
-
spec.description = 'Partisan is a Ruby library that allows ActiveRecord records to be follower and followable, just like on popular social networks. It’s heavily inspired by acts_as_follower which is no longer
|
11
|
+
spec.description = 'Partisan is a Ruby library that allows ActiveRecord records to be follower and followable, just like on popular social networks. It’s heavily inspired by acts_as_follower which is no longer maintained.'
|
12
12
|
spec.summary = 'Partisan is a Ruby library that allows ActiveRecord records to be follower and followable'
|
13
13
|
spec.homepage = 'https://github.com/mirego/partisan'
|
14
14
|
spec.license = 'BSD 3-Clause'
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
24
|
spec.add_development_dependency 'rake'
|
25
|
-
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
26
26
|
spec.add_development_dependency 'sqlite3'
|
27
27
|
end
|
@@ -31,8 +31,8 @@ describe Partisan::Followable do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe :followed_by? do
|
34
|
-
it { expect(band.followed_by? user).to
|
35
|
-
it { expect(concert.followed_by? user).to
|
34
|
+
it { expect(band.followed_by? user).to be_truthy }
|
35
|
+
it { expect(concert.followed_by? user).to be_falsey }
|
36
36
|
end
|
37
37
|
|
38
38
|
describe :followers_by_type do
|
@@ -62,8 +62,8 @@ describe Partisan::Followable do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
describe :respond_to? do
|
65
|
-
it { expect(band.respond_to?(:user_followers)).to
|
66
|
-
it { expect(band.respond_to?(:users_follower_ids)).to
|
65
|
+
it { expect(band.respond_to?(:user_followers)).to be_truthy }
|
66
|
+
it { expect(band.respond_to?(:users_follower_ids)).to be_truthy }
|
67
67
|
end
|
68
68
|
|
69
69
|
describe :update_follow_counter do
|
@@ -52,8 +52,8 @@ describe Partisan::Follower do
|
|
52
52
|
describe :follows? do
|
53
53
|
let(:band2) { Band.create }
|
54
54
|
|
55
|
-
it { expect(user.follows? band).to
|
56
|
-
it { expect(user.follows? band2).to
|
55
|
+
it { expect(user.follows? band).to be_truthy }
|
56
|
+
it { expect(user.follows? band2).to be_falsey }
|
57
57
|
end
|
58
58
|
|
59
59
|
describe :following_by_type do
|
@@ -89,8 +89,8 @@ describe Partisan::Follower do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
describe :respond_to? do
|
92
|
-
it { expect(user.respond_to?(:following_bands)).to
|
93
|
-
it { expect(user.respond_to?(:following_band_ids)).to
|
92
|
+
it { expect(user.respond_to?(:following_bands)).to be_truthy }
|
93
|
+
it { expect(user.respond_to?(:following_band_ids)).to be_truthy }
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Partisan::Helper do
|
4
|
+
describe :ClassMethods do
|
5
|
+
describe :parent_class_name do
|
6
|
+
let(:parent_class_name) { Partisan::Helper.send(:parent_class_name, object) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
run_migration { create_table 'articles' }
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with regular record object' do
|
13
|
+
let(:object) { spawn_model('Article', ActiveRecord::Base).new }
|
14
|
+
|
15
|
+
it { expect(parent_class_name).to eql 'Article' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with STI-model record object' do
|
19
|
+
let(:object) do
|
20
|
+
spawn_model('Article', ActiveRecord::Base)
|
21
|
+
spawn_model('BlogPost', Article).new
|
22
|
+
end
|
23
|
+
|
24
|
+
it { expect(parent_class_name).to eql 'Article' }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with a presented record object' do
|
28
|
+
let(:presenter_class) do
|
29
|
+
Class.new(::SimpleDelegator) do
|
30
|
+
alias_method :object, :__getobj__
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:object) do
|
35
|
+
spawn_model('Article', ActiveRecord::Base)
|
36
|
+
presenter_class.new(Article.new)
|
37
|
+
end
|
38
|
+
|
39
|
+
it { expect(parent_class_name).to eql 'Article' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -29,7 +29,8 @@ module ModelMacros
|
|
29
29
|
# Create a new model class
|
30
30
|
def spawn_model(klass_name, parent_klass, &block)
|
31
31
|
Object.instance_eval { remove_const klass_name } if Object.const_defined?(klass_name)
|
32
|
-
Object.const_set(klass_name, Class.new(parent_klass))
|
32
|
+
klass = Object.const_set(klass_name, Class.new(parent_klass))
|
33
33
|
Object.const_get(klass_name).class_eval(&block) if block_given?
|
34
|
+
klass
|
34
35
|
end
|
35
36
|
end
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module RailsMacros
|
2
|
+
# NOTE: This method is not fun to maintain but we need it to make sure
|
3
|
+
# Partisan methods return *real* not-loaded ActiveRecord relations
|
2
4
|
def relation_class(klass)
|
3
5
|
if ActiveRecord::VERSION::MAJOR == 3
|
4
6
|
ActiveRecord::Relation
|
5
|
-
|
7
|
+
elsif [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] == [4, 0]
|
6
8
|
"ActiveRecord::Relation::ActiveRecord_Relation_#{klass.name}".constantize
|
9
|
+
else
|
10
|
+
"#{klass.name}::ActiveRecord_Relation".constantize
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partisan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Prévost
|
@@ -9,81 +9,81 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 3.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.3'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.3'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '3.1'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '3.1'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: sqlite3
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
description: Partisan is a Ruby library that allows ActiveRecord records to be follower
|
85
85
|
and followable, just like on popular social networks. It’s heavily inspired by acts_as_follower
|
86
|
-
which is no longer
|
86
|
+
which is no longer maintained.
|
87
87
|
email:
|
88
88
|
- sprevost@mirego.com
|
89
89
|
- Rémi Prévost
|
@@ -91,28 +91,30 @@ executables: []
|
|
91
91
|
extensions: []
|
92
92
|
extra_rdoc_files: []
|
93
93
|
files:
|
94
|
-
- .gitignore
|
95
|
-
- .rspec
|
96
|
-
- .travis.yml
|
94
|
+
- ".gitignore"
|
95
|
+
- ".rspec"
|
96
|
+
- ".travis.yml"
|
97
97
|
- Gemfile
|
98
98
|
- LICENSE.md
|
99
99
|
- README.md
|
100
100
|
- Rakefile
|
101
101
|
- gemfiles/Gemfile.activerecord-3.2.x
|
102
102
|
- gemfiles/Gemfile.activerecord-4.0
|
103
|
+
- gemfiles/Gemfile.activerecord-4.1
|
103
104
|
- lib/generators/partisan/USAGE
|
104
105
|
- lib/generators/partisan/install_generator.rb
|
105
106
|
- lib/generators/partisan/templates/migration.rb
|
106
107
|
- lib/generators/partisan/templates/model.rb
|
107
108
|
- lib/partisan.rb
|
108
109
|
- lib/partisan/follow.rb
|
109
|
-
- lib/partisan/follow_helper.rb
|
110
110
|
- lib/partisan/followable.rb
|
111
111
|
- lib/partisan/follower.rb
|
112
|
+
- lib/partisan/helper.rb
|
112
113
|
- lib/partisan/version.rb
|
113
114
|
- partisan.gemspec
|
114
115
|
- spec/partisan/followable_spec.rb
|
115
116
|
- spec/partisan/follower_spec.rb
|
117
|
+
- spec/partisan/helper_spec.rb
|
116
118
|
- spec/spec_helper.rb
|
117
119
|
- spec/support/macros/database_macros.rb
|
118
120
|
- spec/support/macros/model_macros.rb
|
@@ -127,17 +129,17 @@ require_paths:
|
|
127
129
|
- lib
|
128
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
131
|
requirements:
|
130
|
-
- -
|
132
|
+
- - ">="
|
131
133
|
- !ruby/object:Gem::Version
|
132
134
|
version: '0'
|
133
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
136
|
requirements:
|
135
|
-
- -
|
137
|
+
- - ">="
|
136
138
|
- !ruby/object:Gem::Version
|
137
139
|
version: '0'
|
138
140
|
requirements: []
|
139
141
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.2.2
|
141
143
|
signing_key:
|
142
144
|
specification_version: 4
|
143
145
|
summary: Partisan is a Ruby library that allows ActiveRecord records to be follower
|
@@ -145,6 +147,7 @@ summary: Partisan is a Ruby library that allows ActiveRecord records to be follo
|
|
145
147
|
test_files:
|
146
148
|
- spec/partisan/followable_spec.rb
|
147
149
|
- spec/partisan/follower_spec.rb
|
150
|
+
- spec/partisan/helper_spec.rb
|
148
151
|
- spec/spec_helper.rb
|
149
152
|
- spec/support/macros/database_macros.rb
|
150
153
|
- spec/support/macros/model_macros.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Partisan
|
2
|
-
module FollowHelper
|
3
|
-
|
4
|
-
private
|
5
|
-
|
6
|
-
# Retrieves the parent class name if using STI.
|
7
|
-
def parent_class_name(obj)
|
8
|
-
klass = obj.class
|
9
|
-
klass = klass.superclass while klass.superclass != ActiveRecord::Base
|
10
|
-
|
11
|
-
klass.name
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|