popular 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTFlYzUwZDA3NTAxOGFiNzcxZmE1YWIyOGJlYzMzODZiNzBlNTU1ZA==
5
+ data.tar.gz: !binary |-
6
+ OWZmNDFlMjhjNTJiMzczMWFjZTExZTNhZDIzZjZiNTA2N2ZiOGUwYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZmI5MGVhMDA1MmFhZmJlMjRiNDQxZjg2MGY2NTJlN2NjN2U0Nzg5NTEwODU4
10
+ MDFmMjI0ZTExY2U1NDZkNDRjYTJiMGYxMDAyYjU1ODE5ZTllMTQyN2E3NjI3
11
+ OWZmZDAwZTFjZjhiOWQwZWIzN2FlZDFlMjQxYTg1MzRiMmY1YWY=
12
+ data.tar.gz: !binary |-
13
+ NDFlNzU4YjY2NmM4YjAwNDRjYjFjZjIyMWExYzI0NWU4YWNiNjljNTkyNTg1
14
+ MWQ0MjEwYjRkZjFmNzJmOTNkYjBjNzQyOGEwNzBhMDI3ZDc2OWEwMzUzYjA2
15
+ MDk0MjcxMzQ2N2U5MGJkYjMyMmIzNjgwYWM0ZTliYmQ4N2FjNjk=
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ addons:
5
+ code_climate:
6
+ repo_token: 961309bcd7fffdccfec595d69b0d054b56308dcc414edad136f2c153bba245f4
7
+ deploy:
8
+ provider: rubygems
9
+ api_key:
10
+ secure: lxiDHlutKFERFmsSzhqoGtVGRk06wQIv3Gp7GnvaYdbZzC2tH35tvW4RFxdSWPU8Fp02M8Qc89gV+T0IbAigFZEVp3F7IN4DM09oJWGJ4G1XKykYV0c5aFrEfcPVs4rzxletQanObqbVZqBj/+pCaGA1WvwqojL9Jg6a/w/LhyE=
11
+ gem: friendly
12
+ on:
13
+ tags: true
14
+ repo: thejchap/friendly
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ rails_version = ENV['RAILS_VERSION'] || 'default'
6
+
7
+ rails = case rails_version
8
+ when 'master'
9
+ { github: 'rails/rails'}
10
+ when 'default'
11
+ '~> 4.0.4'
12
+ else
13
+ "~> #{rails_version}"
14
+ end
15
+
16
+ gem 'rails', rails
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 thejchap
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Popular
2
+ [![Build Status](https://travis-ci.org/thejchap/popular.svg?branch=master)](https://travis-ci.org/thejchap/popular)
3
+ [![Dependency Status](https://gemnasium.com/thejchap/popular.svg)](https://gemnasium.com/thejchap/popular)
4
+
5
+ Popular is a friendship gem designed for Rails/ActiveRecord models.
6
+
7
+ ### THIS IS A VERY YOUNG GEM. YOU HAVE BEEN WARNED
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'popular'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install popular
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/<my-github-username>/popular/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new :spec
5
+
6
+ task default: :spec
@@ -0,0 +1,18 @@
1
+ require "active_record"
2
+
3
+ # Namespace for classes and modules that handle friendship related tasks
4
+ #
5
+ # @author Justin Chapman
6
+ #
7
+ # @since 0.0.1
8
+ module Popular
9
+
10
+ if defined? ActiveRecord::Base
11
+ require "popular/extenders/popular"
12
+ require "popular/friendship"
13
+
14
+ # Extend ActiveRecord with extenders
15
+ ActiveRecord::Base.extend Popular::Extenders::Popular
16
+ end
17
+
18
+ end
@@ -0,0 +1,33 @@
1
+ module Popular
2
+ # Namespace for classes and modules that handle including the library's modules
3
+ module Extenders
4
+
5
+ # Namespace for classes and modules that handle making a given model friendly
6
+ module Popular
7
+
8
+ # Helper method for determining whether or not a model has included
9
+ # the Popular module
10
+ #
11
+ # @return [Boolean] whether or not the including class has included the module
12
+ def popular?
13
+ false
14
+ end
15
+
16
+ # Includes the module in a given class
17
+ #
18
+ # @overload friendable *args
19
+ # @param [Hash] options
20
+ def popular *args
21
+ require 'popular/popular'
22
+ include ::Popular::Popular
23
+
24
+ class_eval do
25
+ def self.popular?
26
+ true
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ module Popular
2
+
3
+ class Friendship < ::ActiveRecord::Base
4
+
5
+ belongs_to :popular_model, polymorphic: true
6
+ belongs_to :friend, polymorphic: true
7
+
8
+ end
9
+
10
+ end
@@ -0,0 +1,41 @@
1
+ module Popular
2
+
3
+ module Popular
4
+
5
+ def self.included base
6
+
7
+ base.class_eval do
8
+
9
+ has_many :friendships, class_name: 'Popular::Friendship', as: :popular_model, dependent: :destroy
10
+ has_many :friends, through: :friendships, source_type: base
11
+
12
+ end
13
+
14
+ end
15
+
16
+ # Adds a friend to an instance's friend's list
17
+ #
18
+ # @param [PopularModel] a popular_model that the instance is not already friends with
19
+ def befriend new_friend
20
+ friendships.create friend: new_friend
21
+ end
22
+
23
+ # Removes a friend from an instance's friend's list
24
+ #
25
+ # @param [PopularModel] a popular_model in this instance's friends list
26
+ def unfriend friend
27
+ friendships.where( friend: friend ).first.destroy
28
+ end
29
+
30
+ # Helper method for finding whether or not the instance is friends with
31
+ # another given popular_model
32
+ #
33
+ # @param [PopularModel] a popular_model
34
+ # @return [Boolean] if the instance has popular_model as a friend
35
+ def friends_with? popular_model
36
+ friendships.where( friend: popular_model ).any?
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ module Popular
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'popular/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "popular"
8
+ spec.version = Popular::VERSION
9
+ spec.authors = ["thejchap"]
10
+ spec.email = ["commonmodestudio@gmail.com"]
11
+ spec.summary = %q{Friendship gem for Rails/ActiveRecord}
12
+ spec.description = %q{Friendship gem for Rails/ActiveRecord. Popular saves time when developing social apps}
13
+ spec.homepage = "http://thejchap.github.io/popular"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 10.2"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ spec.add_development_dependency "sqlite3", "~> 1.3"
25
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.3"
26
+ spec.add_development_dependency "yard", "~> 0.8"
27
+ spec.add_development_dependency "redcarpet", "~> 3.1"
28
+ spec.add_development_dependency "inch", "~> 0.3"
29
+ end
@@ -0,0 +1,32 @@
1
+ shared_examples "a popular model" do
2
+
3
+ describe '.befriend' do
4
+ it 'creates a one way friendship' do
5
+ popular_model.befriend another_popular_model
6
+
7
+ expect( popular_model.friends ).to match_array [another_popular_model]
8
+ end
9
+ end
10
+
11
+ describe '#friends_with?' do
12
+ it 'returns true if a popular_model is friends with a given popular_model' do
13
+ expect( popular_model ).to_not be_friends_with another_popular_model
14
+ end
15
+ it 'returns true if a popular_model is friends with a given popular_model' do
16
+ popular_model.befriend another_popular_model
17
+
18
+ expect( popular_model ).to be_friends_with another_popular_model
19
+ end
20
+ end
21
+
22
+ describe '.unfriend' do
23
+ it 'destroys a friendship' do
24
+ [:befriend, :unfriend].each do |method|
25
+ popular_model.send method, another_popular_model
26
+ end
27
+
28
+ expect( popular_model.friends ).to be_empty
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Popular::Popular do
4
+
5
+ context 'popular user' do
6
+ it 'is popular' do
7
+ expect( PopularModel ).to be_popular
8
+ end
9
+ end
10
+
11
+ context 'un-popular user' do
12
+ it 'is not popular' do
13
+ expect( UnpopularModel ).to_not be_popular
14
+ end
15
+ end
16
+
17
+ it_behaves_like 'a popular model' do
18
+ let ( :popular_model ) { PopularModel.create }
19
+ let ( :another_popular_model ) { PopularModel.create }
20
+ end
21
+
22
+ end
@@ -0,0 +1,36 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require 'sqlite3'
7
+ require 'popular'
8
+
9
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
10
+
11
+ ActiveRecord::Schema.define version: 1 do
12
+
13
+ create_table :friendships do |t|
14
+ t.references :popular_model, polymorphic: true, null: false
15
+ t.references :friend, polymorphic: true, null: false
16
+ end
17
+
18
+ create_table :popular_models
19
+
20
+ end
21
+
22
+ UnpopularModel = Class.new ActiveRecord::Base
23
+
24
+ class PopularModel < ActiveRecord::Base
25
+ popular
26
+ end
27
+
28
+ RSpec.configure do |config|
29
+ config.order = 'random'
30
+ end
31
+
32
+ def clean_database
33
+ [PopularModel, Popular::Friendship].each do |model|
34
+ ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: popular
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - thejchap
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '3.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: inch
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.3'
125
+ description: Friendship gem for Rails/ActiveRecord. Popular saves time when developing
126
+ social apps
127
+ email:
128
+ - commonmodestudio@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .travis.yml
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - lib/popular.rb
141
+ - lib/popular/extenders/popular.rb
142
+ - lib/popular/friendship.rb
143
+ - lib/popular/popular.rb
144
+ - lib/popular/version.rb
145
+ - popular.gemspec
146
+ - spec/popular/popular_model_spec.rb
147
+ - spec/popular/popular_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: http://thejchap.github.io/popular
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.2.2
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Friendship gem for Rails/ActiveRecord
173
+ test_files:
174
+ - spec/popular/popular_model_spec.rb
175
+ - spec/popular/popular_spec.rb
176
+ - spec/spec_helper.rb
177
+ has_rdoc: