Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
73c9afd
make fallthrough accessors compatible with ruby 3
doits Jul 23, 2021
2d24acb
run ci with ruby 3, too
doits Jul 25, 2021
7970ee4
Release 1.1.3
shioyama Aug 6, 2021
b9a70f2
Add missing changelog entry
shioyama Sep 14, 2021
366352a
Clearly distinguish backend classes from their configured subclasses
shioyama Sep 23, 2021
a14c308
Bump version to 3.2.0.alpha
shioyama Sep 23, 2021
e536866
Accept passing configured backend class as third argument to setup
shioyama Sep 23, 2021
707ed92
Add inline docs mentioning optional third argument
shioyama Sep 23, 2021
968e4c1
Extract defining after_destroy callback into class method
shioyama Sep 23, 2021
b13e596
Extract defining save callbacks into class method
shioyama Sep 23, 2021
9c54414
Fix indenting
shioyama Sep 23, 2021
f93309c
Extract defining association into backend class method
shioyama Sep 23, 2021
da9de51
Extract defining initialize_dup into class method
shioyama Sep 23, 2021
4b1659b
Sequel KeyValue setup block cleanup
shioyama Sep 23, 2021
0428a48
Use backend_class everywhere
shioyama Sep 23, 2021
fbeb7b0
Add missing inline docs
shioyama Sep 23, 2021
b5d347a
Pass model class to backend class methods
shioyama Sep 23, 2021
f218c7c
Add Sequel querying integration spec
shioyama Sep 25, 2021
a6c7eaf
Fix handling of Sequel::SQL::Expression in KeyValue backend
shioyama Sep 25, 2021
72959de
Expression -> ComplexExpression
shioyama Sep 25, 2021
98c3de2
Remover Ruby 2.5 from build
shioyama Sep 26, 2021
7cbca64
Add ColumnFallback plugin
shioyama Apr 9, 2021
c622cdb
Release 1.2.0
shioyama Sep 26, 2021
d0a7065
Fix changelog
shioyama Sep 26, 2021
6eec8a8
Refactor ColumnFallback plugin
shioyama Sep 27, 2021
cf6bbf4
Release 1.2.1
shioyama Sep 27, 2021
61a915e
Remove released entry from unreleased section
shioyama Oct 1, 2021
e2e58b1
Simplify Fallbacks plugin
shioyama Oct 1, 2021
3d0ea30
Update changelog
shioyama Oct 1, 2021
893b31f
Fix Seuqel container op in Sequel
shioyama Oct 3, 2021
42c5b2a
Add failing test for Marshal.dump
shioyama Feb 5, 2021
3c29f4e
Repalce Hash with named backends class
shioyama Feb 5, 2021
ae05209
Add equality operator for Mobility::Backend
shioyama Mar 19, 2021
fc1d77a
Don't dump cached backends
shioyama Oct 3, 2021
30529fd
Release 1.2.2
shioyama Oct 3, 2021
b687bca
Add missing changelog entry
shioyama Oct 3, 2021
68ead91
Move #531 from unreleased to 1.2.2 in changelog
shioyama Oct 3, 2021
98383ae
Simplify AR PgHash backend
shioyama Oct 5, 2021
8873ccb
Bump to 1.3.0.alpha
shioyama Oct 7, 2021
bfc5506
Fix broken version
shioyama Oct 8, 2021
14d2ab9
Add unreleased PR
shioyama Oct 17, 2021
a5292e1
fix passing wrong options to super in fallbacks plugin
doits Oct 21, 2021
00407b1
Rename accessor_options to kwargs
shioyama Oct 25, 2021
7b4d4eb
Release 1.2.3
shioyama Oct 25, 2021
c818900
Add 1-1, 1-2 branches
shioyama Oct 25, 2021
de0d3e9
Support primary keys other then :id on model classes
Oct 26, 2021
05f8379
Update changelog
shioyama Nov 3, 2021
15be6e8
Fix fallbacks performance regression
shioyama Nov 17, 2021
9a54517
Release 1.2.4
shioyama Nov 28, 2021
f3bd05a
Avoid referencing ActiveRecord::Base
shioyama Dec 3, 2021
89cf655
Release 1.2.5
shioyama Dec 4, 2021
389fc67
Remove installation step for MySQL
shioyama Feb 16, 2022
967c92f
Handle attribute_method_matchers rename
shioyama Feb 16, 2022
46a5ea5
Test against Rails 7.0
shioyama Feb 16, 2022
4bf96b7
Update changelog
shioyama Feb 16, 2022
b678b1d
clean up and refactor active record container backend
doits Nov 5, 2021
87a3a98
refactor spec to match other spec style
doits Nov 5, 2021
d0a517a
updates after review
doits Dec 2, 2021
d75c88d
add spec about removing empty locale hash after last attribute is del…
doits Dec 2, 2021
73ca1be
Add changelog entry
shioyama Feb 28, 2022
cfba956
Require mfa on rubygems
shioyama Nov 17, 2021
c5ee5df
Add bug_tracker_uri
shioyama Nov 17, 2021
7777dd4
Update cert
shioyama Mar 2, 2022
7683433
Release 1.2.6
shioyama Mar 2, 2022
2767e9b
Avoid querying same attribute more than once
shioyama Jun 18, 2022
60fdeaf
Avoid querying same attribute more than once (Sequel)
shioyama Jun 18, 2022
10fd352
Release 1.2.7
shioyama Jun 18, 2022
b3d8806
Fix issues with subclassing, such as when using ActiveRecord STI.
mrbrdo Apr 14, 2022
ca9f048
add failing test for #566
mrbrdo May 3, 2022
9ec2534
Release 1.2.8
shioyama Jun 18, 2022
93f4c47
Update fallthrough_accessor regex to allow for ISO 639-2 codes
phil-allcock Feb 1, 2022
dbabf48
Update test to check ISO 639-2 (3 character) language code
shioyama Jun 19, 2022
b342074
Update changelog
shioyama Jun 19, 2022
516e19f
Add regression test for #513 with select
shioyama Jun 24, 2022
8af0306
Check that class responds to mobility_attribute?
borisrorsvort Jun 22, 2022
c0e4296
Release 1.2.9
shioyama Jun 24, 2022
afeb067
Add column_fallback to Mobility initializer
fluke Aug 12, 2022
ff509a2
change translation classes to be destroyed
peter-tran-goldenowl Jul 2, 2021
c627349
Add failing test for Marshal.dump
shioyama Feb 5, 2021
b98b464
Give backend subclasses a unique name so they can be marshalled
shioyama Mar 19, 2021
ac11052
Add OriginalColumn backend (AR only)
shioyama Apr 9, 2021
d594a14
Remove unnecessary arel/relation stuff
shioyama Apr 9, 2021
0c1e472
Merge branch 'master' into 1.2.9merge
steven-hoang-goldenowl Dec 5, 2022
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
76 changes: 67 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ on:
push:
branches:
- master
- 1-2
- 1-1
- 1-0
- 0-8
pull_request:
branches:
- master
- 1-2
- 1-1
- 1-0
- 0-8

