ar-uuid 0.1.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 211af2aa01d2050af8510cd61f090734e8eb2e5c
4
- data.tar.gz: b679257afd1846687f2b29d6a6c96ffc596316ed
2
+ SHA256:
3
+ metadata.gz: 89711805f2e4a8f202186b701a490127ed55dc23df8aaee62f0fcaad8648c840
4
+ data.tar.gz: 4443bec600bf3366de382b5724a202a0107b173d3b2f48f238084695f516fa53
5
5
  SHA512:
6
- metadata.gz: 4192b75517ae01de3b0e3dd4550c759ee129be1adbc9e96da6c4daaf1d3829bacbe577abb08aa59e0358448fb3f730b2c737f340ab17e3b01bb12247f5e93450
7
- data.tar.gz: 4cd10cdf46460e9708f003f94f408db821529e0d768a3681e8b676db9d7f50faf006c241e0a0208bff4bff930366b6cea5d50cc546a332dc576af7cea966190d
6
+ metadata.gz: 1fd89d52a5e7c5d306f9cd532b9a2201195f9e4ce171386cf87d2ac8dacdc647203e032dd07fabce340460438971250597e9dde630ae87f917b02bc111dd78f8
7
+ data.tar.gz: e8b4248c57c4b6cf1711119961f2fce98aff1e7410d6767f6dd9513cd06c5c0a2ea0097fd149b3893737e5ac3972ae7416c000dfe88bf148ecfc44c2d4b61247
@@ -0,0 +1,4 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [fnando]
4
+ custom: ["https://paypal.me/nandovieira/🍕"]
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: "🐛 Bug Report"
3
+ about: Report a reproducible bug or regression.
4
+ title: 'Bug: '
5
+ labels: 'Status: Unconfirmed'
6
+
7
+ ---
8
+
9
+ <!--
10
+ - Please provide a clear and concise description of what the bug is.
11
+ - If possible, add an example reproducing your issue.
12
+ - Please test using the latest version of ar-uuid
13
+ to make sure your issue has not already been fixed.
14
+ -->
15
+
16
+ ## Description
17
+
18
+ [Add bug description here]
19
+
20
+ ## How to reproduce
21
+
22
+ [Add steps on how to reproduce this issue]
23
+
24
+ ## What do you expect
25
+
26
+ [Describe what do you expect to happen]
27
+
28
+ ## What happened instead
29
+
30
+ [Describe the actual results]
31
+
32
+ ## Software:
33
+
34
+ - Gem version: [Add gem version here]
35
+ - Ruby version: [Add version here]
36
+
37
+ ## Full backtrace
38
+
39
+ ```text
40
+ [Paste full backtrace here]
41
+ ```
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: "💡 Feature request"
3
+ about: Have an idea that may be useful? Make a suggestion!
4
+ title: 'Feature Request: '
5
+ labels: 'Feature request'
6
+
7
+ ---
8
+
9
+ ## Description
10
+
11
+ _A clear and concise description of what the problem is._
12
+
13
+ ## Describe the solution
14
+
15
+ _A clear and concise description of what you want to happen._
16
+
17
+ ## Alternatives you considered
18
+
19
+ _A clear and concise description of any alternative solutions or features you've considered._
20
+
21
+ ## Additional context
22
+
23
+ _Add any other context, screenshots, links, etc about the feature request here._
@@ -0,0 +1,38 @@
1
+ <!--
2
+ If you're making a doc PR or something tiny where the below is irrelevant,
3
+ delete this template and use a short description, but in your description aim to
4
+ include both what the change is, and why it is being made, with enough context
5
+ for anyone to understand.
6
+ -->
7
+
8
+ <details>
9
+ <summary>PR Checklist</summary>
10
+
11
+ ### PR Structure
12
+
13
+ - [ ] This PR has reasonably narrow scope (if not, break it down into smaller
14
+ PRs).
15
+ - [ ] This PR avoids mixing refactoring changes with feature changes (split into
16
+ two PRs otherwise).
17
+ - [ ] This PR's title starts is concise and descriptive.
18
+
19
+ ### Thoroughness
20
+
21
+ - [ ] This PR adds tests for the most critical parts of the new functionality or
22
+ fixes.
23
+ - [ ] I've updated any docs, `.md` files, etc… affected by this change.
24
+
25
+ </details>
26
+
27
+ ### What
28
+
29
+ [TODO: Short statement about what is changing.]
30
+
31
+ ### Why
32
+
33
+ [TODO: Why this change is being made. Include any context required to understand
34
+ the why.]
35
+
36
+ ### Known limitations
37
+
38
+ [TODO or N/A]
@@ -0,0 +1,15 @@
1
+ ---
2
+ # Documentation:
3
+ # https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates
4
+
5
+ version: 2
6
+ updates:
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
11
+
12
+ - package-ecosystem: "bundler"
13
+ directory: "/"
14
+ schedule:
15
+ interval: "daily"
@@ -0,0 +1,75 @@
1
+ ---
2
+ name: Tests
3
+
4
+ on:
5
+ pull_request:
6
+ branches:
7
+ - main
8
+ push:
9
+ branches:
10
+ - main
11
+
12
+ jobs:
13
+ build:
14
+ name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
15
+ runs-on: "ubuntu-latest"
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: [2.6.x, 2.7.x, 3.0.x]
20
+ gemfile:
21
+ - Gemfile
22
+ - gemfiles/6_0.gemfile
23
+ - gemfiles/5_2.gemfile
24
+ - gemfiles/5_1.gemfile
25
+ - gemfiles/5_0.gemfile
26
+
27
+ services:
28
+ postgres:
29
+ image: postgres:11.5
30
+ ports: ["5432:5432"]
31
+ options:
32
+ --health-cmd pg_isready --health-interval 10s --health-timeout 5s
33
+ --health-retries 5
34
+
35
+ steps:
36
+ - uses: actions/checkout@v2.3.4
37
+
38
+ - uses: actions/cache@v2
39
+ with:
40
+ path: vendor/bundle
41
+ key: >
42
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
43
+ hashFiles(matrix.gemfile) }}
44
+ restore-keys: >
45
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
46
+ hashFiles(matrix.gemfile) }}
47
+
48
+ - name: Set up Ruby
49
+ uses: actions/setup-ruby@v1
50
+ with:
51
+ ruby-version: ${{ matrix.ruby }}
52
+
53
+ - name: Install PostgreSQL client
54
+ env:
55
+ PGHOST: localhost
56
+ PGUSER: postgres
57
+ run: |
58
+ sudo apt-get -yqq install libpq-dev
59
+ psql -U postgres -c "create database test"
60
+
61
+ - name: Install gem dependencies
62
+ env:
63
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
64
+ run: |
65
+ gem install bundler
66
+ bundle config path vendor/bundle
67
+ bundle update --jobs 4 --retry 3
68
+
69
+ - name: Run Tests
70
+ env:
71
+ PGHOST: localhost
72
+ PGUSER: postgres
73
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
74
+ run: |
75
+ bundle exec rake
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
7
+ NewCops: enable
8
+ Naming/FileName:
9
+ Exclude:
10
+ - lib/ar-uuid.rb
data/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ <!--
4
+ Prefix your message with one of the following:
5
+
6
+ - [Added] for new features.
7
+ - [Changed] for changes in existing functionality.
8
+ - [Deprecated] for soon-to-be removed features.
9
+ - [Removed] for now removed features.
10
+ - [Fixed] for any bug fixes.
11
+ - [Security] in case of vulnerabilities.
12
+ -->
13
+
14
+ ## Unreleased
15
+
16
+ - [Changed] Change namespace from `ActiveRecord::UUID` to `AR::UUID`.
17
+ - [Removed] Dropped support for Rails 4.2.
18
+
19
+ ## v0.2.1 - 2019-11-26
20
+
21
+ - No significant changes.
22
+
23
+ ## v0.2.0 - 2017-06-23
24
+
25
+ - [Fixed] Use the first available extension for UUID generation (`pgcrypto` or
26
+ `uuid-ossp`).
27
+ - [Fixed] Handle `belongs_to_required_by_default`.
28
+
29
+ ## v0.1.2 - 2015-05-23
30
+
31
+ - [Fixed] Make sure we always override schema statements's create_table method.
32
+
33
+ ## v0.1.1 - 2015-04-27
34
+
35
+ - Initial release.
36
+
37
+ ## v0.1.0 - 2015-04-27
38
+
39
+ - Yanked release.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at me@fnando.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,79 @@
1
+ # Contributing to ar-uuid
2
+
3
+ 👍🎉 First off, thanks for taking the time to contribute! 🎉👍
4
+
5
+ The following is a set of guidelines for contributing to this project. These are
6
+ mostly guidelines, not rules. Use your best judgment, and feel free to propose
7
+ changes to this document in a pull request.
8
+
9
+ ## Code of Conduct
10
+
11
+ Everyone interacting in this project's codebases, issue trackers, chat rooms and
12
+ mailing lists is expected to follow the [code of conduct](https://github.com/fnando/ar-uuid/blob/main/CODE_OF_CONDUCT.md).
13
+
14
+ ## Reporting bugs
15
+
16
+ This section guides you through submitting a bug report. Following these
17
+ guidelines helps maintainers and the community understand your report, reproduce
18
+ the behavior, and find related reports.
19
+
20
+ - Before creating bug reports, please check the open issues; somebody may
21
+ already have submitted something similar, and you may not need to create a new
22
+ one.
23
+ - When you are creating a bug report, please include as many details as
24
+ possible, with an example reproducing the issue.
25
+
26
+ ## Contributing with code
27
+
28
+ Before making any radicals changes, please make sure you discuss your intention
29
+ by [opening an issue on Github](https://github.com/fnando/ar-uuid/issues).
30
+
31
+ When you're ready to make your pull request, follow checklist below to make sure
32
+ your contribution is according to how this project works.
33
+
34
+ 1. [Fork](https://help.github.com/forking/) ar-uuid
35
+ 2. Create a topic branch - `git checkout -b my_branch`
36
+ 3. Make your changes using [descriptive commit messages](#commit-messages)
37
+ 4. Update CHANGELOG.md describing your changes by adding an entry to the
38
+ "Unreleased" section. If this section is not available, create one right
39
+ before the last version.
40
+ 5. Push to your branch - `git push origin my_branch`
41
+ 6. [Create a pull request](https://docs.github.com/articles/creating-a-pull-request)
42
+ 7. That's it!
43
+
44
+ ## Styleguides
45
+
46
+ ### Commit messages
47
+
48
+ - Use the present tense ("Add feature" not "Added feature")
49
+ - Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
50
+ - Limit the first line to 72 characters or less
51
+ - Reference issues and pull requests liberally after the first line
52
+
53
+ ### Changelog
54
+
55
+ - Add a message describing your changes to the "Unreleased" section. The
56
+ changelog message should follow the same style as the commit message.
57
+ - Prefix your message with one of the following:
58
+ - `[Added]` for new features.
59
+ - `[Changed]` for changes in existing functionality.
60
+ - `[Deprecated]` for soon-to-be removed features.
61
+ - `[Removed]` for now removed features.
62
+ - `[Fixed]` for any bug fixes.
63
+ - `[Security]` in case of vulnerabilities.
64
+
65
+ ### Ruby code
66
+
67
+ - This project uses [Rubocop](https://rubocop.org) to enforce code style. Before
68
+ submitting your changes, make sure your tests are passing and code conforms to
69
+ the expected style by running `rake`.
70
+ - Do not change the library version. This will be done by the maintainer
71
+ whenever a new version is about to be released.
72
+
73
+ ### JavaScript code
74
+
75
+ - This project uses [ESLint](https://eslint.org) to enforce code style. Before
76
+ submitting your changes, make sure your tests are passing and code conforms to
77
+ the expected style by running `yarn test:ci`.
78
+ - Do not change the library version. This will be done by the maintainer
79
+ whenever a new version is about to be released.
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
- # Specify your gem's dependencies in ar-uuid.gemspec
4
5
  gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Nando Vieira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Nando Vieira
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,33 +1,30 @@
1
- # ActiveRecord::UUID
1
+ # ar-uuid
2
2
 
3
- [![Build Status](https://travis-ci.org/fnando/ar-uuid.svg)](https://travis-ci.org/fnando/ar-uuid)
3
+ [![Tests](https://github.com/fnando/ar-uuid/workflows/Tests/badge.svg)](https://github.com/fnando/ar-uuid)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/ar-uuid/badges/gpa.svg)](https://codeclimate.com/github/fnando/ar-uuid)
5
+ [![Gem](https://img.shields.io/gem/v/ar-uuid.svg)](https://rubygems.org/gems/ar-uuid)
6
+ [![Gem](https://img.shields.io/gem/dt/ar-uuid.svg)](https://rubygems.org/gems/ar-uuid)
4
7
 
5
- Override migration methods to support UUID columns without having to be explicit about it.
6
-
7
- What this gem will do for you:
8
-
9
- - When creating new tables, will set the `id` column as `uuid`.
10
- - When creating associations with `t.belongs_to`, `t.references` or `add_reference`, will set the column type as `uuid`.
8
+ Override migration methods to support UUID columns without having to be explicit
9
+ about it.
11
10
 
12
11
  ## Installation
13
12
 
14
- Add this line to your application's Gemfile:
15
-
16
- ```ruby
17
- gem 'ar-uuid'
13
+ ```bash
14
+ gem install ar-uuid
18
15
  ```
19
16
 
20
- And then execute:
21
-
22
- $ bundle
17
+ Or add the following line to your project's Gemfile:
23
18
 
24
- Or install it yourself as:
25
-
26
- $ gem install ar-uuid
19
+ ```ruby
20
+ gem "ar-uuid"
21
+ ```
27
22
 
28
23
  ## Usage
29
24
 
30
- There's no setup. Just adding the gem to your Gemfile is enough. When you create a new table, the `id` column will be defined as `uuid`. This is also true for references.
25
+ There's no setup. Just adding the gem to your Gemfile is enough. When you create
26
+ a new table, the `id` column will be defined as `uuid`. This is also true for
27
+ references.
31
28
 
32
29
  ```ruby
33
30
  create_table :users
@@ -40,7 +37,8 @@ create_table :posts do |t|
40
37
  end
41
38
  ```
42
39
 
43
- If you need a serial column, AR's PostgreSQL supports the `bigserial` column type.
40
+ If you need a serial column, AR's PostgreSQL supports the `bigserial` column
41
+ type.
44
42
 
45
43
  ```ruby
46
44
  create_table :users do |t|
@@ -48,16 +46,88 @@ create_table :users do |t|
48
46
  end
49
47
  ```
50
48
 
51
- ## Development
49
+ ### Sorting
50
+
51
+ #### Rails 6.0 or newer
52
+
53
+ If you're using Rails 6.0 or newer, you can set a default sorting with
54
+ [ActiveRecord::ModelSchema.implicit_order_column](https://api.rubyonrails.org/classes/ActiveRecord/ModelSchema.html#method-c-implicit_order_column),
55
+ so methods like `ActiveRecord::FinderMethods::InstanceMethods#first` and
56
+ `ActiveRecord::FinderMethods::InstanceMethods#last` will work transparently, as
57
+ long as you define another column for sorting, such as `created_at` (you may
58
+ need to add an index).
59
+
60
+ The following example sets a default behavior to always sort using `created_at`
61
+ (when available). On your abstract model, add the following lines:
62
+
63
+ ```ruby
64
+ class ApplicationRecord < ActiveRecord::Base
65
+ self.abstract_class = true
66
+
67
+ def self.inherited(child_class)
68
+ super
69
+
70
+ return unless child_class.columns.any? {|col| col.name == "created_at" }
71
+
72
+ child_class.implicit_order_column ||= "created_at"
73
+ end
74
+ end
75
+ ```
76
+
77
+ #### Older Rails versions
52
78
 
53
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
54
- 4
55
- 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+ For older Rails versions, you can't use methods like
80
+ `ActiveRecord::FinderMethods::InstanceMethods#first` and
81
+ `ActiveRecord::FinderMethods::InstanceMethods#last`, since they are scoped to
82
+ the sequential id.
83
+
84
+ The easiest alternative is ordering results and calling `first`/`last`. You can
85
+ either create a sequence, or use the `created_at`/`updated_at` columns:
86
+
87
+ ```ruby
88
+ # Get first record
89
+ User.order(created_at: :asc).first
90
+
91
+ # Get last record
92
+ User.order(created_at: :desc).first
93
+
94
+ # Use scopes
95
+ class User < ApplicationRecord
96
+ scope :newer, -> { order(created_at: :desc) }
97
+ scope :older, -> { order(created_at: :asc) }
98
+ end
99
+
100
+ User.older.first
101
+ User.newer.first
102
+ ```
103
+
104
+ You can also replace `.first` with
105
+ [ActiveRecord::FinderMethods::InstanceMethods#take](https://github.com/rails/rails/blob/f52354ad1d15120dcc5284714bee7ee3f052986c/activerecord/lib/active_record/relation/finder_methods.rb#L104),
106
+ which will use the order implemented by the database.
107
+
108
+ There's no alternative to `.last`.
109
+
110
+ ## Maintainer
111
+
112
+ - [Nando Vieira](https://github.com/fnando)
113
+
114
+ ## Contributors
115
+
116
+ - https://github.com/fnando/ar-uuid/contributors
56
117
 
57
118
  ## Contributing
58
119
 
59
- 1. Fork it ( https://github.com/[my-github-username]/ar-uuid/fork )
60
- 2. Create your feature branch (`git checkout -b my-new-feature`)
61
- 3. Commit your changes (`git commit -am 'Add some feature'`)
62
- 4. Push to the branch (`git push origin my-new-feature`)
63
- 5. Create a new Pull Request
120
+ For more details about how to contribute, please read
121
+ https://github.com/fnando/ar-uuid/blob/main/CONTRIBUTING.md.
122
+
123
+ ## License
124
+
125
+ The gem is available as open source under the terms of the
126
+ [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
127
+ found at https://github.com/fnando/ar-uuid/blob/main/LICENSE.md.
128
+
129
+ ## Code of Conduct
130
+
131
+ Everyone interacting in the ar-uuid project's codebases, issue trackers, chat
132
+ rooms and mailing lists is expected to follow the
133
+ [code of conduct](https://github.com/fnando/ar-uuid/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,6 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.libs << "lib"
10
+ t.test_files = FileList["test/**/*_test.rb"]
11
+ end
3
12
 
4
- RSpec::Core::RakeTask.new(:spec)
13
+ RuboCop::RakeTask.new
5
14
 
6
- task :default => :spec
15
+ task default: %i[test rubocop]
data/ar-uuid.gemspec CHANGED
@@ -1,24 +1,35 @@
1
- require './lib/active_record/uuid/version'
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/ar/uuid/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.required_ruby_version = '>= 2.1.0'
5
- spec.name = 'ar-uuid'
6
- spec.version = ActiveRecord::UUID::VERSION
7
- spec.authors = ['Nando Vieira']
8
- spec.email = ['fnando.vieira@gmail.com']
9
- spec.summary = %[Add UUID support for ActiveRecord. It enforces uuid primary keys, fixes ActiveRecord's first/last methods and more.]
6
+ spec.name = "ar-uuid"
7
+ spec.version = AR::UUID::VERSION
8
+ spec.authors = ["Nando Vieira"]
9
+ spec.email = ["fnando.vieira@gmail.com"]
10
+ spec.summary = "Override migration methods to support UUID columns " \
11
+ "without having to be explicit about it."
10
12
  spec.description = spec.summary
11
- spec.homepage = 'http://rubygems.org/gems/ar-uuid'
13
+ spec.homepage = "http://rubygems.org/gems/ar-uuid"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
16
+
17
+ spec.files = `git ls-files -z`
18
+ .split("\x0")
19
+ .reject {|f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
12
23
 
13
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
- spec.bindir = 'exe'
15
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
- spec.require_paths = ['lib']
24
+ spec.add_dependency "activerecord"
17
25
 
18
- spec.add_dependency 'activerecord'
19
- spec.add_development_dependency 'bundler', '~> 1.9'
20
- spec.add_development_dependency 'rake', '~> 10.0'
21
- spec.add_development_dependency 'rspec'
22
- spec.add_development_dependency 'pg'
23
- spec.add_development_dependency 'pry-meta'
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "minitest-utils"
28
+ spec.add_development_dependency "mocha"
29
+ spec.add_development_dependency "pg"
30
+ spec.add_development_dependency "pry-meta"
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "rubocop"
33
+ spec.add_development_dependency "rubocop-fnando"
34
+ spec.add_development_dependency "simplecov"
24
35
  end
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ar-uuid"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ begin
11
+ require "pry"
12
+ Pry.start
13
+ rescue LoadError
14
+ require "irb"
15
+ IRB.start(__FILE__)
16
+ end
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+
5
+ IFS=$'\n\t'
6
+ set -vx
7
+
8
+ bundle install
9
+
10
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+ gem "activerecord", "~> 5.0.0"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+ gem "activerecord", "~> 5.1.0"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+ gem "activerecord", "~> 5.2.0"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+ gem "activerecord", "~> 6.0.0"
data/lib/ar-uuid.rb CHANGED
@@ -1 +1,3 @@
1
- require 'active_record/uuid'
1
+ # frozen_string_literal: true
2
+
3
+ require "ar/uuid"
data/lib/ar/uuid.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AR
4
+ module UUID
5
+ require "active_record"
6
+ require "active_record/base"
7
+ require "ar/uuid/version"
8
+ require "ar/uuid/schema"
9
+ require "ar/uuid/table_definition"
10
+ require "ar/uuid/ext"
11
+ require "ar/uuid/utils"
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ ActiveSupport.on_load(:active_record) do
4
+ require "active_record/connection_adapters/postgresql_adapter"
5
+
6
+ ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(
7
+ AR::UUID::Schema
8
+ )
9
+
10
+ ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.include(
11
+ AR::UUID::TableDefinition
12
+ )
13
+ end
@@ -1,14 +1,16 @@
1
- module ActiveRecord
1
+ # frozen_string_literal: true
2
+
3
+ module AR
2
4
  module UUID
3
5
  module Schema
4
6
  def create_table(table_name, options = {}, &block)
5
7
  options[:id] = :uuid unless options.key?(:id)
6
- super(table_name, options, &block)
8
+ super(table_name, **options, &block)
7
9
  end
8
10
 
9
11
  def add_reference(table_name, ref_name, options = {})
10
12
  options[:type] = :uuid unless options.key?(:type)
11
- super(table_name, ref_name, options)
13
+ super(table_name, ref_name, **options)
12
14
  end
13
15
  end
14
16
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AR
4
+ module UUID
5
+ module TableDefinition
6
+ def references(*args)
7
+ options = args.extract_options!
8
+ options[:type] = :uuid unless options.include?(:type)
9
+
10
+ unless options.include?(:null)
11
+ options[:null] =
12
+ !::AR::UUID::Utils.belongs_to_required_by_default
13
+ end
14
+
15
+ super(*args, **options)
16
+ end
17
+ alias belongs_to references
18
+
19
+ def primary_key(name, type = :primary_key, **options)
20
+ options[:default] = ::AR::UUID::Utils.uuid_default_function
21
+ super(name, type, **options)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AR
4
+ module UUID
5
+ MissingExtensionError = Class.new(StandardError) do
6
+ def initialize
7
+ super(
8
+ 'Use either `enable_extension "uuid-ossp"` or' \
9
+ '`enable_extension "pgcrypto"`'
10
+ )
11
+ end
12
+ end
13
+
14
+ module Utils
15
+ EXTENSIONS_SQL = <<~SQL
16
+ select
17
+ extname
18
+ from pg_extension
19
+ where
20
+ extname in ('uuid-ossp', 'pgcrypto')
21
+ order by 1
22
+ limit 1
23
+ SQL
24
+
25
+ FUNCTION_NAMES = {
26
+ "uuid-ossp" => "uuid_generate_v4()",
27
+ "pgcrypto" => "gen_random_uuid()"
28
+ }.freeze
29
+
30
+ def self.uuid_extname
31
+ connection = ::ActiveRecord::Base.connection
32
+ result = connection.execute(EXTENSIONS_SQL).first
33
+ raise MissingExtensionError unless result
34
+
35
+ result.fetch("extname")
36
+ end
37
+
38
+ def self.uuid_default_function
39
+ FUNCTION_NAMES.fetch(uuid_extname)
40
+ end
41
+
42
+ def self.belongs_to_required_by_default
43
+ if ::ActiveRecord::Base.respond_to?(:belongs_to_required_by_default)
44
+ ::ActiveRecord::Base.belongs_to_required_by_default
45
+ else
46
+ false
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AR
4
+ module UUID
5
+ VERSION = "0.2.2"
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-27 00:00:00.000000000 Z
11
+ date: 2021-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -28,32 +28,32 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.9'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.9'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: minitest-utils
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: mocha
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -94,31 +94,105 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Add UUID support for ActiveRecord. It enforces uuid primary keys, fixes
98
- ActiveRecord's first/last methods and more.
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-fnando
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Override migration methods to support UUID columns without having to
154
+ be explicit about it.
99
155
  email:
100
156
  - fnando.vieira@gmail.com
101
157
  executables: []
102
158
  extensions: []
103
159
  extra_rdoc_files: []
104
160
  files:
161
+ - ".github/FUNDING.yml"
162
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
163
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
164
+ - ".github/PULL_REQUEST_TEMPLATE.md"
165
+ - ".github/dependabot.yml"
166
+ - ".github/workflows/tests.yml"
105
167
  - ".gitignore"
106
- - ".rspec"
107
- - ".travis.yml"
168
+ - ".rubocop.yml"
169
+ - CHANGELOG.md
170
+ - CODE_OF_CONDUCT.md
171
+ - CONTRIBUTING.md
108
172
  - Gemfile
173
+ - LICENSE.md
174
+ - LICENSE.txt
109
175
  - README.md
110
176
  - Rakefile
111
177
  - ar-uuid.gemspec
112
- - lib/active_record/uuid.rb
113
- - lib/active_record/uuid/ext.rb
114
- - lib/active_record/uuid/schema.rb
115
- - lib/active_record/uuid/table_definition.rb
116
- - lib/active_record/uuid/version.rb
178
+ - bin/console
179
+ - bin/setup
180
+ - gemfiles/5_0.gemfile
181
+ - gemfiles/5_1.gemfile
182
+ - gemfiles/5_2.gemfile
183
+ - gemfiles/6_0.gemfile
117
184
  - lib/ar-uuid.rb
185
+ - lib/ar/uuid.rb
186
+ - lib/ar/uuid/ext.rb
187
+ - lib/ar/uuid/schema.rb
188
+ - lib/ar/uuid/table_definition.rb
189
+ - lib/ar/uuid/utils.rb
190
+ - lib/ar/uuid/version.rb
118
191
  homepage: http://rubygems.org/gems/ar-uuid
119
- licenses: []
192
+ licenses:
193
+ - MIT
120
194
  metadata: {}
121
- post_install_message:
195
+ post_install_message:
122
196
  rdoc_options: []
123
197
  require_paths:
124
198
  - lib
@@ -126,17 +200,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
200
  requirements:
127
201
  - - ">="
128
202
  - !ruby/object:Gem::Version
129
- version: 2.1.0
203
+ version: 2.6.0
130
204
  required_rubygems_version: !ruby/object:Gem::Requirement
131
205
  requirements:
132
206
  - - ">="
133
207
  - !ruby/object:Gem::Version
134
208
  version: '0'
135
209
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.4.6
138
- signing_key:
210
+ rubygems_version: 3.2.22
211
+ signing_key:
139
212
  specification_version: 4
140
- summary: Add UUID support for ActiveRecord. It enforces uuid primary keys, fixes ActiveRecord's
141
- first/last methods and more.
213
+ summary: Override migration methods to support UUID columns without having to be explicit
214
+ about it.
142
215
  test_files: []
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
- before_install:
5
- - gem install bundler
6
- before_script:
7
- - createdb test
8
- rvm:
9
- - '2.2'
10
- - '2.1'
@@ -1,10 +0,0 @@
1
- module ActiveRecord
2
- module UUID
3
- require 'active_record'
4
- require 'active_record/base'
5
- require 'active_record/uuid/version'
6
- require 'active_record/uuid/schema'
7
- require 'active_record/uuid/table_definition'
8
- require 'active_record/uuid/ext'
9
- end
10
- end
@@ -1,6 +0,0 @@
1
- ActiveSupport.on_load(:active_record) do
2
- require 'active_record/connection_adapters/postgresql_adapter'
3
-
4
- ActiveRecord::Schema.include ActiveRecord::UUID::Schema
5
- ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.include ActiveRecord::UUID::TableDefinition
6
- end
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module UUID
3
- module TableDefinition
4
- def references(*args)
5
- options = args.extract_options!
6
- options[:type] = :uuid unless options.include?(:type)
7
- args << options
8
-
9
- super(*args)
10
- end
11
-
12
- alias_method :belongs_to, :references
13
- end
14
- end
15
- end
@@ -1,5 +0,0 @@
1
- module ActiveRecord
2
- module UUID
3
- VERSION = '0.1.1'
4
- end
5
- end