adaptive_alias 0.0.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +70 -70
- data/.gitignore +62 -62
- data/.rubocop.yml +1227 -1227
- data/CHANGELOG.md +12 -1
- data/CODE_OF_CONDUCT.md +49 -49
- data/LICENSE +21 -21
- data/README.md +67 -67
- data/Rakefile +10 -10
- data/adaptive_alias.gemspec +44 -44
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/gemfiles/6.0.gemfile +11 -10
- data/gemfiles/6.1.gemfile +11 -10
- data/gemfiles/7.0.gemfile +12 -11
- data/lib/adaptive_alias/active_model_patches/apply_scope.rb +17 -0
- data/lib/adaptive_alias/active_model_patches/read_attribute.rb +30 -20
- data/lib/adaptive_alias/active_model_patches/remove_alias_attribute.rb +24 -27
- data/lib/adaptive_alias/active_model_patches/write_attribute.rb +25 -0
- data/lib/adaptive_alias/hooks/association.rb +17 -13
- data/lib/adaptive_alias/hooks/association_scope.rb +13 -13
- data/lib/adaptive_alias/hooks/relation.rb +21 -21
- data/lib/adaptive_alias/hooks/singular_association.rb +13 -13
- data/lib/adaptive_alias/patches/backward_patch.rb +24 -21
- data/lib/adaptive_alias/patches/base.rb +110 -75
- data/lib/adaptive_alias/patches/forward_patch.rb +24 -21
- data/lib/adaptive_alias/version.rb +3 -3
- data/lib/adaptive_alias.rb +79 -65
- metadata +8 -6
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
-
### [
|
3
|
+
### [v0.1.0](https://github.com/khiav223577/adaptive_alias/compare/v0.0.3...v0.1.0) 2022/08/01
|
4
|
+
- [#6](https://github.com/khiav223577/adaptive_alias/pull/6) Deal with creating records (@khiav223577)
|
5
|
+
- [#5](https://github.com/khiav223577/adaptive_alias/pull/5) Prevent infinite loop if something went wrong (@khiav223577)
|
6
|
+
- [#4](https://github.com/khiav223577/adaptive_alias/pull/4) Fix: attributes writer method should be defined after schema changes (@khiav223577)
|
7
|
+
|
8
|
+
### [v0.0.3](https://github.com/khiav223577/adaptive_alias/compare/v0.0.2...v0.0.3) 2022/07/27
|
9
|
+
- [#3](https://github.com/khiav223577/adaptive_alias/pull/3) Fix: prevent calling custom column names from raising missing attributes (@khiav223577)
|
10
|
+
|
11
|
+
### [v0.0.2](https://github.com/khiav223577/adaptive_alias/compare/v0.0.1...v0.0.2) 2022/07/26
|
12
|
+
- [#2](https://github.com/khiav223577/adaptive_alias/pull/2) Doesn't need rails_compatibility in runtime (@khiav223577)
|
13
|
+
|
14
|
+
### v0.0.1 2022/07/22
|
4
15
|
- [#1](https://github.com/khiav223577/adaptive_alias/pull/1) Implement adaptive_alias features (@khiav223577)
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
7
|
-
|
8
|
-
We are committed to making participation in this project a harassment-free
|
9
|
-
experience for everyone, regardless of level of experience, gender, gender
|
10
|
-
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
-
body size, race, ethnicity, age, religion, or nationality.
|
12
|
-
|
13
|
-
Examples of unacceptable behavior by participants include:
|
14
|
-
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
* Personal attacks
|
17
|
-
* Trolling or insulting/derogatory comments
|
18
|
-
* Public or private harassment
|
19
|
-
* Publishing other's private information, such as physical or electronic
|
20
|
-
addresses, without explicit permission
|
21
|
-
* Other unethical or unprofessional conduct
|
22
|
-
|
23
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
-
threatening, offensive, or harmful.
|
28
|
-
|
29
|
-
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
-
fairly and consistently applying these principles to every aspect of managing
|
31
|
-
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
-
Conduct may be permanently removed from the project team.
|
33
|
-
|
34
|
-
This code of conduct applies both within project spaces and in public spaces
|
35
|
-
when an individual is representing the project or its community.
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
-
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
incident.
|
43
|
-
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version 1.3.0, available at
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
-
|
48
|
-
[homepage]: http://contributor-covenant.org
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2020 Rumble Huang
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Rumble Huang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
# adaptive_alias
|
2
|
-
|
3
|
-
[![Gem Version](https://img.shields.io/gem/v/adaptive_alias.svg?style=flat)](http://rubygems.org/gems/adaptive_alias)
|
4
|
-
[![Build Status](https://github.com/khiav223577/adaptive_alias/workflows/Ruby/badge.svg)](https://github.com/khiav223577/adaptive_alias/actions)
|
5
|
-
[![RubyGems](http://img.shields.io/gem/dt/adaptive_alias.svg?style=flat)](http://rubygems.org/gems/adaptive_alias)
|
6
|
-
[![Code Climate](https://codeclimate.com/github/khiav223577/adaptive_alias/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/adaptive_alias)
|
7
|
-
[![Test Coverage](https://codeclimate.com/github/khiav223577/adaptive_alias/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/adaptive_alias/coverage)
|
8
|
-
|
9
|
-
Extend attribute_alias and make it be adaptive with realtime database schema.
|
10
|
-
|
11
|
-
When we are going to rename a column, we may want to add a forward-patch so that we can use new column name before migration. And after migration, we may want to add a backward-patch so that those where are still using old column name will not be broken.
|
12
|
-
Ideally, we switch from forward-patch to backward-patch right after migration:
|
13
|
-
```rb
|
14
|
-
ForwardPatch migrate BackwardPatch
|
15
|
-
|----------------------------------------|----------------------------------------|
|
16
|
-
|
17
|
-
```
|
18
|
-
|
19
|
-
But in reality, it will take times to deploy and restart server to switch patch. There is a gap between migration and restart. So what will happen when db is migrated but server is not restarted?
|
20
|
-
We need a way to automatically adjust the patch to adapt current schema.
|
21
|
-
|
22
|
-
```rb
|
23
|
-
ForwardPatch migrate restart BackwardPatch
|
24
|
-
|----------------------------------------|---@-----|-------------------------------|
|
25
|
-
|
26
|
-
```
|
27
|
-
|
28
|
-
This is what this gem wants to achieve. We don't want to do complex migrations, take care of backward-compatibiliy, and have any downtime.
|
29
|
-
Just rely on this gem.
|
30
|
-
|
31
|
-
|
32
|
-
## Supports
|
33
|
-
- Ruby 2.6 ~ 2.7, 3.0 ~ 3.1
|
34
|
-
- Rails 6.0, 6.1, 7.0
|
35
|
-
|
36
|
-
## Installation
|
37
|
-
|
38
|
-
```ruby
|
39
|
-
gem 'adaptive_alias'
|
40
|
-
```
|
41
|
-
|
42
|
-
And then execute:
|
43
|
-
|
44
|
-
$ bundle
|
45
|
-
|
46
|
-
Or install it yourself as:
|
47
|
-
|
48
|
-
$ gem install adaptive_alias
|
49
|
-
|
50
|
-
## Usage
|
51
|
-
|
52
|
-
|
53
|
-
## Development
|
54
|
-
|
55
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
-
|
57
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
-
|
59
|
-
## Contributing
|
60
|
-
|
61
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/adaptive_alias. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
62
|
-
|
63
|
-
|
64
|
-
## License
|
65
|
-
|
66
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
67
|
-
|
1
|
+
# adaptive_alias
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/adaptive_alias.svg?style=flat)](http://rubygems.org/gems/adaptive_alias)
|
4
|
+
[![Build Status](https://github.com/khiav223577/adaptive_alias/workflows/Ruby/badge.svg)](https://github.com/khiav223577/adaptive_alias/actions)
|
5
|
+
[![RubyGems](http://img.shields.io/gem/dt/adaptive_alias.svg?style=flat)](http://rubygems.org/gems/adaptive_alias)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/khiav223577/adaptive_alias/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/adaptive_alias)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/khiav223577/adaptive_alias/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/adaptive_alias/coverage)
|
8
|
+
|
9
|
+
Extend attribute_alias and make it be adaptive with realtime database schema.
|
10
|
+
|
11
|
+
When we are going to rename a column, we may want to add a forward-patch so that we can use new column name before migration. And after migration, we may want to add a backward-patch so that those where are still using old column name will not be broken.
|
12
|
+
Ideally, we switch from forward-patch to backward-patch right after migration:
|
13
|
+
```rb
|
14
|
+
ForwardPatch migrate BackwardPatch
|
15
|
+
|----------------------------------------|----------------------------------------|
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
But in reality, it will take times to deploy and restart server to switch patch. There is a gap between migration and restart. So what will happen when db is migrated but server is not restarted?
|
20
|
+
We need a way to automatically adjust the patch to adapt current schema.
|
21
|
+
|
22
|
+
```rb
|
23
|
+
ForwardPatch migrate restart BackwardPatch
|
24
|
+
|----------------------------------------|---@-----|-------------------------------|
|
25
|
+
|
26
|
+
```
|
27
|
+
|
28
|
+
This is what this gem wants to achieve. We don't want to do complex migrations, take care of backward-compatibiliy, and have any downtime.
|
29
|
+
Just rely on this gem.
|
30
|
+
|
31
|
+
|
32
|
+
## Supports
|
33
|
+
- Ruby 2.6 ~ 2.7, 3.0 ~ 3.1
|
34
|
+
- Rails 6.0, 6.1, 7.0
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'adaptive_alias'
|
40
|
+
```
|
41
|
+
|
42
|
+
And then execute:
|
43
|
+
|
44
|
+
$ bundle
|
45
|
+
|
46
|
+
Or install it yourself as:
|
47
|
+
|
48
|
+
$ gem install adaptive_alias
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/khiav223577/adaptive_alias. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
67
|
+
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'rake/testtask'
|
3
|
-
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << 'test'
|
6
|
-
t.libs << 'lib'
|
7
|
-
t.test_files = FileList['test/**/*_test.rb']
|
8
|
-
end
|
9
|
-
|
10
|
-
task default: :test
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :test
|
data/adaptive_alias.gemspec
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'adaptive_alias/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'adaptive_alias'
|
8
|
-
spec.version = AdaptiveAlias::VERSION
|
9
|
-
spec.authors = ['khiav reoy']
|
10
|
-
spec.email = ['mrtmrt15xn@yahoo.com.tw']
|
11
|
-
|
12
|
-
spec.summary = 'Extend attribute_alias and make it be adaptive with realtime database schema'
|
13
|
-
spec.description = 'Extend attribute_alias and make it be adaptive with realtime database schema'
|
14
|
-
spec.homepage = 'https://github.com/khiav223577/adaptive_alias'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = 'exe'
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
|
28
|
-
spec.require_paths = ['lib']
|
29
|
-
spec.metadata = {
|
30
|
-
'homepage_uri' => 'https://github.com/khiav223577/adaptive_alias',
|
31
|
-
'changelog_uri' => 'https://github.com/khiav223577/adaptive_alias/blob/master/CHANGELOG.md',
|
32
|
-
'source_code_uri' => 'https://github.com/khiav223577/adaptive_alias',
|
33
|
-
'documentation_uri' => 'https://www.rubydoc.info/gems/adaptive_alias',
|
34
|
-
'bug_tracker_uri' => 'https://github.com/khiav223577/adaptive_alias/issues',
|
35
|
-
}
|
36
|
-
|
37
|
-
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
|
38
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
39
|
-
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
40
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
41
|
-
spec.add_development_dependency 'rails_compatibility', '>= 0.0.8'
|
42
|
-
|
43
|
-
spec.add_dependency 'activerecord', '>= 3'
|
44
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'adaptive_alias/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'adaptive_alias'
|
8
|
+
spec.version = AdaptiveAlias::VERSION
|
9
|
+
spec.authors = ['khiav reoy']
|
10
|
+
spec.email = ['mrtmrt15xn@yahoo.com.tw']
|
11
|
+
|
12
|
+
spec.summary = 'Extend attribute_alias and make it be adaptive with realtime database schema'
|
13
|
+
spec.description = 'Extend attribute_alias and make it be adaptive with realtime database schema'
|
14
|
+
spec.homepage = 'https://github.com/khiav223577/adaptive_alias'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}){|f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
spec.metadata = {
|
30
|
+
'homepage_uri' => 'https://github.com/khiav223577/adaptive_alias',
|
31
|
+
'changelog_uri' => 'https://github.com/khiav223577/adaptive_alias/blob/master/CHANGELOG.md',
|
32
|
+
'source_code_uri' => 'https://github.com/khiav223577/adaptive_alias',
|
33
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/adaptive_alias',
|
34
|
+
'bug_tracker_uri' => 'https://github.com/khiav223577/adaptive_alias/issues',
|
35
|
+
}
|
36
|
+
|
37
|
+
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
|
38
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
39
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
40
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
41
|
+
spec.add_development_dependency 'rails_compatibility', '>= 0.0.8'
|
42
|
+
|
43
|
+
spec.add_dependency 'activerecord', '>= 3'
|
44
|
+
end
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'adaptive_alias'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'adaptive_alias'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
set -vx
|
5
|
-
|
6
|
-
bundle install --gemfile=gemfiles/4.2.gemfile
|
7
|
-
|
8
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install --gemfile=gemfiles/4.2.gemfile
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
data/gemfiles/6.0.gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'activerecord', '~> 6.0.0'
|
4
|
-
|
5
|
-
group :test do
|
6
|
-
gem 'simplecov', '< 0.18'
|
7
|
-
gem 'mysql2', '0.5.3'
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'activerecord', '~> 6.0.0'
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'simplecov', '< 0.18'
|
7
|
+
gem 'mysql2', '0.5.3'
|
8
|
+
gem 'acts-as-taggable-on', '~> 7.0.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
gemspec path: '../'
|
data/gemfiles/6.1.gemfile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'activerecord', '~> 6.1.3'
|
4
|
-
|
5
|
-
group :test do
|
6
|
-
gem 'simplecov', '< 0.18'
|
7
|
-
gem 'mysql2', '0.5.3'
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'activerecord', '~> 6.1.3'
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'simplecov', '< 0.18'
|
7
|
+
gem 'mysql2', '0.5.3'
|
8
|
+
gem 'acts-as-taggable-on', '~> 7.0.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
gemspec path: '../'
|
data/gemfiles/7.0.gemfile
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'zeitwerk'
|
4
|
-
gem 'activerecord', '~> 7.0.0'
|
5
|
-
|
6
|
-
group :test do
|
7
|
-
gem 'simplecov', '< 0.18'
|
8
|
-
gem 'mysql2', '0.5.3'
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'zeitwerk'
|
4
|
+
gem 'activerecord', '~> 7.0.0'
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'simplecov', '< 0.18'
|
8
|
+
gem 'mysql2', '0.5.3'
|
9
|
+
gem 'acts-as-taggable-on', '~> 9.0.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: '../'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module AdaptiveAlias
|
4
|
+
module ActiveModelPatches
|
5
|
+
module ApplyScope
|
6
|
+
def apply_scope(scope, table, key, value)
|
7
|
+
klass = table.instance_variable_get(:@klass) || table.send(:type_caster).send(:types)
|
8
|
+
key = klass.attribute_aliases[key] || key
|
9
|
+
super(scope, table, key, value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActiveRecord::Associations::AssociationScope
|
16
|
+
prepend AdaptiveAlias::ActiveModelPatches::ApplyScope
|
17
|
+
end
|
@@ -1,20 +1,30 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module AdaptiveAlias
|
4
|
+
module ActiveModelPatches
|
5
|
+
module ReadAttribute
|
6
|
+
def read_attribute(attr_name, &block) # :nodoc:
|
7
|
+
name = attr_name.to_s
|
8
|
+
name = self.class.attribute_aliases[name] || name
|
9
|
+
|
10
|
+
name = @primary_key if name == 'id' && @primary_key
|
11
|
+
_read_attribute(name, &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
# This method exists to avoid the expensive primary_key check internally, without
|
15
|
+
# breaking compatibility with the write_attribute API
|
16
|
+
def _read_attribute(attr_name, &block) # :nodoc:
|
17
|
+
name = attr_name.to_s
|
18
|
+
name = self.class.attribute_aliases[name] || name
|
19
|
+
|
20
|
+
sync_with_transaction_state if @transaction_state&.finalized?
|
21
|
+
return yield(name) if block_given? and AdaptiveAlias.missing_value?(@attributes, self.class, name)
|
22
|
+
return @attributes.fetch_value(name, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module ActiveRecord::AttributeMethods::Read
|
29
|
+
prepend AdaptiveAlias::ActiveModelPatches::ReadAttribute
|
30
|
+
end
|