partisan 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5144131fd00599fe346d266846c160768aa821e2
4
+ data.tar.gz: ab4d801d4cf2e632474efa1d8a1117d1b66b7a19
5
+ SHA512:
6
+ metadata.gz: e416ac5b694502c5d7f84442079987f5b3561a7b6cfe90c36f78517b6f9d791a16c78f20b9069d35d5e2874b425c4e5c236a9e2257c4e74fbfba8fa30f41791d
7
+ data.tar.gz: e5fbe276053c550f4ecadb39df3c8933eade895eb435ee0d3558504da5592d1eb71d7fef076446aed41b56aa7a913c4bbe190393c3ab0fba644fffa4f3ca3eee
data/README.md CHANGED
@@ -37,7 +37,7 @@ And then execute
37
37
  $ bundle
38
38
  ```
39
39
 
40
- Run the migration to add the `follows` table:
40
+ Run the migration to add the `follows` table and the `Follow` model:
41
41
 
42
42
  ```bash
43
43
  $ rails generate partisan:install
@@ -20,6 +20,10 @@ module Partisan
20
20
  def create_migration_file
21
21
  migration_template 'migration.rb', 'db/migrate/add_follows_migration.rb'
22
22
  end
23
+
24
+ def create_model_file
25
+ template "model.rb", "app/models/follow.rb"
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -0,0 +1,3 @@
1
+ class Follow < ActiveRecord::Base
2
+ acts_as_follow
3
+ end
@@ -19,6 +19,10 @@ module Partisan
19
19
  def self.acts_as_followable
20
20
  self.send :include, Partisan::Followable
21
21
  end
22
+
23
+ def self.acts_as_follow
24
+ self.send :include, Partisan::Follow
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -1,23 +1,6 @@
1
1
  module Partisan
2
- class Follow < ActiveRecord::Base
3
- self.table_name = 'follows'
4
-
5
- # Validations
6
- validates :followable, presence: true
7
- validates :follower, presence: true
8
-
9
- # Associations
10
- belongs_to :followable, polymorphic: true
11
- belongs_to :follower, polymorphic: true
12
-
13
- # Callbacks
14
- after_create :update_follow_counter
15
- after_destroy :update_follow_counter
16
-
17
- around_create :around_create_follower
18
- around_create :around_create_followable
19
- around_destroy :around_destroy_follower
20
- around_destroy :around_destroy_followable
2
+ module Follow
3
+ extend ActiveSupport::Concern
21
4
 
22
5
  # Constants
23
6
  FOLLOWER_FOLLOW_ACCESSORS = [:about_to_follow, :just_followed]
@@ -25,6 +8,25 @@ module Partisan
25
8
  FOLLOWABLE_BEING_FOLLOWED_ACCESSORS = [:about_to_be_followed_by, :just_followed_by]
26
9
  FOLLOWABLE_BEING_UNFOLLOWED_ACCESSORS = [:about_to_be_unfollowed_by, :just_unfollowed_by]
27
10
 
11
+ included do
12
+ # Validations
13
+ validates :followable, presence: true
14
+ validates :follower, presence: true
15
+
16
+ # Associations
17
+ belongs_to :followable, polymorphic: true
18
+ belongs_to :follower, polymorphic: true
19
+
20
+ # Callbacks
21
+ after_create :update_follow_counter
22
+ after_destroy :update_follow_counter
23
+
24
+ around_create :around_create_follower
25
+ around_create :around_create_followable
26
+ around_destroy :around_destroy_follower
27
+ around_destroy :around_destroy_followable
28
+ end
29
+
28
30
  protected
29
31
 
30
32
  def update_follow_counter
@@ -48,10 +50,6 @@ module Partisan
48
50
  execute_callback :followable, :being_unfollowed, &blk
49
51
  end
50
52
 
51
- def self.accessors_for_follow_callback(association, callback)
52
- const_get "#{association}_#{callback}_accessors".upcase
53
- end
54
-
55
53
  private
56
54
 
57
55
  def execute_callback(association, callback, &blk)
@@ -71,5 +69,11 @@ module Partisan
71
69
 
72
70
  true
73
71
  end
72
+
73
+ module ClassMethods
74
+ def accessors_for_follow_callback(association, callback)
75
+ const_get "#{association}_#{callback}_accessors".upcase
76
+ end
77
+ end
74
78
  end
75
79
  end
@@ -6,7 +6,7 @@ module Partisan
6
6
  include Partisan::FollowHelper
7
7
 
8
8
  included do
9
- has_many :followings, as: :followable, class_name: 'Partisan::Follow', dependent: :destroy
9
+ has_many :followings, as: :followable, class_name: 'Follow', dependent: :destroy
10
10
  define_model_callbacks :being_followed
11
11
  define_model_callbacks :being_unfollowed
12
12
  attr_accessor :about_to_be_followed_by, :just_followed_by, :about_to_be_unfollowed_by, :just_unfollowed_by
