Skip to content

Commit 9dda30f

Browse files
committed
Standardize
1 parent 3df5787 commit 9dda30f

35 files changed

+101
-102
lines changed

Gemfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ gem "appraisal"
99
gem "standardrb"
1010

1111
group :development, :test do
12-
gem 'sqlite3', '~> 1.4.4'
12+
gem "sqlite3", "~> 1.4.4"
1313
# gem 'mysql2'
14-
gem 'pg'
15-
gem 'net-imap'
16-
gem 'net-pop'
17-
gem 'net-smtp'
14+
gem "pg"
15+
gem "net-imap"
16+
gem "net-pop"
17+
gem "net-smtp"
1818
end
1919

2020
# Declare any dependencies that are still in development here instead of in

Rakefile

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
#!/usr/bin/env rake
22
begin
3-
require 'bundler/setup'
3+
require "bundler/setup"
44
rescue LoadError
5-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
66
end
77
begin
8-
require 'rdoc/task'
8+
require "rdoc/task"
99
rescue LoadError
10-
require 'rdoc/rdoc'
11-
require 'rake/rdoctask'
10+
require "rdoc/rdoc"
11+
require "rake/rdoctask"
1212
RDoc::Task = Rake::RDocTask
1313
end
1414

1515
RDoc::Task.new(:rdoc) do |rdoc|
16-
rdoc.rdoc_dir = 'rdoc'
17-
rdoc.title = 'Sequenced'
18-
rdoc.options << '--line-numbers'
19-
rdoc.rdoc_files.include('README.rdoc')
20-
rdoc.rdoc_files.include('lib/**/*.rb')
16+
rdoc.rdoc_dir = "rdoc"
17+
rdoc.title = "Sequenced"
18+
rdoc.options << "--line-numbers"
19+
rdoc.rdoc_files.include("README.rdoc")
20+
rdoc.rdoc_files.include("lib/**/*.rb")
2121
end
2222

2323
Bundler::GemHelper.install_tasks
2424

25-
require 'rake/testtask'
25+
require "rake/testtask"
2626

2727
Rake::TestTask.new(:test) do |t|
28-
t.libs << 'lib'
29-
t.libs << 'test'
30-
t.pattern = 'test/**/*_test.rb'
28+
t.libs << "lib"
29+
t.libs << "test"
30+
t.pattern = "test/**/*_test.rb"
3131
t.verbose = false
3232
end
3333

34-
task :default => :test
34+
task default: :test
3535

3636
namespace :db do
3737
task :create do
3838
# File.expand_path is executed directory of generated Rails app
39-
rakefile = File.expand_path('Rakefile', 'test/dummy/')
39+
rakefile = File.expand_path("Rakefile", "test/dummy/")
4040
command = "rake -f '%s' db:create" % rakefile
4141
sh(command)
4242
end
4343

4444
task :drop do
4545
# File.expand_path is executed directory of generated Rails app
46-
rakefile = File.expand_path('Rakefile', 'test/dummy/')
46+
rakefile = File.expand_path("Rakefile", "test/dummy/")
4747
command = "rake -f '%s' db:drop" % rakefile
4848
sh(command)
4949
end
5050

5151
namespace :test do
5252
task :prepare do
5353
# File.expand_path is executed directory of generated Rails app
54-
rakefile = File.expand_path('Rakefile', 'test/dummy/')
54+
rakefile = File.expand_path("Rakefile", "test/dummy/")
5555
command = "rake -f '%s' db:test:prepare" % rakefile
5656
sh(command)
5757
end

lib/sequenced.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'sequenced/generator'
2-
require 'sequenced/acts_as_sequenced'
1+
require "sequenced/generator"
2+
require "sequenced/acts_as_sequenced"
33

4-
ActiveRecord::Base.send(:include, Sequenced::ActsAsSequenced)
4+
ActiveRecord::Base.send(:include, Sequenced::ActsAsSequenced)

lib/sequenced/acts_as_sequenced.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
require 'active_support/core_ext/hash/slice'
2-
require 'active_support/core_ext/class/attribute_accessors'
1+
require "active_support/core_ext/hash/slice"
2+
require "active_support/core_ext/class/attribute_accessors"
33

44
module Sequenced
55
module ActsAsSequenced
@@ -51,7 +51,7 @@ def acts_as_sequenced(options = {})
5151
options = DEFAULT_OPTIONS.merge(options)
5252
column_name = options[:column]
5353

54-
if sequenced_options.any? {|options| options[:column] == column_name}
54+
if sequenced_options.any? { |options| options[:column] == column_name }
5555
raise(SequencedColumnExists, <<-MSG.squish)
5656
Tried to set #{column_name} as sequenced but there was already a
5757
definition here. Did you accidentally call acts_as_sequenced

lib/sequenced/generator.rb

+11-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def id_set?
2121
end
2222

2323
def skip?
24-
skip && skip.call(record)
24+
skip&.call(record)
2525
end
2626

