Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Ruby

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

strategy:
matrix:
ruby:
- '3.3.5'
- '3.2.5'
rails:
- '7.2.1.2'
- '6.1.7.10'

steps:
- uses: actions/checkout@v4
- name: Configure Dependencies
run: |
echo "gem 'rails', '${{ matrix.rails }}'" >> Gemfile
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run Specs
run: bundle exec rake spec
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
/pkg/
/spec/reports/
/tmp/
/gemfiles/*.gemfile.lock
22 changes: 0 additions & 22 deletions .rubocop.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

54 changes: 0 additions & 54 deletions Appraisals

This file was deleted.

6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in active_record-sequence.gemspec
gemspec

gem "rake"
gem "rspec"
gem "bundler"
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ which will create a git tag for the version, push git commits and tags, and push
file to [rubygems.org](https://rubygems.org).


We test this gem against different versions of `ActiveRecord` using [appraisal](https://github.com/thoughtbot/appraisal) gem.
To regenerate gemfiles run:

$ appraisal install

To run specs against all versions:

$ appraisal rake spec

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bolshakov/active_record-sequence.
Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

Expand Down
38 changes: 16 additions & 22 deletions active_record-sequence.gemspec
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'active_record/sequence/version'
require "active_record/sequence/version"

Gem::Specification.new do |spec|
spec.name = 'active_record-sequence'
spec.version = ActiveRecord::Sequence::VERSION
spec.authors = ['Tëma Bolshakov']
spec.email = ['[email protected]']
spec.license = "MIT"
spec.name = "active_record-sequence"
spec.version = ActiveRecord::Sequence::VERSION
spec.authors = ["Tëma Bolshakov"]
spec.email = ["[email protected]"]
spec.license = "MIT"

spec.summary = "Provide access to PostgreSQL's sequences"
spec.description = "Provide access to PostgreSQL's sequences"
spec.homepage = 'https://github.com/bolshakov/active_record-sequence'
spec.summary = "Provide access to PostgreSQL's sequences"
spec.description = "Provide access to PostgreSQL's sequences"
spec.homepage = "https://github.com/bolshakov/active_record-sequence"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency 'activerecord', '>= 4.2.11', '<= 6.0.0.beta1'
spec.add_runtime_dependency 'pg'

spec.add_development_dependency 'appraisal', '2.1.0'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake', '11.3.0'
spec.add_development_dependency 'rspec', '3.5.0'
spec.add_development_dependency 'rubocop', '0.64.0'
spec.add_runtime_dependency "activerecord"
spec.add_runtime_dependency "pg"
end
8 changes: 0 additions & 8 deletions gemfiles/rails_4.2.11.gemfile

This file was deleted.

8 changes: 0 additions & 8 deletions gemfiles/rails_5.2.2.gemfile

This file was deleted.

30 changes: 15 additions & 15 deletions lib/active_record/sequence.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'active_record'
require 'active_record/sequence/version'
require 'active_record/sequence/error'
require 'active_support/core_ext/module/delegation'
require "active_record"
require "active_record/sequence/version"
require "active_record/sequence/error"
require "active_support/core_ext/module/delegation"

module ActiveRecord
# Usage
Expand All @@ -11,11 +11,11 @@ module ActiveRecord
# sequence.next #=> 2
#
class Sequence
autoload :SequenceSQLBuilder, 'active_record/sequence/sequence_sql_builder'
autoload :SequenceSQLBuilder, "active_record/sequence/sequence_sql_builder"

class << self
CREATE_ERRORS = {
'PG::DuplicateTable' => ActiveRecord::Sequence::AlreadyExist,
"PG::DuplicateTable" => ActiveRecord::Sequence::AlreadyExist
}.freeze
# Create sequence
# @param name [String]
Expand Down Expand Up @@ -44,13 +44,13 @@ def create(name, options = {})
end

DROP_ERRORS = {
'PG::UndefinedTable' => NotExist,
"PG::UndefinedTable" => NotExist
}.freeze

# @param name [String]
# @return [void]
def drop(name)
drop_sql = format('DROP SEQUENCE %s', name)
drop_sql = format("DROP SEQUENCE %s", name)
handle_postgres_errors(DROP_ERRORS) do
with_connection do |connection|
connection.execute(drop_sql)
Expand Down Expand Up @@ -83,27 +83,27 @@ def initialize(name)
end

NEXT_ERRORS = {
'PG::ObjectNotInPrerequisiteState' => StopIteration,
'PG::SequenceGeneratorLimitExceeded' => StopIteration,
'PG::UndefinedTable' => ActiveRecord::Sequence::NotExist,
"PG::ObjectNotInPrerequisiteState" => StopIteration,
"PG::SequenceGeneratorLimitExceeded" => StopIteration,
"PG::UndefinedTable" => ActiveRecord::Sequence::NotExist
}.freeze

# @return [Integer]
def next
next_sql = 'SELECT nextval(%s)'.freeze
next_sql = "SELECT nextval(%s)".freeze
handle_postgres_errors(NEXT_ERRORS) do
execute(next_sql, name)
end
end

PEEK_ERRORS = {
'PG::ObjectNotInPrerequisiteState' => ActiveRecord::Sequence::CurrentValueUndefined,
'PG::UndefinedTable' => ActiveRecord::Sequence::NotExist,
"PG::ObjectNotInPrerequisiteState" => ActiveRecord::Sequence::CurrentValueUndefined,
"PG::UndefinedTable" => ActiveRecord::Sequence::NotExist
}.freeze

# @return [Integer]
def peek
current_sql = 'SELECT currval(%s)'.freeze
current_sql = "SELECT currval(%s)".freeze
handle_postgres_errors(PEEK_ERRORS) do
execute(current_sql, name)
end
Expand Down
14 changes: 7 additions & 7 deletions lib/active_record/sequence/sequence_sql_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SequenceSQLBuilder

def initialize(name, options = {})
@options = options
@parts = [format('CREATE SEQUENCE %s', name)]
@parts = [format("CREATE SEQUENCE %s", name)]
end

def to_sql
Expand All @@ -17,29 +17,29 @@ def to_sql
configure_max_value
configure_start_value
configure_cycle
parts.join(' ')
parts.join(" ")
end

private

def configure_increment
parts << format('INCREMENT BY %s', options[:increment]) if options[:increment]
parts << format("INCREMENT BY %s", options[:increment]) if options[:increment]
end

def configure_min_value
parts << format('MINVALUE %s', options[:min]) if options[:min]
parts << format("MINVALUE %s", options[:min]) if options[:min]
end

def configure_max_value
parts << format('MAXVALUE %s', options[:max]) if options[:max]
parts << format("MAXVALUE %s", options[:max]) if options[:max]
end

def configure_start_value
parts << format('START %s', options[:start]) if options[:start]
parts << format("START %s", options[:start]) if options[:start]
end

def configure_cycle
parts << (options.fetch(:cycle, false) ? 'CYCLE' : 'NO CYCLE')
parts << (options.fetch(:cycle, false) ? "CYCLE" : "NO CYCLE")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_record/sequence/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveRecord
class Sequence
VERSION = '0.3.0'.freeze
VERSION = "0.3.0".freeze
end
end
Loading