Skip to content

Commit

Permalink
Scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Jan 28, 2018
0 parents commit 4c5ba94
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.gem
gemfiles/*.lock
Gemfile.local
53 changes: 53 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require:
- rubocop-md

AllCops:
Include:
- 'lib/**/*.rb'
- 'lib/**/*.rake'
- 'spec/**/*.rb'
Exclude:
- 'bin/**/*'
- 'gemfiles/**/*'
- 'spec/dummy/**/*'
- 'vendor/**/*'
- 'tmp/**/*'
- 'Rakefile'
- 'Gemfile'
- '*.gemspec'
DisplayCopNames: true
StyleGuideCopsOnly: false
TargetRubyVersion: 2.3

Rails:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/Documentation:
Exclude:
- 'spec/**/*.rb'

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/RegexpLiteral:
Enabled: false

Style/BlockDelimiters:
Exclude:
- 'spec/**/*.rb'

Layout/SpaceInsideStringInterpolation:
EnforcedStyle: no_space

Lint/AmbiguousRegexpLiteral:
Enabled: false

Metrics/LineLength:
Max: 100

Metrics/BlockLength:
Exclude:
- 'spec/**/*.rb'
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sudo: false
language: ruby
rvm:
- 2.5.0

notifications:
email: false

matrix:
fast_finish: true
include:
- rvm: ruby-head
gemfile: gemfiles/railsmaster.gemfile
- rvm: jruby-9.1.0.0
gemfile: gemfiles/jruby.gemfile
- rvm: 2.5.0
gemfile: Gemfile
- rvm: 2.4.3
gemfile: Gemfile
- rvm: 2.3.1
gemfile: gemfiles/activerecord42.gemfile
allow_failures:
- rvm: ruby-head
gemfile: gemfiles/railsmaster.gemfile
- rvm: jruby-9.1.0.0
gemfile: gemfiles/jruby.gemfile
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Change log

## master

[@palkan]: https://github.com/palkan
16 changes: 16 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
source "https://rubygems.org"

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

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

gem 'pry-byebug'
gem 'sqlite3'
gem 'activerecord', '>= 5.0'

local_gemfile = 'Gemfile.local'

if File.exist?(local_gemfile)
eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
end
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Vladimir Dementyev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[![Gem Version](https://badge.fury.io/rb/isolator.svg)](https://badge.fury.io/rb/isolator)
[![Build Status](https://travis-ci.org/palkan/isolator.svg?branch=master)](https://travis-ci.org/palkan/isolator)

# Isolator

Detect non-atomic interactions within DB transactions.

Examples:

```ruby
# HTTP calls within transaction
User.transaction do
user = User.new(user_params)
user.save!
# HTTP API call
PaymentsService.charge!(user)
end

#=> raises Isolator::HTTPError

# background job
User.transaction do
user.update!(confirmed_at: Time.now)
UserMailer.successful_confirmation(user).deliver_later
end

#=> raises Isolator::BackgroundJobError
```

## Installation

Add this line to your application's Gemfile:

```ruby
group :development, :test do
gem "isolator"
end
```

## Usage

TBD

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/isolator.

## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"

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

task default: [:rubocop, :spec]
7 changes: 7 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "isolator"

require "pry"
Pry.start
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
6 changes: 6 additions & 0 deletions gemfiles/activerecord42.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gem 'activerecord', '~> 4.2'
gem 'sqlite3'

gemspec path: '..'
7 changes: 7 additions & 0 deletions gemfiles/jruby.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'activerecord-jdbcsqlite3-adapter', '~> 50.0'
gem 'jdbc-sqlite3'
gem 'activerecord', '~> 5.0.0'

gemspec path: '..'
7 changes: 7 additions & 0 deletions gemfiles/railsmaster.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source 'https://rubygems.org'

gem 'arel', github: 'rails/arel'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'

gemspec path: '..'
28 changes: 28 additions & 0 deletions isolator.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "isolator/version"

Gem::Specification.new do |spec|
spec.name = "isolator"
spec.version = Isolator::VERSION
spec.authors = ["Vladimir Dementyev"]
spec.email = ["[email protected]"]

spec.summary = "Detect non-atomic interactions within DB transactions"
spec.description = "Detect non-atomic interactions within DB transactions"
spec.homepage = "https://github.com/palkan/isolator"
spec.license = "MIT"

spec.required_ruby_version = ">= 2.3.0"

spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rubocop", "~> 0.51"
spec.add_development_dependency "rubocop-md", "~> 0.2"
end
6 changes: 6 additions & 0 deletions lib/isolator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

require "isolator/version"

module Isolator # :nodoc:
end
5 changes: 5 additions & 0 deletions lib/isolator/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Isolator
VERSION = "0.0.1"
end
27 changes: 27 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "active_record"
require "isolator"

begin
require "pry-byebug"
rescue LoadError # rubocop:disable Lint/HandleExceptions
end

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

RSpec.configure do |config|
config.example_status_persistence_file_path = ".rspec_status"
config.filter_run focus: true
config.run_all_when_everything_filtered = true

config.order = :random

config.expect_with :rspec do |c|
c.syntax = :expect
end

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end
end
12 changes: 12 additions & 0 deletions spec/support/active_record_init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "activerecord-jdbc-adapter" if defined? JRUBY_VERSION
require "activerecord-jdbcsqlite3-adapter" if defined? JRUBY_VERSION

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

ActiveRecord::Schema.define do
# Create schema here
end

ActiveRecord::Base.logger = Logger.new(STDOUT) if ENV["LOG"]

0 comments on commit 4c5ba94

Please sign in to comment.