Skip to content

Commit

Permalink
Merge pull request #42 from doctolib/refacto-activemodel-attribute
Browse files Browse the repository at this point in the history
Refacto activemodel attribute
  • Loading branch information
giallon committed Sep 15, 2022
2 parents b40a02c + 9cb5b05 commit 27cdb71
Show file tree
Hide file tree
Showing 26 changed files with 674 additions and 223 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ jobs:
include:
- ruby: '3.0'
gemfile: '7.0.0'
couchbase: '6.6.5'
couchbase: '6.6.5'
- ruby: '3.0'
gemfile: '7.0.0'
couchbase: '7.1.0'
- ruby: '2.7'
gemfile: '7.0.0'
couchbase: '7.1.0'
- ruby: '2.6'
gemfile: '5.1.7'
gemfile: '5.2.8.1'
couchbase: '7.1.0'
fail-fast: false
runs-on: ubuntu-20.04
name: ${{ matrix.ruby }} rails-${{ matrix.gemfile }} couchbase-${{ matrix.couchbase }}
name: ${{ matrix.ruby }} rails-${{ matrix.gemfile }} couchbase-${{ matrix.couchbase }}
steps:
- uses: actions/checkout@v2
- run: sudo apt-get update && sudo apt-get install libevent-dev libev-dev python-httplib2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.sw?
.DS_Store
.rbenv-vars
coverage
rdoc
html
Expand Down
5 changes: 4 additions & 1 deletion couchbase-orm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ Gem::Specification.new do |gem|
gem.required_ruby_version = '>= 2.1.0'
gem.require_paths = ["lib"]

gem.add_runtime_dependency 'activemodel', ENV["ACTIVE_MODEL_VERSION"] || '>= 5.0'
gem.add_runtime_dependency 'activemodel', ENV["ACTIVE_MODEL_VERSION"] || '>= 5.2'
gem.add_runtime_dependency 'activerecord', ENV["ACTIVE_MODEL_VERSION"] || '>= 5.2'

gem.add_runtime_dependency 'couchbase'
gem.add_runtime_dependency 'radix', '~> 2.2' # converting numbers to and from any base

gem.add_development_dependency 'rake', '~> 12.2'
gem.add_development_dependency 'rspec', '~> 3.7'
gem.add_development_dependency 'yard', '~> 0.9'
gem.add_development_dependency 'pry'
gem.add_development_dependency 'pry-stack_explorer'
gem.add_development_dependency 'simplecov'

gem.files = `git ls-files`.split("\n")
Expand Down
7 changes: 6 additions & 1 deletion lib/couchbase-orm.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# frozen_string_literal: true, encoding: ASCII-8BIT

require "active_support/lazy_load_hooks"
ActiveSupport.on_load(:i18n) do
I18n.load_path << File.expand_path("couchbase-orm/locale/en.yml", __dir__)
end

module CouchbaseOrm
autoload :Error, 'couchbase-orm/error'
autoload :Connection, 'couchbase-orm/connection'
Expand All @@ -8,7 +13,7 @@ module CouchbaseOrm
autoload :HasMany, 'couchbase-orm/utilities/has_many'

def self.logger
@@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT).tap { |l| l.level = Logger::INFO unless ENV["COUCHBASE_ORM_DEBUG"] }
end

def self.logger=(logger)
Expand Down
11 changes: 6 additions & 5 deletions lib/couchbase-orm/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ def has_and_belongs_to_many(name, **options)
old, new = previous_changes[ref]
adds = (new || []) - (old || [])
subs = (old || []) - (new || [])

update_has_and_belongs_to_many_reverse_association(assoc, adds, true, **options)
update_has_and_belongs_to_many_reverse_association(assoc, subs, false, **options)
update_has_and_belongs_to_many_reverse_association(assoc, adds, true, **options) if adds.any?
update_has_and_belongs_to_many_reverse_association(assoc, subs, false, **options) if subs.any?
end

after_create save_method
Expand Down Expand Up @@ -167,9 +166,11 @@ def update_has_and_belongs_to_many_reverse_association(assoc, keys, is_add, **op
elsif !is_add && index
tab = tab.dup
tab.delete_at(index)
else
next
end
v.__send__(:"#{remote_method}=", tab)
v.__send__(:save!)
v[remote_method] = tab
v.save!
end
end

Expand Down
Loading

0 comments on commit 27cdb71

Please sign in to comment.