bool_at 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.byebug_history +3 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/.travis.yml +19 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +120 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +12 -0
- data/bin/console +18 -0
- data/bin/setup +6 -0
- data/bool_at.gemspec +34 -0
- data/bool_at_test +0 -0
- data/db/config.yml +9 -0
- data/gemfiles/rails_4.2.gemfile +5 -0
- data/gemfiles/rails_5.gemfile +5 -0
- data/jsonb_accessor +0 -0
- data/lib/bool_at.rb +16 -0
- data/lib/bool_at/macro.rb +26 -0
- data/lib/bool_at/version.rb +3 -0
- data/spec/bool_at/macro_spec.rb +39 -0
- data/spec/bool_at_spec.rb +5 -0
- data/spec/spec_helper.rb +55 -0
- metadata +196 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23003f8b652ba36c79cf693fe59860065b29db88afdde7472889bb9a29186088
|
4
|
+
data.tar.gz: 4bfe89fae24d76255a6207fc4fe1f4e6d5f001101269bbb272d81dd31a6e0608
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e21b40ff99929d379d6ed87ae1323f1bfa09801f522564a3a1b0b3675cfb39ef92d6685b507e677110402866be3504dc63c2c2793108a09829e66ae9b3045d86
|
7
|
+
data.tar.gz: 699042a0a9b39ab499e13bd47c068eaff755bd561d98834c879e887e6dd360be9674943db4d3a23a317a46a126676281fb6743b067743769198324eac918f998
|
data/.byebug_history
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.5.1
|
5
|
+
- 2.4.1
|
6
|
+
- 2.3.3
|
7
|
+
addons:
|
8
|
+
postgresql: '10'
|
9
|
+
before_install:
|
10
|
+
- gem update --system
|
11
|
+
- gem --version
|
12
|
+
- gem install bundler
|
13
|
+
before_script:
|
14
|
+
- bundle exec rake db:create
|
15
|
+
- bundle exec rake db:migrate
|
16
|
+
cache: bundler
|
17
|
+
gemfile:
|
18
|
+
- gemfiles/rails_4.2.gemfile
|
19
|
+
- gemfiles/rails_5.0.gemfile
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 iamchoonggg@gmail.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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bool_at (0.1.0)
|
5
|
+
activerecord (>= 4.2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (5.2.0)
|
11
|
+
actionview (= 5.2.0)
|
12
|
+
activesupport (= 5.2.0)
|
13
|
+
rack (~> 2.0)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
17
|
+
actionview (5.2.0)
|
18
|
+
activesupport (= 5.2.0)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
23
|
+
activemodel (5.2.0)
|
24
|
+
activesupport (= 5.2.0)
|
25
|
+
activerecord (5.2.0)
|
26
|
+
activemodel (= 5.2.0)
|
27
|
+
activesupport (= 5.2.0)
|
28
|
+
arel (>= 9.0)
|
29
|
+
activesupport (5.2.0)
|
30
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
+
i18n (>= 0.7, < 2)
|
32
|
+
minitest (~> 5.1)
|
33
|
+
tzinfo (~> 1.1)
|
34
|
+
arel (9.0.0)
|
35
|
+
ast (2.4.0)
|
36
|
+
builder (3.2.3)
|
37
|
+
coderay (1.1.2)
|
38
|
+
concurrent-ruby (1.0.5)
|
39
|
+
crass (1.0.4)
|
40
|
+
diff-lcs (1.3)
|
41
|
+
erubi (1.7.1)
|
42
|
+
i18n (1.0.1)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
loofah (2.2.2)
|
45
|
+
crass (~> 1.0.2)
|
46
|
+
nokogiri (>= 1.5.9)
|
47
|
+
method_source (0.9.0)
|
48
|
+
mini_portile2 (2.3.0)
|
49
|
+
minitest (5.11.3)
|
50
|
+
nokogiri (1.8.2)
|
51
|
+
mini_portile2 (~> 2.3.0)
|
52
|
+
parser (2.5.1.0)
|
53
|
+
ast (~> 2.4.0)
|
54
|
+
powerpack (0.1.2)
|
55
|
+
pry (0.11.3)
|
56
|
+
coderay (~> 1.1.0)
|
57
|
+
method_source (~> 0.9.0)
|
58
|
+
rack (2.0.5)
|
59
|
+
rack-test (1.0.0)
|
60
|
+
rack (>= 1.0, < 3)
|
61
|
+
rails-dom-testing (2.0.3)
|
62
|
+
activesupport (>= 4.2.0)
|
63
|
+
nokogiri (>= 1.6)
|
64
|
+
rails-html-sanitizer (1.0.4)
|
65
|
+
loofah (~> 2.2, >= 2.2.2)
|
66
|
+
railties (5.2.0)
|
67
|
+
actionpack (= 5.2.0)
|
68
|
+
activesupport (= 5.2.0)
|
69
|
+
method_source
|
70
|
+
rake (>= 0.8.7)
|
71
|
+
thor (>= 0.18.1, < 2.0)
|
72
|
+
rainbow (2.2.2)
|
73
|
+
rake
|
74
|
+
rake (10.5.0)
|
75
|
+
rspec (3.7.0)
|
76
|
+
rspec-core (~> 3.7.0)
|
77
|
+
rspec-expectations (~> 3.7.0)
|
78
|
+
rspec-mocks (~> 3.7.0)
|
79
|
+
rspec-core (3.7.1)
|
80
|
+
rspec-support (~> 3.7.0)
|
81
|
+
rspec-expectations (3.7.0)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.7.0)
|
84
|
+
rspec-mocks (3.7.0)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.7.0)
|
87
|
+
rspec-support (3.7.1)
|
88
|
+
rubocop (0.48.1)
|
89
|
+
parser (>= 2.3.3.1, < 3.0)
|
90
|
+
powerpack (~> 0.1)
|
91
|
+
rainbow (>= 1.99.1, < 3.0)
|
92
|
+
ruby-progressbar (~> 1.7)
|
93
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
94
|
+
ruby-progressbar (1.9.0)
|
95
|
+
sqlite3 (1.3.13)
|
96
|
+
standalone_migrations (5.2.5)
|
97
|
+
activerecord (>= 4.2.7, < 5.3.0)
|
98
|
+
railties (>= 4.2.7, < 5.3.0)
|
99
|
+
rake (>= 10.0)
|
100
|
+
thor (0.20.0)
|
101
|
+
thread_safe (0.3.6)
|
102
|
+
tzinfo (1.2.5)
|
103
|
+
thread_safe (~> 0.1)
|
104
|
+
unicode-display_width (1.4.0)
|
105
|
+
|
106
|
+
PLATFORMS
|
107
|
+
ruby
|
108
|
+
|
109
|
+
DEPENDENCIES
|
110
|
+
bool_at!
|
111
|
+
bundler (~> 1.16)
|
112
|
+
pry
|
113
|
+
rake (~> 10.0)
|
114
|
+
rspec (~> 3.0)
|
115
|
+
rubocop (~> 0.48.1)
|
116
|
+
sqlite3 (= 1.3.13)
|
117
|
+
standalone_migrations (~> 5.2.0)
|
118
|
+
|
119
|
+
BUNDLED WITH
|
120
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Chong Hui
|
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
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/choonggg/bool_at.svg?branch=master)](https://travis-ci.org/choonggg/bool_at)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'bool_at'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install bool_at
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
bool_at converts timestamps `time_at` methods into boolean
|
22
|
+
|
23
|
+
Add `bool_at` to your model
|
24
|
+
|
25
|
+
```
|
26
|
+
class Post < ActiveRecord::Base
|
27
|
+
bool_at :published_at
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
These methods will be available
|
32
|
+
|
33
|
+
```
|
34
|
+
post = Post.new
|
35
|
+
post.published? #=> false
|
36
|
+
post.published!
|
37
|
+
post.published? #=> true
|
38
|
+
```
|
39
|
+
|
40
|
+
### Methods
|
41
|
+
|
42
|
+
It adds `!` and `?` method to your timestamps without `_at` prefix
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
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.
|
47
|
+
|
48
|
+
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).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bool_at. 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.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
## Code of Conduct
|
59
|
+
|
60
|
+
Everyone interacting in the BoolAt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bool_at/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require "rubocop/rake_task"
|
6
|
+
require "standalone_migrations"
|
7
|
+
StandaloneMigrations::Tasks.load_tasks
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[rubocop spec]
|
data/bin/console
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bool_at"
|
5
|
+
require "rspec"
|
6
|
+
|
7
|
+
dbconfig = YAML.safe_load(File.open("db/config.yml"))
|
8
|
+
ActiveRecord::Base.establish_connection(dbconfig["development"])
|
9
|
+
|
10
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
11
|
+
# with your gem easier. You can also use a different console, if you like.
|
12
|
+
|
13
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
14
|
+
# require "pry"
|
15
|
+
# Pry.start
|
16
|
+
|
17
|
+
require "irb"
|
18
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bool_at.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "bool_at/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "bool_at"
|
9
|
+
spec.version = BoolAt::VERSION
|
10
|
+
spec.authors = ["Chong Hui"]
|
11
|
+
spec.email = ["iamchoonggg@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "Convert datetime to boolean in ActiveRecord"
|
14
|
+
spec.description = "Convert datetime to boolean in ActiveRecord."
|
15
|
+
spec.homepage = "https://github.com/choonggg/bool_at"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
# Not recommending old ActiveRecord version but good to support
|
25
|
+
spec.add_dependency "activerecord", "~>5.2", ">= 4.2.0"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "pry", "~>0.11.3"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "rubocop", "~> 0.48.1"
|
32
|
+
spec.add_development_dependency "sqlite3", "1.3.13"
|
33
|
+
spec.add_development_dependency "standalone_migrations", "~> 5.2.0", ">= 4.2.0"
|
34
|
+
end
|
data/bool_at_test
ADDED
Binary file
|
data/db/config.yml
ADDED
data/jsonb_accessor
ADDED
File without changes
|
data/lib/bool_at.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
require "active_support"
|
5
|
+
|
6
|
+
require "bool_at/version"
|
7
|
+
require "bool_at/macro"
|
8
|
+
|
9
|
+
module BoolAt
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
include Macro
|
12
|
+
end
|
13
|
+
|
14
|
+
ActiveSupport.on_load(:active_record) do
|
15
|
+
ActiveRecord::Base.send(:include, BoolAt)
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BoolAt
|
4
|
+
module Macro
|
5
|
+
module ClassMethods
|
6
|
+
def bool_at(*keys)
|
7
|
+
keys.each do |key|
|
8
|
+
unless key.to_s.include?("_at")
|
9
|
+
raise ArgumentError, "bool_at keys should be prefixed with `_at'"
|
10
|
+
end
|
11
|
+
|
12
|
+
key_attribute = key
|
13
|
+
method_name = key.to_s.remove("_at")
|
14
|
+
|
15
|
+
define_method(:"#{method_name}?") do
|
16
|
+
send(key_attribute).present?
|
17
|
+
end
|
18
|
+
|
19
|
+
define_method(:"#{method_name}!") do
|
20
|
+
send(:"#{key_attribute}=", Time.zone.now)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe BoolAt::Macro do
|
4
|
+
before do
|
5
|
+
Post.bool_at :published_at
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#bool_at" do
|
9
|
+
it "defines bool_at to Model" do
|
10
|
+
post = Post.new
|
11
|
+
expect(post.published?).to be false
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#bool?" do
|
15
|
+
it "is false when boo_at nil" do
|
16
|
+
post = Post.new(published_at: nil)
|
17
|
+
expect(post.published?).to be false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "is true when date_time is defined in key_attribute" do
|
21
|
+
post = Post.new(published_at: Time.now)
|
22
|
+
expect(post.published?).to be true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#bool! method" do
|
27
|
+
it "sets published_at when banging bool_at method" do
|
28
|
+
post = Post.new
|
29
|
+
expect { post.published! }.to change { post.published_at }.from(nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets date now" do
|
33
|
+
post = Post.new
|
34
|
+
post.published!
|
35
|
+
expect(post.published_at).to be_a(Time)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "bool_at"
|
3
|
+
require "pry"
|
4
|
+
|
5
|
+
require "active_record/railtie"
|
6
|
+
ActiveRecord::Base.logger = Logger.new(STDERR)
|
7
|
+
ActiveRecord::Base.logger.level = 3
|
8
|
+
|
9
|
+
class Post < ActiveRecord::Base; end
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
# Enable flags like --only-failures and --next-failure
|
13
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
14
|
+
|
15
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
16
|
+
config.disable_monkey_patching!
|
17
|
+
|
18
|
+
config.expect_with :rspec do |c|
|
19
|
+
c.syntax = :expect
|
20
|
+
end
|
21
|
+
|
22
|
+
config.before(:all) do
|
23
|
+
Time.zone = "Singapore"
|
24
|
+
|
25
|
+
ActiveRecord::Base.establish_connection(
|
26
|
+
adapter: "sqlite3",
|
27
|
+
encoding: "unicode",
|
28
|
+
database: "bool_at_test"
|
29
|
+
)
|
30
|
+
create_database
|
31
|
+
end
|
32
|
+
|
33
|
+
config.after(:all) do
|
34
|
+
drop_database
|
35
|
+
end
|
36
|
+
|
37
|
+
config.after(:each) do
|
38
|
+
Post.delete_all
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_database
|
43
|
+
ActiveRecord::Schema.define(version: 1) do
|
44
|
+
create_table :posts do |t|
|
45
|
+
t.timestamp :published_at
|
46
|
+
t.timestamps null: true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def drop_database
|
52
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
53
|
+
ActiveRecord::Base.connection.drop_table(table)
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bool_at
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chong Hui
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.2.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.2.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.16'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.16'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: pry
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.11.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.11.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 0.48.1
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.48.1
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: sqlite3
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.3.13
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.3.13
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: standalone_migrations
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 5.2.0
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 4.2.0
|
127
|
+
type: :development
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 5.2.0
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 4.2.0
|
137
|
+
description: Convert datetime to boolean in ActiveRecord.
|
138
|
+
email:
|
139
|
+
- iamchoonggg@gmail.com
|
140
|
+
executables: []
|
141
|
+
extensions: []
|
142
|
+
extra_rdoc_files: []
|
143
|
+
files:
|
144
|
+
- ".byebug_history"
|
145
|
+
- ".gitignore"
|
146
|
+
- ".rspec"
|
147
|
+
- ".rubocop.yml"
|
148
|
+
- ".travis.yml"
|
149
|
+
- CODE_OF_CONDUCT.md
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- bool_at.gemspec
|
158
|
+
- bool_at_test
|
159
|
+
- db/config.yml
|
160
|
+
- gemfiles/rails_4.2.gemfile
|
161
|
+
- gemfiles/rails_5.gemfile
|
162
|
+
- jsonb_accessor
|
163
|
+
- lib/bool_at.rb
|
164
|
+
- lib/bool_at/macro.rb
|
165
|
+
- lib/bool_at/version.rb
|
166
|
+
- spec/bool_at/macro_spec.rb
|
167
|
+
- spec/bool_at_spec.rb
|
168
|
+
- spec/spec_helper.rb
|
169
|
+
homepage: https://github.com/choonggg/bool_at
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.7.6
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: Convert datetime to boolean in ActiveRecord
|
193
|
+
test_files:
|
194
|
+
- spec/bool_at/macro_spec.rb
|
195
|
+
- spec/bool_at_spec.rb
|
196
|
+
- spec/spec_helper.rb
|