@@ -5,7 +5,7 @@ module Partisan
5
5
  include Partisan::FollowHelper
6
6
 
7
7
  included do
8
- has_many :follows, as: :follower, class_name: 'Partisan::Follow', dependent: :destroy
8
+ has_many :follows, as: :follower, class_name: 'Follow', dependent: :destroy
9
9
  define_model_callbacks :follow
10
10
  define_model_callbacks :unfollow
11
11
  attr_accessor :about_to_follow, :just_followed, :about_to_unfollow, :just_unfollowed
@@ -17,7 +17,7 @@ module Partisan
17
17
  #
18
18
  # @user.follow(@team)
19
19
  #
20
- # @return (Partisan::Follow)
20
+ # @return (Follow)
21
21
  def follow(resource)
22
22
  return if self == resource
23
23
 
@@ -32,7 +32,7 @@ module Partisan
32
32
  #
33
33
  # @user.unfollow(@team)
34
34
  #
35
- # @return (Partisan::Follow) || nil
35
+ # @return (Follow) || nil
36
36
  def unfollow(resource)
37
37
  return if self == resource
38
38
 
@@ -61,7 +61,7 @@ module Partisan
61
61
  #
62
62
  # @user.fetch_follows(@team)
63
63
  #
64
- # @return [Partisan::Follow, ...]
64
+ # @return [Follow, ...]
65
65
  def fetch_follows(resource)
66
66
  follows.where followable_id: resource.id, followable_type: parent_class_name(resource)
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module Partisan
2
- VERSION = "0.3"
2
+ VERSION = '0.4'
3
3
  end
@@ -41,12 +41,12 @@ describe Partisan::Follower do
41
41
  end
42
42
 
43
43
  describe :follow do
44
- it { expect(Partisan::Follow.last.follower_id).to eq user.id }
45
- it { expect(Partisan::Follow.last.followable_id).to eq band.id }
44
+ it { expect(Follow.last.follower_id).to eq user.id }
45
+ it { expect(Follow.last.followable_id).to eq band.id }
46
46
  end
47
47
 
48
48
  describe :unfollow do
49
- it { expect{user.unfollow band}.to change{Partisan::Follow.last}.to(nil) }
49
+ it { expect{user.unfollow band}.to change{Follow.last}.to(nil) }
50
50
  end
51
51
 
52
52
  describe :follows? do
@@ -20,6 +20,10 @@ RSpec.configure do |config|
20
20
 
21
21
  # Run our migration
22
22
  run_default_migration
23
+
24
+ spawn_model 'Follow', ActiveRecord::Base do
25
+ acts_as_follow
26
+ end
23
27
  end
24
28
 
25
29
  config.after(:each) do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: partisan
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
5
- prerelease:
4
+ version: '0.4'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Simon Prévost
@@ -10,28 +9,25 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-08-28 00:00:00.000000000 Z
12
+ date: 2013-09-16 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 3.0.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: 3.0.0
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: bundler
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ~>
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ~>
45
40
  - !ruby/object:Gem::Version
@@ -47,49 +42,43 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rake
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: rspec
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: sqlite3
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  description: Partisan is a Ruby library that allows ActiveRecord records to be follower
@@ -114,6 +103,7 @@ files:
114
103
  - lib/generators/partisan/USAGE
115
104
  - lib/generators/partisan/install_generator.rb
116
105
  - lib/generators/partisan/templates/migration.rb
106
+ - lib/generators/partisan/templates/model.rb
117
107
  - lib/partisan.rb
118
108
  - lib/partisan/follow.rb
119
109
  - lib/partisan/follow_helper.rb
@@ -130,33 +120,26 @@ files:
130
120
  homepage: https://github.com/mirego/partisan
131
121
  licenses:
132
122
  - BSD 3-Clause
123
+ metadata: {}
133
124
  post_install_message:
134
125
  rdoc_options: []
135
126
  require_paths:
136
127
  - lib
137
128
  required_ruby_version: !ruby/object:Gem::Requirement
138
- none: false
139
129
  requirements:
140
- - - ! '>='
130
+ - - '>='
141
131
  - !ruby/object:Gem::Version
142
132
  version: '0'
143
- segments:
144
- - 0
145
- hash: 83070319270688629
146
133
  required_rubygems_version: !ruby/object:Gem::Requirement
147
- none: false
148
134
  requirements:
149
- - - ! '>='
135
+ - - '>='
150
136
  - !ruby/object:Gem::Version
151
137
  version: '0'
152
- segments:
153
- - 0
154
- hash: 83070319270688629
155
138
  requirements: []
156
139
  rubyforge_project:
157
- rubygems_version: 1.8.23
140
+ rubygems_version: 2.1.0
158
141
  signing_key:
159
- specification_version: 3
142
+ specification_version: 4
160
143
  summary: Partisan is a Ruby library that allows ActiveRecord records to be follower
161
144
  and followable
162
145
  test_files: