boolean_timestamp 0.2.1 → 1.0.0

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: 63a477776a3b733822c338ce3081f213ab1f8f5f
4
- data.tar.gz: 0a0d939425f2f96c4af728637542f828a86b0c9f
2
+ SHA256:
3
+ metadata.gz: d20b9909e7be91e64f90de5ccc3c4080678a96e3c89c91301d8dcbb76d19fe19
4
+ data.tar.gz: 49d931170052f330e27d057e6cb9e8097bcdef74a8ec3131e1fc8fcde8b4581d
5
5
  SHA512:
6
- metadata.gz: 3126f84ae36f8859d9cced14c77d4d2f78432764f770ada154a40f9345609b56487b6490675e750b42b05735c79f5efd759c96be6cde417ea2513c177e991268
7
- data.tar.gz: 17b98688580b5ffaeb5a8d6ccebecf2e713384c41136b28b2fa7abc4e5550cf1fe89e0b23a39e9517433ef081a0fca4f28c3d59d5f650245c81af572537825f0
6
+ metadata.gz: 322f0edb31cbc91735b792020869f4108a3902be47d67cf45ef13e99c4c63a24525ab954f6bf9f6811efc4bd428067164fe6b494c31437c858729d546298d99a
7
+ data.tar.gz: 47a1955970419409767ea71f31dd45b5f122a371630b22c3d2fa5452293789f3a339ca58fcc0cb0e6d796049300896d263c6babec0f033cd0190478a44146c90
@@ -0,0 +1,13 @@
1
+ # These commits should be ignored by git-blame, making it much easier to step through the history
2
+ # of a line without hitting formatting commits (esp. large, update-all-the-files sorts of commits).
3
+ #
4
+ # For git-blame to ignore these revisions, you'll need to tell it about this file.
5
+ #
6
+ # You can either pass it to the command each time:
7
+ # git blame --ignore-rev-file=.git-blame-ignore-revs -L 12,14 lib/repeatable/conversions.rb
8
+ #
9
+ # Or you can set it as a config value, which will be used by all git-blame commands henceforth:
10
+ # git config blame.ignoreRevsFile .git-blame-ignore-revs
11
+
12
+ # Initial style fix after introducing Standard
13
+ 16899ecbfea2c371ed1fafada52e6abe227b3b1d
data/.gitignore CHANGED
@@ -7,7 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- /Gemfile.lock
11
10
  /gemfiles/*.lock
12
11
  /gemfiles/.bundle/
13
12
 
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see: https://github.com/testdouble/standard
2
+
3
+ default_ignores: true
data/.travis.yml CHANGED
@@ -1,36 +1,27 @@
1
- sudo: false
2
1
  env:
3
2
  global:
4
- - CC_TEST_REPORTER_ID=a7a2478b2a951030d73fbb60cb2b78e485ab91fbd4f608e891cb2bf98b285998
5
3
  - COVERAGE=true
4
+ services:
5
+ - sqlite3
6
+ - mysql
7
+ - postgresql
6
8
  language: ruby
7
9
  rvm:
8
- - 2.3
9
- - 2.4
10
10
  - 2.5
11
11
  - 2.6
12
+ - 2.7
13
+ - 3.0
12
14
  gemfile:
13
- - gemfiles/activerecord_4_0.gemfile
14
- - gemfiles/activerecord_4_1.gemfile
15
- - gemfiles/activerecord_4_2.gemfile
16
- - gemfiles/activerecord_5_0.gemfile
17
- - gemfiles/activerecord_5_1.gemfile
18
15
  - gemfiles/activerecord_5_2.gemfile
16
+ - gemfiles/activerecord_6_0.gemfile
17
+ - gemfiles/activerecord_6_1.gemfile
19
18
  matrix:
20
- exclude:
21
- - rvm: 2.4
22
- gemfile: gemfiles/activerecord_4_0.gemfile
23
- - rvm: 2.4
24
- gemfile: gemfiles/activerecord_4_1.gemfile
25
- - rvm: 2.5
26
- gemfile: gemfiles/activerecord_4_0.gemfile
27
- - rvm: 2.5
28
- gemfile: gemfiles/activerecord_4_1.gemfile
29
- - rvm: 2.6
30
- gemfile: gemfiles/activerecord_4_0.gemfile
31
- - rvm: 2.6
32
- gemfile: gemfiles/activerecord_4_1.gemfile
33
- before_install: gem install bundler -v 1.16.2
19
+ exclude:
20
+ - rvm: 3.0
21
+ gemfile: gemfiles/activerecord_5_2.gemfile
22
+ before_install:
23
+ - yes | gem update --system --force
24
+ - gem install bundler
34
25
  before_script:
35
26
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
36
27
  - chmod +x ./cc-test-reporter
data/Appraisals CHANGED
@@ -1,29 +1,11 @@
1
- appraise "activerecord-4-0" do
2
- gem "activerecord", "~> 4.0.13"
3
- gem "mysql2", "~> 0.3.21"
4
- gem "pg", "~> 0.21.0"
5
- end
6
-
7
- appraise "activerecord-4-1" do
8
- gem "activerecord", "~> 4.1.16"
9
- gem "mysql2", "~> 0.3.21"
10
- gem "pg", "~> 0.21.0"
11
- end
12
-
13
- appraise "activerecord-4-2" do
14
- gem "activerecord", "~> 4.2.10"
15
- gem "mysql2", "~> 0.3.21"
16
- gem "pg", "~> 0.21.0"
17
- end
18
-
19
- appraise "activerecord-5-0" do
20
- gem "activerecord", "~> 5.0.6"
1
+ appraise "activerecord-5-2" do
2
+ gem "activerecord", "~> 5.2.0"
21
3
  end
22
4
 
23
- appraise "activerecord-5-1" do
24
- gem "activerecord", "~> 5.1.6"
5
+ appraise "activerecord-6-0" do
6
+ gem "activerecord", "~> 6.0.3"
25
7
  end
26
8
 
27
- appraise "activerecord-5-2" do
28
- gem "activerecord", "~> 5.2.0"
9
+ appraise "activerecord-6-1" do
10
+ gem "activerecord", "~> 6.1.2"
29
11
  end
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.0.0] - 2021-03-26
6
+ ### Breaking
7
+ - Drop support for Rails < 5.2.0
8
+ - Drop support for Ruby < 2.5.0
9
+
10
+ ### Added
11
+ - `strict: false` option for simpler querying where possible
12
+ - Support for Rails 6.0 and 6.1
13
+ - Support for Ruby 2.7 and 3.0
14
+
5
15
  ## [0.2.1] - 2018-08-01
6
16
  ### Fixed
7
17
  - Remove over-eager check for column existence
@@ -16,6 +26,7 @@
16
26
  ### Added
17
27
  - Copy/paste of code from app where it was originally used
18
28
 
19
- [Unreleased]: https://github.com/molawson/boolean_timestamp/compare/v0.2.1...HEAD
29
+ [Unreleased]: https://github.com/molawson/boolean_timestamp/compare/v1.0.0...HEAD
30
+ [1.0.0]: https://github.com/molawson/boolean_timestamp/compare/v0.2.1...v1.0.0
20
31
  [0.2.1]: https://github.com/molawson/boolean_timestamp/compare/v0.2.0...v0.2.1
21
32
  [0.2.0]: https://github.com/molawson/boolean_timestamp/compare/v0.1.0...v0.2.0
data/Gemfile CHANGED
@@ -1,10 +1,19 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in boolean_timestamp.gemspec
6
6
  gemspec
7
7
 
8
+ gem "appraisal"
9
+ gem "mysql2"
10
+ gem "pg"
11
+ gem "rake", ">= 12.3.3"
12
+ gem "rspec", "~> 3.0"
13
+ gem "sqlite3"
14
+ gem "standard", "~> 1.0"
15
+ gem "timecop"
16
+
8
17
  group :test do
9
18
  gem "simplecov", require: false
10
19
  end
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ boolean_timestamp (1.0.0)
5
+ activerecord (>= 5.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.1.3)
11
+ activesupport (= 6.1.3)
12
+ activerecord (6.1.3)
13
+ activemodel (= 6.1.3)
14
+ activesupport (= 6.1.3)
15
+ activesupport (6.1.3)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
21
+ appraisal (2.4.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ ast (2.4.2)
26
+ concurrent-ruby (1.1.8)
27
+ diff-lcs (1.4.4)
28
+ docile (1.3.5)
29
+ i18n (1.8.9)
30
+ concurrent-ruby (~> 1.0)
31
+ minitest (5.14.4)
32
+ mysql2 (0.5.3)
33
+ parallel (1.20.1)
34
+ parser (3.0.0.0)
35
+ ast (~> 2.4.1)
36
+ pg (1.2.3)
37
+ rainbow (3.0.0)
38
+ rake (13.0.3)
39
+ regexp_parser (2.1.1)
40
+ rexml (3.2.4)
41
+ rspec (3.10.0)
42
+ rspec-core (~> 3.10.0)
43
+ rspec-expectations (~> 3.10.0)
44
+ rspec-mocks (~> 3.10.0)
45
+ rspec-core (3.10.1)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-expectations (3.10.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-mocks (3.10.2)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.10.0)
53
+ rspec-support (3.10.2)
54
+ rubocop (1.11.0)
55
+ parallel (~> 1.10)
56
+ parser (>= 3.0.0.0)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml
60
+ rubocop-ast (>= 1.2.0, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 1.4.0, < 3.0)
63
+ rubocop-ast (1.4.1)
64
+ parser (>= 2.7.1.5)
65
+ rubocop-performance (1.10.1)
66
+ rubocop (>= 0.90.0, < 2.0)
67
+ rubocop-ast (>= 0.4.0)
68
+ ruby-progressbar (1.11.0)
69
+ simplecov (0.21.2)
70
+ docile (~> 1.1)
71
+ simplecov-html (~> 0.11)
72
+ simplecov_json_formatter (~> 0.1)
73
+ simplecov-html (0.12.3)
74
+ simplecov_json_formatter (0.1.2)
75
+ sqlite3 (1.4.2)
76
+ standard (1.0.4)
77
+ rubocop (= 1.11.0)
78
+ rubocop-performance (= 1.10.1)
79
+ thor (1.1.0)
80
+ timecop (0.9.4)
81
+ tzinfo (2.0.4)
82
+ concurrent-ruby (~> 1.0)
83
+ unicode-display_width (2.0.0)
84
+ zeitwerk (2.4.2)
85
+
86
+ PLATFORMS
87
+ x86_64-darwin-19
88
+
89
+ DEPENDENCIES
90
+ appraisal
91
+ boolean_timestamp!
92
+ mysql2
93
+ pg
94
+ rake (>= 12.3.3)
95
+ rspec (~> 3.0)
96
+ simplecov
97
+ sqlite3
98
+ standard (~> 1.0)
99
+ timecop
100
+
101
+ BUNDLED WITH
102
+ 2.2.15
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BooleanTimestamp
2
2
 
3
- [![Build Status](https://travis-ci.org/molawson/boolean_timestamp.svg?branch=master)](https://travis-ci.org/molawson/boolean_timestamp)
3
+ [![Build Status](https://travis-ci.org/molawson/boolean_timestamp.svg?branch=main)](https://travis-ci.org/molawson/boolean_timestamp)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/23eb9fb7a853d24551fa/maintainability)](https://codeclimate.com/github/molawson/boolean_timestamp/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/23eb9fb7a853d24551fa/test_coverage)](https://codeclimate.com/github/molawson/boolean_timestamp/test_coverage)
6
6
 
@@ -21,37 +21,96 @@ And then execute:
21
21
 
22
22
  $ bundle
23
23
 
24
- Or install it yourself as:
24
+ Or install it yourself with:
25
25
 
26
26
  $ gem install boolean_timestamp
27
27
 
28
28
  ## Usage
29
29
 
30
+ ### Model Setup
30
31
  In any `ActiveRecord` model, you can define a boolean field based on a timestamp column by including the `BooleanTimestmap` module and calling a single method.
31
32
 
32
33
  ```ruby
33
34
  class Article < ActiveRecord::Base
34
35
  include BooleanTimestamp
35
- boolean_timestamp :published # works with an existing column named `published_at`
36
+ boolean_timestamp :published
36
37
  end
37
38
  ```
38
39
 
39
- The gem doesn't provide any code for setting up the database column. You'll need to use Rails migrations (or any other means you choose) to create the tables and columns you need.
40
+ ### Database Requirements
41
+ The only requirement is that you have a time-based column with a matching name, including the standard `_at` suffix. In the example above, you'd need an `articles.published_at` column.
42
+
43
+ The gem does not provide any code for setting up the database column. You'll need to use Rails migrations (or any other means you choose) to create the tables and columns you need.
44
+
45
+ ### Convenience Methods
46
+ With this model setup, you get a number of methods for reading, writing, and querying a timestamp column as if it were a boolean, without restricting or altering any of the attributes that Rails adds for accessing the column directly.
47
+
48
+ ```ruby
49
+ article = Article.new
50
+ article.published? # => false
51
+
52
+ article.published = true
53
+ article.published? # => true
54
+ article.published_at # => 2021-03-25 10:00:00 -0500
55
+
56
+ Article.new(published_at: Time.now).published? # => true
57
+
58
+ published = Article.create(title: "Published", published: true)
59
+ draft = Article.create(title: "Draft")
60
+ future = Article.create(title: "Future", published_at: Time.now + 86400)
61
+ Article.published # => [published]
62
+ Article.not_published # => [draft, future]
63
+ ```
64
+
65
+ ### (Not-so-)Strict Mode
66
+
67
+ By default, `boolean_timestamp` is strict about which `Time` values are considered `true` or `false`. A value in the future is considered false because if an article has a `published_at` value of "tomorrow at noon", then strictly speaking it hasn't been published yet.
68
+
69
+ This is most useful in circumstances where you really care about that time value. For example, being strict about this lets you add features like auto-publishing articles at a future date. A user can finish writing the article and set a future `published_at` value when they want the article to be "released", and any query that fetches published articles will automatically start including it after we reach the `published_at` time.
70
+
71
+ In other cases, it's useful to have the timestamp value for debugging and reporting, but for all other intents and purposes, your code treats this data as boolean column. For example, you could have a `payments.failed_at` column. The timestamp is there mostly for historical reasons, the primary functio of that column is about separating the failed payments from those that didn't fail. You're not using this "a future value is falsey" feature of the library, but every time you lookup failed payments with `Payment.failed`, the query is going to use the current time, which can be needlessly slow (for this use-case) and is more difficult to cache (either explicitly in application code or by the database engine itself).
72
+
73
+ You can disable the current time checks for both querying and reading values on a per-attribute basis by passing the `strict: false` option. This will only treat `nil` values as `false`. Everything else is `true`. This does not change how values are written to the database.
74
+
75
+ ```ruby
76
+ class Article < ActiveRecord::Base
77
+ include BooleanTimestamp
78
+ boolean_timestamp :published, strict: false
79
+ end
80
+
81
+ published = Article.create(title: "Published", published: true)
82
+ draft = Article.create(title: "Draft")
83
+ future = Article.create(title: "Future", published: Time.now + 86400)
84
+
85
+ # Where things start to behave differently
86
+
87
+ future.published? # => true
88
+ Article.published # => [published, future]
89
+ Article.not_published # => [draft]
90
+ ```
40
91
 
41
92
  ## Development
42
93
 
43
94
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
95
 
45
- 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).
96
+ You can run the tests with `bundle exec rake`. That will run the tests against the latest version of Rails (from Gemfile.lock) and the SQLite database, so you'll need to have SQLite setup locally. You can also run the tests selectively against another database with `bundle exec rake spec:mysql` or `bundle exec rake spec:postgres`. Or run all three database engine tests with `bundle exec rake spec:all`.
97
+
98
+ If you're feeling even more ambitious, this project uses [appraisal](https://github.com/thoughtbot/appraisal) to test against multiple versions of `ActiveRecord`. You can get all of those tests setup with `bundle exec appraisal install` and run them all with `bundle exec appraisal rake spec:all` (see the appraisal docs for more usage info, including running a single appraisal).
46
99
 
47
100
  ## Contributing
48
101
 
49
102
  Bug reports and pull requests are welcome on GitHub at https://github.com/molawson/boolean_timestamp. 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.
50
103
 
104
+ 1. Fork it ( https://github.com/molawson/repeatable/fork )
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create a new Pull Request
109
+
51
110
  ## License
52
111
 
53
112
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
54
113
 
55
114
  ## Code of Conduct
56
115
 
57
- Everyone interacting in the BooleanTimestamp project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/molawson/boolean_timestamp/blob/master/CODE_OF_CONDUCT.md).
116
+ Everyone interacting in the BooleanTimestamp project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/molawson/boolean_timestamp/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -3,6 +3,8 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
+ require "standard/rake"
7
+
6
8
  namespace :spec do
7
9
  desc "Run tests with sqlite3 adapter"
8
10
  task :sqlite do
@@ -30,4 +32,4 @@ namespace :spec do
30
32
  end
31
33
  end
32
34
 
33
- task default: :spec
35
+ task default: %i[spec standard]
@@ -1,48 +1,38 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "boolean_timestamp/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "boolean_timestamp"
8
- spec.version = BooleanTimestamp::VERSION
9
- spec.authors = ["Mo Lawson"]
10
- spec.email = ["moklawson@gmail.com"]
6
+ spec.name = "boolean_timestamp"
7
+ spec.version = BooleanTimestamp::VERSION
8
+ spec.authors = ["Mo Lawson"]
9
+ spec.email = ["moklawson@gmail.com"]
11
10
 
12
- spec.summary = %q{The precision of a timestamp column with the API of a boolean column}
13
- spec.description = %q{True/False fields have a great simplicity about them, and many times
11
+ spec.summary = "The precision of a timestamp column with the API of a boolean column"
12
+ spec.description = "True/False fields have a great simplicity about them, and many times
14
13
  they're perfect for the job! But, it's not uncommon end up in a place where you'd really love to
15
14
  keep some degree of simplicity with a little more detail about when the value was changed.
16
15
  Sometimes you'll want to display that information to the user and other times you'll keep it for
17
16
  auditing or debugging purposes. Either way, boolean_timestamp makes the job easy from the
18
- beginning and adds very little code to your app.}
19
- spec.homepage = "https://github.com/molawson/boolean_timestamp"
20
- spec.license = "MIT"
21
- spec.metadata = {
17
+ beginning and adds very little code to your app."
18
+ spec.homepage = "https://github.com/molawson/boolean_timestamp"
19
+ spec.license = "MIT"
20
+ spec.metadata = {
22
21
  "homepage_uri" => "https://github.com/molawson/boolean_timestamp",
23
- "changelog_uri" => "https://github.com/molawson/boolean_timestamp/blob/master/CHANGELOG.md",
22
+ "changelog_uri" => "https://github.com/molawson/boolean_timestamp/blob/main/CHANGELOG.md",
24
23
  "source_code_uri" => "https://github.com/molawson/boolean_timestamp",
25
- "bug_tracker_uri" => "https://github.com/molawson/boolean_timestamp/issues",
24
+ "bug_tracker_uri" => "https://github.com/molawson/boolean_timestamp/issues"
26
25
  }
26
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
27
27
 
28
28
  # Specify which files should be added to the gem when it is released.
29
29
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
31
31
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
32
  end
33
- spec.bindir = "exe"
34
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
36
 
37
- spec.add_development_dependency "appraisal"
38
- spec.add_development_dependency "bundler", "~> 1.16"
39
- spec.add_development_dependency "rake", "~> 10.0"
40
- spec.add_development_dependency "rspec", "~> 3.0"
41
- spec.add_development_dependency "rubocop", "0.54.0"
42
- spec.add_development_dependency "sqlite3"
43
- spec.add_development_dependency "mysql2"
44
- spec.add_development_dependency "pg"
45
- spec.add_development_dependency "timecop"
46
-
47
- spec.add_dependency "activerecord", "> 4.0"
37
+ spec.add_dependency "activerecord", ">= 5.2.0"
48
38
  end
@@ -2,6 +2,14 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "appraisal"
6
+ gem "mysql2"
7
+ gem "pg"
8
+ gem "rake", ">= 12.3.3"
9
+ gem "rspec", "~> 3.0"
10
+ gem "sqlite3"
11
+ gem "standard", "~> 1.0"
12
+ gem "timecop"
5
13
  gem "activerecord", "~> 5.2.0"
6
14
 
7
15
  group :test do
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "mysql2"
7
+ gem "pg"
8
+ gem "rake", ">= 12.3.3"
9
+ gem "rspec", "~> 3.0"
10
+ gem "sqlite3"
11
+ gem "standard", "~> 1.0"
12
+ gem "timecop"
13
+ gem "activerecord", "~> 6.0.3"
14
+
15
+ group :test do
16
+ gem "simplecov", require: false
17
+ end
18
+
19
+ gemspec path: "../"
@@ -0,0 +1,19 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "mysql2"
7
+ gem "pg"
8
+ gem "rake", ">= 12.3.3"
9
+ gem "rspec", "~> 3.0"
10
+ gem "sqlite3"
11
+ gem "standard", "~> 1.0"
12
+ gem "timecop"
13
+ gem "activerecord", "~> 6.1.2"
14
+
15
+ group :test do
16
+ gem "simplecov", require: false
17
+ end
18
+
19
+ gemspec path: "../"
@@ -8,18 +8,26 @@ module BooleanTimestamp
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- def boolean_timestamp(method_name)
11
+ def boolean_timestamp(method_name, strict: true)
12
12
  method_name = String(method_name)
13
13
  column_name = "#{method_name}_at"
14
14
  fully_qualified_column_name = "#{table_name}.#{column_name}"
15
15
 
16
- define_boolean_timestamp_scopes(method_name, fully_qualified_column_name)
17
- define_boolean_timestamp_accessors(method_name, column_name)
16
+ define_boolean_timestamp_scopes(method_name, fully_qualified_column_name, strict: strict)
17
+ define_boolean_timestamp_accessors(method_name, column_name, strict: strict)
18
18
  end
19
19
 
20
20
  private
21
21
 
22
- def define_boolean_timestamp_scopes(method_name, fully_qualified_column_name)
22
+ def define_boolean_timestamp_scopes(method_name, fully_qualified_column_name, strict:)
23
+ if strict
24
+ define_boolean_timestamp_strict_scopes(method_name, fully_qualified_column_name)
25
+ else
26
+ define_boolean_timestamp_loose_scopes(method_name, fully_qualified_column_name)
27
+ end
28
+ end
29
+
30
+ def define_boolean_timestamp_strict_scopes(method_name, fully_qualified_column_name)
23
31
  scope(method_name, -> { where("#{fully_qualified_column_name} <= ?", Time.current) })
24
32
 
25
33
  scope(
@@ -27,32 +35,45 @@ module BooleanTimestamp
27
35
  lambda do
28
36
  where(
29
37
  "#{fully_qualified_column_name} IS NULL OR #{fully_qualified_column_name} > ?",
30
- Time.current,
38
+ Time.current
31
39
  )
32
- end,
40
+ end
33
41
  )
34
42
  end
35
43
 
36
- def define_boolean_timestamp_accessors(method_name, column_name)
37
- false_values = if ActiveRecord::VERSION::MAJOR >= 5
38
- ActiveModel::Type::Boolean::FALSE_VALUES
39
- else
40
- ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES
41
- end
44
+ def define_boolean_timestamp_loose_scopes(method_name, fully_qualified_column_name)
45
+ scope(method_name, -> { where("#{fully_qualified_column_name} IS NOT NULL") })
46
+ scope("not_#{method_name}", -> { where("#{fully_qualified_column_name} IS NULL") })
47
+ end
42
48
 
43
- define_method(method_name) do
44
- public_send(column_name).present? && !public_send(column_name).future?
49
+ def define_boolean_timestamp_accessors(method_name, column_name, strict:)
50
+ if strict
51
+ define_boolean_timestamp_strict_reader(method_name, column_name)
52
+ else
53
+ define_boolean_timestamp_loose_reader(method_name, column_name)
45
54
  end
46
55
 
47
56
  alias_method("#{method_name}?", method_name)
48
57
 
49
58
  define_method("#{method_name}=") do |value|
50
- if false_values.include?(value)
59
+ if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
51
60
  public_send("#{column_name}=", nil)
52
61
  elsif !public_send(method_name)
53
62
  public_send("#{column_name}=", Time.current)
54
63
  end
55
64
  end
56
65
  end
66
+
67
+ def define_boolean_timestamp_strict_reader(method_name, column_name)
68
+ define_method(method_name) do
69
+ public_send(column_name).present? && !public_send(column_name).future?
70
+ end
71
+ end
72
+
73
+ def define_boolean_timestamp_loose_reader(method_name, column_name)
74
+ define_method(method_name) do
75
+ public_send(column_name).present?
76
+ end
77
+ end
57
78
  end
58
79
  end
@@ -1,3 +1,3 @@
1
1
  module BooleanTimestamp
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,155 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boolean_timestamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mo Lawson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-01 00:00:00.000000000 Z
11
+ date: 2021-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: appraisal
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.16'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.16'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '10.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - '='
74
- - !ruby/object:Gem::Version
75
- version: 0.54.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - '='
81
- - !ruby/object:Gem::Version
82
- version: 0.54.0
83
- - !ruby/object:Gem::Dependency
84
- name: sqlite3
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: mysql2
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: pg
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: timecop
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
13
  - !ruby/object:Gem::Dependency
140
14
  name: activerecord
141
15
  requirement: !ruby/object:Gem::Requirement
142
16
  requirements:
143
- - - ">"
17
+ - - ">="
144
18
  - !ruby/object:Gem::Version
145
- version: '4.0'
19
+ version: 5.2.0
146
20
  type: :runtime
147
21
  prerelease: false
148
22
  version_requirements: !ruby/object:Gem::Requirement
149
23
  requirements:
150
- - - ">"
24
+ - - ">="
151
25
  - !ruby/object:Gem::Version
152
- version: '4.0'
26
+ version: 5.2.0
153
27
  description: |-
154
28
  True/False fields have a great simplicity about them, and many times
155
29
  they're perfect for the job! But, it's not uncommon end up in a place where you'd really love to
@@ -164,26 +38,26 @@ extensions: []
164
38
  extra_rdoc_files: []
165
39
  files:
166
40
  - ".editorconfig"
41
+ - ".git-blame-ignore-revs"
167
42
  - ".gitignore"
168
43
  - ".rspec"
169
44
  - ".rubocop.yml"
45
+ - ".standard.yml"
170
46
  - ".travis.yml"
171
47
  - Appraisals
172
48
  - CHANGELOG.md
173
49
  - CODE_OF_CONDUCT.md
174
50
  - Gemfile
51
+ - Gemfile.lock
175
52
  - LICENSE.txt
176
53
  - README.md
177
54
  - Rakefile
178
55
  - bin/console
179
56
  - bin/setup
180
57
  - boolean_timestamp.gemspec
181
- - gemfiles/activerecord_4_0.gemfile
182
- - gemfiles/activerecord_4_1.gemfile
183
- - gemfiles/activerecord_4_2.gemfile
184
- - gemfiles/activerecord_5_0.gemfile
185
- - gemfiles/activerecord_5_1.gemfile
186
58
  - gemfiles/activerecord_5_2.gemfile
59
+ - gemfiles/activerecord_6_0.gemfile
60
+ - gemfiles/activerecord_6_1.gemfile
187
61
  - lib/boolean_timestamp.rb
188
62
  - lib/boolean_timestamp/version.rb
189
63
  homepage: https://github.com/molawson/boolean_timestamp
@@ -191,10 +65,10 @@ licenses:
191
65
  - MIT
192
66
  metadata:
193
67
  homepage_uri: https://github.com/molawson/boolean_timestamp
194
- changelog_uri: https://github.com/molawson/boolean_timestamp/blob/master/CHANGELOG.md
68
+ changelog_uri: https://github.com/molawson/boolean_timestamp/blob/main/CHANGELOG.md
195
69
  source_code_uri: https://github.com/molawson/boolean_timestamp
196
70
  bug_tracker_uri: https://github.com/molawson/boolean_timestamp/issues
197
- post_install_message:
71
+ post_install_message:
198
72
  rdoc_options: []
199
73
  require_paths:
200
74
  - lib
@@ -202,16 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
76
  requirements:
203
77
  - - ">="
204
78
  - !ruby/object:Gem::Version
205
- version: '0'
79
+ version: 2.5.0
206
80
  required_rubygems_version: !ruby/object:Gem::Requirement
207
81
  requirements:
208
82
  - - ">="
209
83
  - !ruby/object:Gem::Version
210
84
  version: '0'
211
85
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.5.2.3
214
- signing_key:
86
+ rubygems_version: 3.1.2
87
+ signing_key:
215
88
  specification_version: 4
216
89
  summary: The precision of a timestamp column with the API of a boolean column
217
90
  test_files: []
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.0.13"
6
- gem "mysql2", "~> 0.3.21"
7
- gem "pg", "~> 0.21.0"
8
-
9
- group :test do
10
- gem "simplecov", require: false
11
- end
12
-
13
- gemspec path: "../"
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1.16"
6
- gem "mysql2", "~> 0.3.21"
7
- gem "pg", "~> 0.21.0"
8
-
9
- group :test do
10
- gem "simplecov", require: false
11
- end
12
-
13
- gemspec path: "../"
@@ -1,13 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.10"
6
- gem "mysql2", "~> 0.3.21"
7
- gem "pg", "~> 0.21.0"
8
-
9
- group :test do
10
- gem "simplecov", require: false
11
- end
12
-
13
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.0.6"
6
-
7
- group :test do
8
- gem "simplecov", require: false
9
- end
10
-
11
- gemspec path: "../"
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 5.1.6"
6
-
7
- group :test do
8
- gem "simplecov", require: false
9
- end
10
-
11
- gemspec path: "../"