Expand All @@ -21,6 +25,7 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.0'
- '2.7'
- '2.6'
database:
Expand All @@ -40,11 +45,17 @@ jobs:
version: '6.0'
- name: 'active_record'
version: '6.1'
- name: 'active_record'
version: '7.0'
- name: 'sequel'
version: '5'
experimental: [false]
feature: ['unit']
include:
- ruby: '3.0'
feature: 'unit'
orm:
experimental: false
- ruby: '2.7'
feature: 'unit'
orm:
Expand All @@ -53,15 +64,45 @@ jobs:
feature: 'unit'
orm:
experimental: false
- ruby: '2.5'
feature: 'unit'
- ruby: '3.0'
feature: 'rails'
orm:
name: 'active_record'
version: '7.0'
database: 'sqlite3'
experimental: false
- ruby: '3.0'
feature: 'performance'
experimental: false
- ruby: '3.0'
feature: 'i18n_fallbacks'
experimental: false
- ruby: '3.0'
database: 'sqlite3'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '3.0'
database: 'mysql'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '3.0'
database: 'postgres'
feature: 'unit'
orm:
name: 'active_record'
version: 'edge'
experimental: true
- ruby: '2.7'
feature: 'rails'
orm:
name: 'active_record'
version: '6.1'
version: '7.0'
database: 'sqlite3'
experimental: false
- ruby: '2.7'
Expand All @@ -75,27 +116,47 @@ jobs:
feature: 'unit'
orm:
name: 'active_record'
version: '7.0'
version: 'edge'
experimental: true
- ruby: '2.7'
database: 'mysql'
feature: 'unit'
orm:
name: 'active_record'
version: '7.0'
version: 'edge'
experimental: true
- ruby: '2.7'
database: 'postgres'
feature: 'unit'
orm:
name: 'active_record'
version: '7.0'
version: 'edge'
experimental: true
exclude:
- ruby: '2.6'
orm:
name: 'active_record'
version: '7.0'
- ruby: '2.7'
orm:
name: 'active_record'
version: '4.2'
- ruby: '3.0'
orm:
name: 'active_record'
version: '4.2'
- ruby: '3.0'
orm:
name: 'active_record'
version: '5.0'
- ruby: '3.0'
orm:
name: 'active_record'
version: '5.1'
- ruby: '3.0'
orm:
name: 'active_record'
version: '5.2'
env:
DB: ${{ matrix.database }}
BUNDLE_JOBS: 4
Expand Down Expand Up @@ -133,9 +194,6 @@ jobs:
- name: Install Postgres
run: sudo apt-get install libpq-dev postgresql-client -y
if: matrix.database == 'postgres'
- name: Install MySQL
run: sudo apt-get install libmysqlclient-dev mysql-client -y
if: matrix.database == 'mysql'
- id: cache-bundler
uses: actions/cache@v2
with:
Expand Down
77 changes: 75 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,84 @@
# Mobility Changelog

