bfriend 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 622e58967a1a4efcec7f98f6e09d07b32870dca5
4
- data.tar.gz: 7bf237f63837034e035fa657b49a8e1e55fe0519
3
+ metadata.gz: 6ffc6af4bea6eb13f40601754e7eb1b91911ac6d
4
+ data.tar.gz: f3d9c7e662c2844a9b006eb6a81b31c7a191b35c
5
5
  SHA512:
6
- metadata.gz: 62ad98686710315b30cc7b1ba61519545cafc919251145af521e1e512b53d536a9e3cc680446671dc36f1ae9d4cae2240c868c69de50153b925972211bdeb7fb
7
- data.tar.gz: 1be1b815d8930aff9056de13e4eb0f5e41d7c451aa692b2673a73400bedb5c5c23c403f077bb0453393dac7335d870bd244125986b1dc490d283c80a32de6465
6
+ metadata.gz: 66defefd24e69a79d99c414cbc0f05dc37b8dd0f864af5a4832457e3553b49293ae34e2daa1976c90959d1f49295efe74fee94d46846df5a0ef6913270de7c11
7
+ data.tar.gz: 8a446320e214177cfcbd004b0ae643f173d04ca7dfeb5292915ed623eee56eb6254e3601be5ce8fa356ee13def144c53a902462835ef87849cc00f2246856330
Binary file
data/README.md CHANGED
@@ -21,9 +21,9 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- Run the bfriend generator `rails g bfriend -t --api`. This will generate a friendship model, a migration, add routes & associations to your user model and generate a friendship controller suitable for use in an API.
24
+ Run the bfriend generator `rails g bfriend`. This will generate a friendship model, a migration, add routes & associations to your user model and generate a friendship controller suitable for use in an API.
25
25
 
26
- If you are using the gem for a ruby on rails project, run `rails g bfriend -t --ror` .
26
+ If you are using the gem for a ruby on rails project, run `rails g bfriend --ror` .
27
27
 
28
28
  Edit the migration to give the status a default of false
29
29
 
@@ -47,6 +47,8 @@ Now you can:
47
47
 
48
48
  At this time no view templates are created and I will update this readme when and if I add them.
49
49
 
50
+ ### Upgrading to >= 0.8.0
51
+ The class methods have been moved to the bfriend module of the gem so you will need to remove them from your user model and add `include Bfriend`
50
52
 
51
53
  ## Contributing
52
54
 
@@ -6,8 +6,8 @@ require "bfriend/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "bfriend"
8
8
  spec.version = Bfriend::VERSION
9
- spec.authors = ["xfinger"]
10
- spec.email = ["xfinger@gmail.com"]
9
+ spec.authors = "xfinger"
10
+ spec.email = "xfinger@gmail.com"
11
11
 
12
12
  spec.summary = %q{A simple friendship model}