2727
def next_id
@@ -32,8 +32,11 @@ def next_id
3232

3333
def next_id_in_sequence
3434
start_at = self.start_at.respond_to?(:call) ? self.start_at.call(record) : self.start_at
35-
return start_at unless last_record = find_last_record
36-
max(last_record.send(column) + 1, start_at)
35+
if (last_record = find_last_record)
36+
max(last_record.send(column) + 1, start_at)
37+
else
38+
start_at
39+
end
3740
end
3841

3942
def unique?(id)
@@ -44,7 +47,7 @@ def unique?(id)
4447
end.count == 0
4548
end
4649

47-
private
50+
private
4851

4952
def lock_table
5053
if postgresql?
@@ -54,7 +57,7 @@ def lock_table
5457

5558
def postgresql?
5659
defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
57-
record.class.connection.kind_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
60+
record.class.connection.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
5861
end
5962

6063
def base_relation
@@ -63,9 +66,9 @@ def base_relation
6366

6467
def find_last_record
6568
build_scope(*scope) do
66-
base_relation.
67-
where("#{column.to_s} IS NOT NULL").
68-
order("#{column.to_s} DESC")
69+
base_relation
70+
.where("#{column} IS NOT NULL")
71+
.order("#{column} DESC")
6972
end.first
7073
end
7174

@@ -78,6 +81,5 @@ def build_scope(*columns)
7881
def max(*values)
7982
values.to_a.max
8083
end
81-
8284
end
8385
end

sequenced.gemspec

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ $:.push File.expand_path("../lib", __FILE__)
22
require "sequenced/version"
33

44
Gem::Specification.new do |s|
5-
s.name = "sequenced"
6-
s.version = Sequenced::VERSION
7-
s.authors = ["Derrick Reimer"]
8-
s.licenses = ['MIT']
9-
s.email = ["[email protected]"]
10-
s.homepage = "https://github.com/derrickreimer/sequenced"
11-
s.summary = "Generate scoped sequential IDs for ActiveRecord models"
5+
s.name = "sequenced"
6+
s.version = Sequenced::VERSION
7+
s.authors = ["Derrick Reimer"]
8+
s.licenses = ["MIT"]
9+
s.email = ["[email protected]"]
10+
s.homepage = "https://github.com/derrickreimer/sequenced"
11+
s.summary = "Generate scoped sequential IDs for ActiveRecord models"
1212
s.description = "Sequenced is a gem that generates scoped sequential IDs for ActiveRecord models."
1313

1414
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }

test/acts_as_sequenced_test.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require "test_helper"
22

33
# Test Models:
44
#
@@ -35,29 +35,29 @@ class ActsAsSequencedTest < ActiveSupport::TestCase
3535

3636
test "lambda start_at" do
3737
account = Account.create
38-
product = Product.create(:account_id => account.id)
38+
product = Product.create(account_id: account.id)
3939
assert_equal 3, product.sequential_id
4040

41-
another_product = Product.create(:account_id => account.id)
41+
another_product = Product.create(account_id: account.id)
4242
assert_equal 4, another_product.sequential_id
4343
end
4444

4545
test "custom start_at with populated table" do
4646
account = Account.create
47-
account.invoices.create(:sequential_id => 1)
47+
account.invoices.create(sequential_id: 1)
4848
invoice = account.invoices.create
4949
assert_equal 1000, invoice.sequential_id
5050
end
5151

5252
test "sequential id increment" do
5353
question = Question.create
54-
question.answers.create(:sequential_id => 10)
54+
question.answers.create(sequential_id: 10)
5555
another_answer = question.answers.create
5656
assert_equal 11, another_answer.sequential_id
5757
end
5858

5959
test "default scope" do
60-
Subscription.create(:sequential_id => 1)
60+
Subscription.create(sequential_id: 1)
6161
subscription = Subscription.create
6262
assert_equal 2, subscription.sequential_id
6363
end
@@ -93,8 +93,8 @@ class ActsAsSequencedTest < ActiveSupport::TestCase
9393

9494
test "manually setting sequential id" do
9595
question = Question.create
96-
answer = question.answers.build(:sequential_id => 10)
97-
another_answer = question.answers.build(:sequential_id => 10)
96+
answer = question.answers.build(sequential_id: 10)
97+
another_answer = question.answers.build(sequential_id: 10)
9898
answer.save
9999
another_answer.save
100100

@@ -104,23 +104,23 @@ class ActsAsSequencedTest < ActiveSupport::TestCase
104104

105105
test "model with a default scope for sorting" do
106106
question = Question.create
107-
(1..3).each { |id| question.comments.create(:sequential_id => id) }
107+
(1..3).each { |id| question.comments.create(sequential_id: id) }
108108
comment = question.comments.create
109109
assert_equal 4, comment.sequential_id
110110
end
111111

112112
test "multi-column scopes" do
113-
Email.create(:emailable_id => 1, :emailable_type => "User", :sequential_id => 2)
114-
Email.create(:emailable_id => 1, :emailable_type => "Question", :sequential_id => 3)
115-
email = Email.create(:emailable_id => 1, :emailable_type => "User")
113+
Email.create(emailable_id: 1, emailable_type: "User", sequential_id: 2)
114+
Email.create(emailable_id: 1, emailable_type: "Question", sequential_id: 3)
115+
email = Email.create(emailable_id: 1, emailable_type: "User")
116116
assert_equal 3, email.sequential_id
117117
end
118118

119119
test "skip option" do
120-
rating = Rating.create(:comment_id => 1, :score => 1)
120+
rating = Rating.create(comment_id: 1, score: 1)
121121
assert_equal 1, rating.sequential_id
122122

123-
rating = Rating.create(:comment_id => 1, :score => 0)
123+
rating = Rating.create(comment_id: 1, score: 0)
124124
assert_nil rating.sequential_id
125125
end
126126

test/concurrency_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'test_helper'
1+
require "test_helper"
22

33
# Test Models:
44
#
@@ -20,7 +20,7 @@
2020
# NOT NULL constraint on sequential_id,
2121
# UNIQUE constraint on sequential_id within concurrent_burrow_id scope
2222

23-
if ENV['DB'] == 'postgresql'
23+
if ENV["DB"] == "postgresql"
2424
class ConcurrencyTest < ActiveSupport::TestCase
2525
self.use_transactional_tests = false
2626

test/dummy/Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Add your own tasks in files placed in lib/tasks ending in .rake,
33
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
44

5-
require File.expand_path('../config/application', __FILE__)
5+
require File.expand_path("../config/application", __FILE__)
66

77
Dummy::Application.load_tasks

test/dummy/app/models/address.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Address < ActiveRecord::Base
22
belongs_to :account
3-
acts_as_sequenced :scope => :account_id
3+
acts_as_sequenced scope: :account_id
44
end

test/dummy/app/models/answer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Answer < ActiveRecord::Base
22
belongs_to :question
3-
acts_as_sequenced :scope => :question_id
3+
acts_as_sequenced scope: :question_id
44
end

test/dummy/app/models/comment.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Comment < ActiveRecord::Base
22
belongs_to :question
3-
acts_as_sequenced :scope => :question_id
4-
3+
acts_as_sequenced scope: :question_id
4+
55
def self.default_scope
66
order("question_id ASC")
77
end

test/dummy/app/models/email.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Email < ActiveRecord::Base
2-
belongs_to :emailable, :polymorphic => true
3-
acts_as_sequenced :scope => [:emailable_id, :emailable_type]
2+
belongs_to :emailable, polymorphic: true
3+
acts_as_sequenced scope: [:emailable_id, :emailable_type]
44
end

test/dummy/app/models/invoice.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Invoice < ActiveRecord::Base
22
belongs_to :account
3-
acts_as_sequenced :scope => :account_id, :start_at => 1000
3+
acts_as_sequenced scope: :account_id, start_at: 1000
44
end

test/dummy/app/models/order.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Order < ActiveRecord::Base
22
belongs_to :account
3-
acts_as_sequenced :scope => :non_existent_column
3+
acts_as_sequenced scope: :non_existent_column
44
end

test/dummy/app/models/product.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Product < ActiveRecord::Base
22
belongs_to :account
3-
acts_as_sequenced :scope => :account_id, :start_at => lambda { |r| r.computed_start_value }
4-
3+
acts_as_sequenced scope: :account_id, start_at: lambda { |r| r.computed_start_value }
4+
55
def computed_start_value
66
1 + 2
77
end

test/dummy/app/models/rating.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Rating < ActiveRecord::Base
2-
acts_as_sequenced :scope => :comment_id, :skip => lambda { |r| r.score == 0 }
2+
acts_as_sequenced scope: :comment_id, skip: lambda { |r| r.score == 0 }
33
end

test/dummy/app/models/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class User < ActiveRecord::Base
22
belongs_to :account
3-
acts_as_sequenced :scope => :account_id, :column => :custom_sequential_id
3+
acts_as_sequenced scope: :account_id, column: :custom_sequential_id
44
end

test/dummy/app/models/werewolf.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
class Werewolf < Monster
2-
end
2+
end

test/dummy/app/models/with_custom_primary_key.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ class WithCustomPrimaryKey < ActiveRecord::Base
22
self.primary_key = :legacy_id
33

44
belongs_to :account
5-
acts_as_sequenced :scope => :account_id
5+
acts_as_sequenced scope: :account_id
66
end

test/dummy/app/models/zombie.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
class Zombie < Monster
2-
end
2+
end

test/dummy/config.ru

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# This file is used by Rack-based servers to start the application.
22

3-
require ::File.expand_path('../config/environment', __FILE__)
3+
require ::File.expand_path("../config/environment", __FILE__)
44
run Dummy::Application

0 commit comments

Comments
 (0)