## Unreleased
- Assign blank values in pg hash backends
([#516](https://github.com/shioyama/mobility/pull/516))

- Fix ActiveRecord JSONB blank values
([#536](https://github.com/shioyama/mobility/pull/536))
- Support primary keys other then :id on model classes
([#542](https://github.com/shioyama/mobility/pull/542))
- Clean up and refactor container backend
([#543](https://github.com/shioyama/mobility/pull/543)),
thanks [doits](https://github.com/doits)!
- Update fallthrough_accessor regex to allow for ISO 639-2 codes
([#580](https://github.com/shioyama/mobility/pull/580))
thanks [phil-allcock](https://github.com/phil-allcock)!

## 1.2

### 1.2.9
- Fix missing method `mobility_attribute?` on Rails 7
([#582](https://github.com/shioyama/mobility/pull/582) and
[#584](https://github.com/shioyama/mobility/pull/584))

### 1.2.8
- Fix issues with subclassing, such as when using AR STI,
fixes [#566](https://github.com/shioyama/mobility/issues/566)
([#568](https://github.com/shioyama/mobility/pull/568))
- Handle `attribute_method_matchers` rename (part of
[#560](https://github.com/shioyama/mobility/pull/560))

### 1.2.7
- Do not query same attribute more than once, fixes
[#564](https://github.com/shioyama/mobility/pull/578)
([#577](https://github.com/shioyama/mobility/pull/577))

### 1.2.6
- Require mfa on rubygems
([#545](https://github.com/shioyama/mobility/pull/545))

### 1.2.5
- Avoid referencing ActiveRecord::Base
([#550](https://github.com/shioyama/mobility/pull/550))

### 1.2.4
- Fix fallbacks performance regression
([#548](https://github.com/shioyama/mobility/pull/548))

### 1.2.3
- Fix passing wrong options to super in fallbacks plugin
([#539](https://github.com/shioyama/mobility/pull/539))

### 1.2.2
- Make models work with `Marshal.dump`
([#532](https://github.com/shioyama/mobility/pull/532))
- Fix Sequel container op in Sequel
([#533](https://github.com/shioyama/mobility/pull/533))
- Simplify Fallbacks plugin
([#531](https://github.com/shioyama/mobility/pull/531))

### 1.2.1
- Refactor ColumnFallback plugin
([#530](https://github.com/shioyama/mobility/pull/530))

### 1.2.0
- Add ColumnFallback plugin
([#512](https://github.com/shioyama/mobility/pull/512))
- Fix Sequel querying on untranslated attributes in `i18n` block
([#529](https://github.com/shioyama/mobility/pull/529))
- Allow passing configured backend class as third argument to setup
([#528](https://github.com/shioyama/mobility/pull/528))
- Clearly distinguish backend classes from their configured subclasses
([#527](https://github.com/shioyama/mobility/pull/527))

## 1.1

### 1.1.3
- Do not swallow keyword args on ruby 3 in fallthrough accessors
([#520](https://github.com/shioyama/mobility/pull/520)) thanks
[doits](https://github.com/doits)!
- Assign blank values in pg hash backends
([#516](https://github.com/shioyama/mobility/pull/516))

### 1.1.2
- Check whether class responds to mobility_attribute?
([#515](https://github.com/shioyama/mobility/pull/515))
Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ orm, orm_version = ENV['ORM'], ENV['ORM_VERSION']
group :development, :test do
case orm
when 'active_record'
orm_version ||= '6.1'
orm_version ||= '7.0'
case orm_version
when '4.2', '5.0', '5.1', '5.2', '6.0', '6.1'
when '4.2', '5.0', '5.1', '5.2', '6.0', '6.1', '7.0'
gem 'activerecord', "~> #{orm_version}.0"
when '7.0'
when 'edge'
git 'https://github.com/rails/rails.git', branch: 'main' do
gem 'activerecord'
gem 'activesupport'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Installation
Add this line to your application's Gemfile:

```ruby
gem 'mobility', '~> 1.1.2'
gem 'mobility', '~> 1.2.9'
```

### ActiveRecord (Rails)
Expand Down
22 changes: 11 additions & 11 deletions certs/shioyama.pem
Original file line number Diff line number Diff line change
@@ -1,7 +1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mXrsONdMC
Xohy+Rrr2yT09MPYG+llpLHDnXmTnPsOZUSL5Q4c/iolodv4xJZKwLMZwrm2hQl9
9Or9Os+qxY0zWxmWuAtTFrskLAMhckCPDEcqSZmW4CT1a/quC2Oh0y1GsXPcqtqt
hLRuwfTXGor6bg4CrU7GRbSqjvnBepct5lwZiZrOCnMEUpY+9Q8fwmG3o3B+wBsw
eBMcZq0d1tbtv1M1UXND9mOfhLZ31YvoSTPkrJiRpljUNgD0+ugelnr1/5X/9k8y
J9QOd3C5jpSShf/HMvpJnFuSYFm19cH9GrHjvw==
bWF0YS5jb20wDQYJKoZIhvcNAQELBQADggGBAHJPxoU7brN6goci9iclRYUq1Prs
51E87VRywUDysHpaHJoGRTqRJsQxi5aGZ9pIbiXGj9WJKKnrhiv5cM5fWtAsz564
Ro+Zyx6UVt/2z9rcfYrnXtmC9wh+5/0UqAeoan9RiSd8lscQZ9pEY0E3cmzJRHSU
t8kwB2ipVkFO17mdTVgc3C2ZbWRq80eTzkELDBb+8xO0Cskyh4sGMTOKfHs2RWcJ
217Qeg0F9w0RcqwnORe5zmPihY9zswCPh0IUaJa1pNY+MLTff9LE/qTl3WVTgrif
HsSSnstQYPSLJ3hSP/cu1aOmdXlJiim//XlDQ9DNp4KWje3UW3DMRdTwjW5wPmUq
VA9Ij7DUPaZzUpy1NZEigf1GshvslOnvN5bgol1YFR46jpfZVlgt0K5XBQVNvp/A
QHgocnSksU5GOM+G2UhjVycbTamd+bCxjWAZTEDZNafFt5CmnfK1D1UTIblR/ci9
fUDdW+GhxhobB8N1mtDRlhELoxLLjx7mSvJ3Wg==
-----END CERTIFICATE-----
3 changes: 3 additions & 0 deletions lib/mobility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class Comment
plugin enabled.

=end

def ruby2_keywords(*); end unless respond_to?(:ruby2_keywords, true)

module Mobility
# A generic exception used by Mobility.
class Error < StandardError
Expand Down
58 changes: 38 additions & 20 deletions lib/mobility/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module Mobility
corresponding to valid keys for configuring this backend.
- implement a +configure+ class method to apply any normalization to the
keys on the options hash included in +valid_keys+
- call the +setup+ method yielding attributes and options to configure the
model class
- call the +setup+ method yielding attributes and options (and optionally the
configured backend class) to configure the model class

@example Defining a Backend
class MyBackend
Expand All @@ -49,6 +49,13 @@ def self.configure(options)
setup do |attributes, options|
# Do something with attributes and options in context of model class.
end

# The block can optionally take the configured backend class as its third
# argument:
#
# setup do |attributes, options, backend_class|
# ...
# end
end

@see Mobility::Translations
Expand Down Expand Up @@ -147,9 +154,11 @@ def valid_keys
def setup &block
if @setup_block
setup_block = @setup_block
@setup_block = lambda do |*args|
class_exec(*args, &setup_block)
class_exec(*args, &block)
exec_setup_block = method(:exec_setup_block)
@setup_block = lambda do |attributes, options, backend_class|
[setup_block, block].each do |blk|
exec_setup_block.call(self, attributes, options, backend_class, &blk)
end
end
else
@setup_block = block
Expand All @@ -158,17 +167,6 @@ def setup &block

def inherited(subclass)
subclass.instance_variable_set(:@setup_block, @setup_block)
subclass.instance_variable_set(:@options, @options)
subclass.instance_variable_set(:@model_class, @model_class)
end

# Call setup block on a class with attributes and options.
# @param model_class Class to be setup-ed
# @param [Array<String>] attribute_names
# @param [Hash] options
def setup_model(model_class, attribute_names)
return unless setup_block = @setup_block
model_class.class_exec(attribute_names, options, &setup_block)
end

# Build a subclass of this backend class for a given set of options
Expand Down Expand Up @@ -204,10 +202,30 @@ def #{name}
EOM
end

# Show useful information about this backend class, if it has no name.
# @return [String]
def inspect
name ? super : "#<#{superclass.name}>"
def options
raise_unconfigured!(:options)
end

def model_class
raise_unconfigured!(:model_class)
end

def setup_model(_model_class, _attributes)
raise_unconfigured!(:setup_model)
end

private

def raise_unconfigured!(method_name)
raise UnconfiguredError, "You are calling #{method_name} on an unconfigured backend class."
end

def exec_setup_block(model_class, *args, &block)
if block.arity == 3
model_class.class_exec(*args[0..2], &block)
else
model_class.class_exec(*args[0..1], &block)
end
end
end

Expand Down
Loading