Skip to content

Commit

Permalink
Merge pull request #1 from aredotna/scouting/rebase-origin-master
Browse files Browse the repository at this point in the history
Scouting/rebase origin master
  • Loading branch information
LeFnord authored Jan 21, 2021
2 parents d5a9800 + 8ba746c commit 8c5a217
Show file tree
Hide file tree
Showing 47 changed files with 609 additions and 334 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0']
ruby-version: ['2.6', '2.7']
rails-version: ['~> 5.1.7', '~> 5.2.4', '~> 6.0.3', '~> 6.1.1']

steps:
- uses: actions/checkout@v2
Expand All @@ -31,5 +32,10 @@ jobs:
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
env:
RAILS_VERSION: ${{ matrix.rails-version }}
- name: Run tests
run: bundle exec rake
run: bundle exec rake test
# - name: Run rubocop
# run: bundle exec rubocop
# continue-on-error: true
71 changes: 71 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- 'Gemfile'
- 'acts_as_follower.gemspec'
- 'test/dummy30/**/*'
UseCache: true
SuggestExtensions: false
NewCops: enable

#
# *** Layout
#
Layout/LineLength:
Max: 120

Layout/SpaceBeforeBlockBraces:
EnforcedStyle: space
EnforcedStyleForEmptyBraces: space

#
# *** Metrics
#
Metrics/AbcSize:
Max: 27

Metrics/BlockLength:
Max: 35
Exclude:
- 'test/**/*'

Metrics/ClassLength:
Max: 200
Exclude:
- 'test/**/*'

Metrics/CyclomaticComplexity:
Max: 8

Metrics/MethodLength:
Max: 20

Metrics/ModuleLength:
Max: 150

Metrics/ParameterLists:
Max: 4

Metrics/PerceivedComplexity:
Max: 10

#
# *** Naming
#
Naming/VariableNumber:
EnforcedStyle: snake_case

Naming/MethodParameterName:
Enabled: false
#
# *** Style
#
Style/AsciiComments:
Enabled: false

Style/ClassAndModuleChildren:
EnforcedStyle: nested

Style/Documentation:
Enabled: false
37 changes: 37 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-01-21 22:14:46 UTC using RuboCop version 1.8.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'lib/acts_as_follower/follower.rb'

# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/acts_as_follower/follower.rb'

# Offense count: 3
Style/MissingRespondToMissing:
Exclude:
- 'lib/acts_as_follower.rb'
- 'lib/acts_as_follower/followable.rb'
- 'lib/acts_as_follower/follower.rb'

# Offense count: 2
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/acts_as_follower/followable.rb'
- 'lib/acts_as_follower/follower.rb'

Layout/LineLength:
Exclude:
- 'test/acts_as_follower_test.rb'
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ source "http://rubygems.org"

# Specify your gem's dependencies in acts_as_follower.gemspec
gemspec

gem 'activerecord', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
14 changes: 11 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ Main uses would be for Users to follow other Users or for Users to follow Books,

== Installation

=== The master branch supports Rails 4
=== The master branch supports Rails 5

Add the gem to the gemfile:
gem 'acts_as_follower', github: 'tcocca/acts_as_follower', branch: 'master'

Other instructions same as for Rails 4.

=== Rails 4.x support

The first release that support Rails 4 is 0.2.0

Expand All @@ -33,7 +40,7 @@ Add the gem to the gemfile:

or install from the branch

gem "acts_as_follower", :git => 'git://github.com/tcocca/acts_as_follower.git', :branch => 'rails_3'
gem "acts_as_follower", git: 'git://github.com/tcocca/acts_as_follower.git', branch: 'rails_3'

Run the generator:
rails generate acts_as_follower
Expand Down Expand Up @@ -168,7 +175,7 @@ If you only need the number of blocks use the count method provided
book.blocked_followers_count

Unblocking deletes all records of that follow, instead of just the :blocked attribute => false the follow is deleted. So, a user would need to try and follow the book again.
I would like to hear thoughts on this, I may change this to make the follow as :blocked => false instead of deleting the record.
I would like to hear thoughts on this, I may change this to make the follow as blocked: false instead of deleting the record.