13
13
  spec.description = %q{Based on Railscasts #163 Self-Referential Association}
@@ -26,9 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
27
  f.match(%r{^(test|spec|features)/})
28
28
  end
29
+
29
30
  spec.bindir = "exe"
30
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
+ spec.require_paths = ["lib","lib/generators"]
33
+ spec.required_ruby_version = ">= 2.0.0"
32
34
 
33
35
  spec.add_development_dependency "bundler", "~> 1.15"
34
36
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,5 +1,24 @@
1
- require "bfriend/version"
2
1
 
3
2
  module Bfriend
4
-
3
+ def self.included(base)
4
+ base.class_eval do
5
+ has_many :friendships
6
+ has_many :bfriended_friendships, class_name: "Friendship", foreign_key: "friend_id"
7
+ # bfriended by user
8
+ has_many :current_friends, -> { where(friendships: { status: true}) }, through: :friendships, source: :friend
9
+ # bfriended by friend
10
+ has_many :bfriended_friends, -> { where(friendships: { status: true}) }, through: :bfriended_friendships, source: :user # requested by friend
11
+ has_many :requested_friends, -> { where(friendships: { status: false}) }, through: :bfriended_friendships, source: :user
12
+ # requested by user
13
+ has_many :pending_friends, -> { where(friendships: { status: false}) }, through: :friendships, source: :friend
14
+ end
15
+ # combine the sets to see all your friends
16
+ def friends
17
+ current_friends | bfriended_friends
18
+ end
19
+ # combine the sets to see pending and requested friendships
20
+ def pending
21
+ pending_friends | requested_friends
22
+ end
23
+ end
5
24
  end
@@ -1,5 +1,5 @@
1
1
  require "bfriend/version"
2
2
 
3
3
  module Bfriend
4
- VERSION = "0.7.3"
4
+ VERSION = "0.8.0"
5
5
  end
@@ -5,7 +5,8 @@ require 'rails/generators/active_record'
5
5
  class BfriendGenerator < Rails::Generators::Base
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
  include Rails::Generators::Migration
8
- class_option :controller_template, :type => :string, :aliases => "-t", :desc => "Template engine for the Controller. Available options are 'api' and 'ror'.", :default => "api"
8
+
9
+ class_option :controller_template, :type => :string, :desc => "Template engine for the Controller. Available options are 'api' and 'ror'.", :default => "api"
9
10
  class_option :ror, :type => :boolean, :default => false
10
11
 
11
12
 
@@ -22,34 +23,8 @@ class BfriendGenerator < Rails::Generators::Base
22
23
 
23
24
 
24
25
  def add_to_user
25
- inject_into_file 'app/models/user.rb', before: "end" do
26
- "
27
- has_many :friendships
28
- has_many :bfriended_friendships, :class_name => \"Friendship\", :foreign_key => \"friend_id\"
29
-
30
- # bfriended by user
31
- has_many :current_friends, -> { where(friendships: { status: true}) }, through: :friendships, source: :friend
32
- # bfriended by friend
33
- has_many :bfriended_friends, -> { where(friendships: { status: true}) }, through: :bfriended_friendships, source: :user
34
- # requested by friend
35
- has_many :requested_friends, -> { where(friendships: { status: false}) }, through: :bfriended_friendships, source: :user
36
- # requested by user
37
- has_many :pending_friends, -> { where(friendships: { status: false}) }, through: :friendships, source: :friend
38
- \n
39
-
40
- # combine the sets to see all your friends
41
- def friends
42
- current_friends | bfriended_friends
43
- end
44
-
45
- # combine the sets to see pending and requested friendships
46
- def pending
47
- pending_friends | requested_friends
48
- end
49
-
50
- \n
51
- "
52
-
26
+ inject_into_file 'app/models/user.rb', before: "end" do
27
+ "include Bfriend\n"
53
28
  end
54
29
  end
55
30
 
@@ -65,5 +40,7 @@ class BfriendGenerator < Rails::Generators::Base
65
40
  def generate_migration #after generating the migration, add 'default: false' to status
66
41
  generate "migration", "create_friendships user_id:integer friend_id:integer status:boolean "
67
42
  end
43
+
44
+
68
45
 
69
46
  end
@@ -1,8 +1,5 @@
1
1
 
2
- class Friendship < ApplicationRecord
3
-
2
+ class Friendship < ApplicationRecord
4
3
  belongs_to :user
5
4
  belongs_to :friend, :class_name => 'User'
6
-
7
-
8
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfriend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xfinger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,12 +39,12 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  description: 'Based on Railscasts #163 Self-Referential Association'
42
- email:
43
- - xfinger@gmail.com
42
+ email: xfinger@gmail.com
44
43
  executables: []
45
44
  extensions: []
46
45
  extra_rdoc_files: []
47
46
  files:
47
+ - ".DS_Store"
48
48
  - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
@@ -59,7 +59,6 @@ files:
59
59
  - lib/generators/bfriend/templates/api_controller.rb
60
60
  - lib/generators/bfriend/templates/model.rb
61
61
  - lib/generators/bfriend/templates/ror_controller.rb
62
- - lib/generators/bfriend/tmp.rb
63
62
  homepage: https://github.com/XFinger/bfriend
64
63
  licenses:
65
64
  - MIT
@@ -69,11 +68,12 @@ post_install_message:
69
68
  rdoc_options: []
70
69
  require_paths:
71
70
  - lib
71
+ - lib/generators
72
72
  required_ruby_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: '0'
76
+ version: 2.0.0
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
@@ -1,15 +0,0 @@
1
- has_many :friendships
2
- has_many :received_friendships, class_name: "Friendship", foreign_key: "friend_id"
3
-
4
- has_many :active_friends, -> { where(friendships: { accepted: true}) }, through: :friendships, source: :friend
5
- has_many :received_friends, -> { where(friendships: { accepted: true}) }, through: :received_friendships, source: :user
6
- has_many :pending_friends, -> { where(friendships: { accepted: false}) }, through: :friendships, source: :friend
7
- has_many :requested_friendships, -> { where(friendships: { accepted: false}) }, through: :received_friendships, source: :user
8
-
9
- def friends
10
- active_friends | received_friends
11
- end
12
-
13
- def pending
14
- pending_friends | requested_friendships
15
- end