Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatability with Rails 5.2's ActiveModel::Dirty #19

Merged
merged 9 commits into from
Dec 20, 2018
Merged
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
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AllCops:
Exclude:
- modis.gemspec
- vendor/**/*
- gemfiles/**/*

LineLength:
Enabled: false
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.1
2.5.3
25 changes: 19 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
language: ruby

sudo: false

cache: bundler

services:
- redis-server
language: ruby
- redis-server

rvm:
- 2.2.4
- 2.3.0
- 2.4.0
- jruby-9.1.9.0
- 2.3.8
- 2.4.5
- 2.5.3
- jruby-9.1.17.0
- jruby-9.2.5.0

gemfile:
- gemfiles/rails_42.gemfile
- gemfiles/rails_50.gemfile
- gemfiles/rails_51.gemfile
- gemfiles/rails_52.gemfile

env:
global:
secure: LrTz0Pq2ibNZuKDhdzcrvEUSNxUpPopEq9aJeCxy3UpV0v4vpHBtWV0S6zofvf98g/RkZ6cGI1u+0H578dHgE6pWTo+iR8LAwqPKofrFIWRkeo+M77Vs5swahb3mQyPOcig1hfVWDm25MsojePYm70eBIcBU55NWImtdePXfiU0=
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Unreleased

- Drop support for any Ruby < 2.3 and Rails < 4.2.
- Add support for Rails 5.2
- Resolve some Rubocop lint violations
- Test combinations of Ruby and Rails versions in CI

## v2.1.0

- Add `enable_all_index` option to allow disabling the `all` keys. [#7](https://github.com/ileitch/modis/pull/7)
Expand Down
14 changes: 0 additions & 14 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,4 @@

source 'https://rubygems.org'

gem 'rake'
gem 'rspec'

platform :mri do
gem 'cane'
gem 'codeclimate-test-reporter', require: nil
gem 'rubocop', '0.61.1', require: false
gem 'simplecov', require: false
end

platform :mri_21 do
gem 'stackprof'
end

gemspec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ActiveModel + Redis with the aim to mimic ActiveRecord where possible.

## Requirements

Modis supports CRuby 2.2.2+ and jRuby 9k+
Modis supports any actively supported Ruby and Ruby on Rails versions. As of 2018-12-19, that means CRuby 2.3+ and jRuby 9k+, as well as Rails 4.2+.

## Installation

Expand Down
8 changes: 8 additions & 0 deletions gemfiles/rails_42.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activemodel', '~> 4.2.0'
gem 'activesupport', '~> 4.2.0'

gemspec path: '../'
8 changes: 8 additions & 0 deletions gemfiles/rails_50.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activemodel', '~> 5.0.0'
gem 'activesupport', '~> 5.0.0'

gemspec path: '../'
8 changes: 8 additions & 0 deletions gemfiles/rails_51.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activemodel', '~> 5.1.0'
gem 'activesupport', '~> 5.1.0'

gemspec path: '../'
8 changes: 8 additions & 0 deletions gemfiles/rails_52.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'activemodel', '~> 5.2.0'
gem 'activesupport', '~> 5.2.0'

gemspec path: '../'
12 changes: 5 additions & 7 deletions lib/modis/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def self.included(base)

module ClassMethods
def bootstrap_attributes(parent = nil)
attr_reader :attributes

class << self
attr_accessor :attributes, :attributes_with_defaults
end
Expand Down Expand Up @@ -73,6 +71,10 @@ def #{name}=(value)
end
end

def attributes
@modis_attributes
end

def assign_attributes(hash)
hash.each do |k, v|
setter = "#{k}="
Expand All @@ -96,12 +98,8 @@ def set_sti_type
write_attribute(:type, self.class.name)
end

def reset_changes
@changed_attributes = nil
end

def apply_defaults
@attributes = Hash[self.class.attributes_with_defaults]
@modis_attributes = Hash[self.class.attributes_with_defaults]
end
end
end
2 changes: 1 addition & 1 deletion lib/modis/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize(record = nil, options = {})
apply_defaults
set_sti_type
assign_attributes(record) if record
reset_changes
changes_applied

return unless options.key?(:new_record)

Expand Down
2 changes: 1 addition & 1 deletion lib/modis/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def create_or_update(args = {})
future = persist

if future && (future == :unchanged || future.value == 'OK')
reset_changes
changes_applied
@new_record = false
true
else
Expand Down
13 changes: 11 additions & 2 deletions modis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_runtime_dependency 'activemodel', ['>= 3.0', '< 5.2']
gem.add_runtime_dependency 'activesupport', ['>= 3.0', '< 5.2']
gem.required_ruby_version = ">= 2.3.0"

gem.add_runtime_dependency 'activemodel', ['>= 4.2']
gem.add_runtime_dependency 'activesupport', ['>= 4.2']
gem.add_runtime_dependency 'redis', '>= 3.0'
gem.add_runtime_dependency 'hiredis', '>= 0.5'
gem.add_runtime_dependency 'connection_pool', '>= 2'
Expand All @@ -30,4 +32,11 @@ Gem::Specification.new do |gem|
else
gem.add_runtime_dependency 'msgpack', '>= 0.5'
end

gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'codeclimate-test-reporter'
gem.add_development_dependency 'cane'
gem.add_development_dependency 'rubocop', '0.61.1'
gem.add_development_dependency 'simplecov'
end