The following methods take an optional hash parameter of ActiveRecord options (:limit, :order, etc...)
followers_by_type, followers, blocks
Expand Down Expand Up @@ -230,6 +237,7 @@ Thanks to everyone for their interest and time in committing to making this plug
* arthurgeek (Arthur Zapparoli) - https://github.com/arthurgeek
* james2m (James McCarthy) - https://github.com/james2m
* peterjm (Peter McCracken) - https://github.com/peterjm
* merqlove (Alexander Merkulov) - https://github.com/merqlove

Please let me know if I missed you.

Expand Down
17 changes: 11 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# frozen_string_literal: true

require 'bundler'
Bundler::GemHelper.install_tasks

require 'rake'
require 'rake/testtask'
require 'rdoc/task'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the acts_as_follower gem.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
Expand All @@ -25,13 +24,19 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
end

namespace :rcov do
desc "Generate a coverage report in coverage/"
desc 'Generate a coverage report in coverage/'
task :gen do
sh "rcov --output coverage test/*_test.rb --exclude 'gems/*'"
end

desc "Remove generated coverage files."
desc 'Remove generated coverage files.'
task :clobber do
sh "rm -rdf coverage"
sh 'rm -rdf coverage'
end
end

# rubocop tasks
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)

task default: %i[test rubocop]
9 changes: 6 additions & 3 deletions acts_as_follower.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency 'activerecord', '>= 5.0'

s.add_development_dependency "sqlite3"
s.add_development_dependency "shoulda_create"
s.add_development_dependency "shoulda", ">= 3.5.0"
s.add_development_dependency "factory_girl", ">= 4.2.0"
s.add_development_dependency "rails", "~> 4.0.0"
s.add_development_dependency "shoulda"
s.add_development_dependency "factory_bot"
s.add_development_dependency "rails", ">= 5.0"
s.add_development_dependency "rubocop", ">= 1.0"
end
2 changes: 2 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'acts_as_follower'
23 changes: 22 additions & 1 deletion lib/acts_as_follower.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
require "acts_as_follower/version"
# frozen_string_literal: true

require 'acts_as_follower/version'

module ActsAsFollower
autoload :Follower, 'acts_as_follower/follower'
autoload :Followable, 'acts_as_follower/followable'
autoload :FollowerLib, 'acts_as_follower/follower_lib'
autoload :FollowScopes, 'acts_as_follower/follow_scopes'

def self.setup
@configuration ||= Configuration.new
yield @configuration if block_given?
end

def self.method_missing(method_name, *args, &block)
@configuration.respond_to?(method_name) ? @configuration.send(method_name, *args, &block) : super
end

class Configuration
attr_accessor :custom_parent_classes

def initialize
@custom_parent_classes = []
end
end

setup

require 'acts_as_follower/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
end
29 changes: 18 additions & 11 deletions lib/acts_as_follower/follow_scopes.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
# frozen_string_literal: true

module ActsAsFollower #:nodoc:
module FollowScopes

# returns Follow records where follower is the record passed in.
def for_follower(follower)
where(:follower_id => follower.id,
:follower_type => parent_class_name(follower))
where(follower_id: follower.id, follower_type: parent_class_name(follower))
end

# returns Follow records where followable is the record passed in.
def for_followable(followable)
where(:followable_id => followable.id, :followable_type => parent_class_name(followable))
where(followable_id: followable.id, followable_type: parent_class_name(followable))
end

# returns Follow records where follower_type is the record passed in.
def for_follower_type(follower_type)
where(:follower_type => follower_type)
where(follower_type: follower_type)
end

# returns Follow records where followeable_type is the record passed in.
def for_followable_type(followable_type)
where(:followable_type => followable_type)
where(followable_type: followable_type)
end

# returns Follow records from past 2 weeks with default parameter.
def recent(from)
where(["created_at > ?", (from || 2.weeks.ago).to_s(:db)])
where(['created_at > ?', (from || 2.weeks.ago).to_s(:db)])
end

# returns Follow records in descending order.
def descending
order("follows.created_at DESC")
order('follows.created_at DESC')
end

# returns unblocked Follow records.
def unblocked
where(:blocked => false)
where(blocked: false)
end

# returns blocked Follow records.
def blocked
where(:blocked => true)
where(blocked: true)
end

end
end
Loading

0 comments on commit 8c5a217

Please sign in to comment.