time_for_a_boolean 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +5 -0
- data/lib/time_for_a_boolean/version.rb +1 -1
- data/lib/time_for_a_boolean.rb +9 -4
- data/spec/time_for_a_boolean_spec.rb +17 -0
- data/time_for_a_boolean.gemspec +7 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0901b7d1345001ec725cbb1b9a8611d8014f611f539631f6a71bfdf03c6bbc3a'
|
4
|
+
data.tar.gz: 9a202da422fad3672d96941d6d5c7b3578f742ec0c5253ef42617217d65013e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17bb87c43aa0d9b10e83001f206105bf89ca36f4ce62569ad6eb2d8f9bdc9c51b06c3824f5700c3d5dabb91431908a819d8138b65cc400685732418ee985586d
|
7
|
+
data.tar.gz: 83f9c14b99d5c6c432708a67f155b65a641cfff762e94e2f6757e53fb8240abef572e6ccf98a0141cd2847a3123d4c9ee03ca7594dd3a68b8fc38bf0355a66dc
|
data/Rakefile
CHANGED
data/lib/time_for_a_boolean.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "active_support"
|
1
2
|
require "active_support/core_ext/module/delegation"
|
2
3
|
require "active_support/core_ext/time/calculations"
|
3
4
|
require "active_model/type"
|
@@ -5,20 +6,24 @@ require "time_for_a_boolean/version"
|
|
5
6
|
require "time_for_a_boolean/railtie"
|
6
7
|
|
7
8
|
module TimeForABoolean
|
8
|
-
def time_for_a_boolean(attribute, field
|
9
|
+
def time_for_a_boolean(attribute, field=:"#{attribute}_at")
|
9
10
|
define_method(attribute) do
|
10
11
|
!send(field).nil? && send(field) <= -> { Time.current }.()
|
11
12
|
end
|
12
13
|
|
13
|
-
alias_method "#{attribute}?", attribute
|
14
|
+
alias_method :"#{attribute}?", attribute
|
14
15
|
|
15
|
-
setter_attribute = "#{field}="
|
16
|
-
define_method("#{attribute}=") do |value|
|
16
|
+
setter_attribute = :"#{field}="
|
17
|
+
define_method(:"#{attribute}=") do |value|
|
17
18
|
if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
|
18
19
|
send(setter_attribute, nil)
|
19
20
|
else
|
20
21
|
send(setter_attribute, -> { Time.current }.())
|
21
22
|
end
|
22
23
|
end
|
24
|
+
|
25
|
+
define_method(:"#{attribute}!") do
|
26
|
+
send(:"#{attribute}=", true)
|
27
|
+
end
|
23
28
|
end
|
24
29
|
end
|
@@ -22,6 +22,12 @@ describe TimeForABoolean do
|
|
22
22
|
expect(klass.new).to respond_to :attribute=
|
23
23
|
end
|
24
24
|
|
25
|
+
it 'defines the bangable method to act as an implicit writer' do
|
26
|
+
klass.time_for_a_boolean :attribute
|
27
|
+
|
28
|
+
expect(klass.new).to respond_to :attribute!
|
29
|
+
end
|
30
|
+
|
25
31
|
describe 'attribute method' do
|
26
32
|
it 'calls nil? on the backing timestamp' do
|
27
33
|
klass.time_for_a_boolean :attribute
|
@@ -136,6 +142,17 @@ describe TimeForABoolean do
|
|
136
142
|
end
|
137
143
|
end
|
138
144
|
|
145
|
+
describe 'the bangable method' do
|
146
|
+
it 'sets the timestamp to now' do
|
147
|
+
klass.time_for_a_boolean :attribute
|
148
|
+
klass.send(:attr_accessor, :attribute_at)
|
149
|
+
|
150
|
+
object.attribute!
|
151
|
+
|
152
|
+
expect(object.attribute_at).to be_kind_of(Time)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
139
156
|
def klass
|
140
157
|
@klass ||= Class.new do
|
141
158
|
extend TimeForABoolean
|
data/time_for_a_boolean.gemspec
CHANGED
@@ -6,20 +6,24 @@ require "time_for_a_boolean/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "time_for_a_boolean"
|
8
8
|
spec.version = TimeForABoolean::VERSION
|
9
|
-
spec.authors = ["Caleb
|
10
|
-
spec.email = ["caleb@
|
9
|
+
spec.authors = ["Caleb Hearth"]
|
10
|
+
spec.email = ["caleb@calebhearth.com"]
|
11
11
|
spec.description = <<-DESCRIPTION
|
12
12
|
Use timestamp values to represent boolean data such as deleted, published,
|
13
13
|
or subscribed.
|
14
14
|
DESCRIPTION
|
15
15
|
spec.summary = "Back boolean values with timestamps"
|
16
|
-
spec.homepage = "https://github.com/
|
16
|
+
spec.homepage = "https://github.com/calebhearth/time_for_a_boolean"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
19
|
spec.files = `git ls-files`.split($/)
|
20
20
|
spec.test_files = spec.files.grep(%r{^spec/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
+
spec.metadata = {
|
24
|
+
"funding-uri" => "https://github.com/sponsors/calebhearth"
|
25
|
+
}
|
26
|
+
|
23
27
|
spec.add_dependency "activerecord"
|
24
28
|
spec.add_dependency "railties"
|
25
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_for_a_boolean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Caleb
|
8
|
-
autorequire:
|
7
|
+
- Caleb Hearth
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -98,7 +98,7 @@ description: |2
|
|
98
98
|
Use timestamp values to represent boolean data such as deleted, published,
|
99
99
|
or subscribed.
|
100
100
|
email:
|
101
|
-
- caleb@
|
101
|
+
- caleb@calebhearth.com
|
102
102
|
executables: []
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
@@ -115,11 +115,12 @@ files:
|
|
115
115
|
- lib/time_for_a_boolean/version.rb
|
116
116
|
- spec/time_for_a_boolean_spec.rb
|
117
117
|
- time_for_a_boolean.gemspec
|
118
|
-
homepage: https://github.com/
|
118
|
+
homepage: https://github.com/calebhearth/time_for_a_boolean
|
119
119
|
licenses:
|
120
120
|
- MIT
|
121
|
-
metadata:
|
122
|
-
|
121
|
+
metadata:
|
122
|
+
funding-uri: https://github.com/sponsors/calebhearth
|
123
|
+
post_install_message:
|
123
124
|
rdoc_options: []
|
124
125
|
require_paths:
|
125
126
|
- lib
|
@@ -134,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
|
138
|
-
|
139
|
-
signing_key:
|
138
|
+
rubygems_version: 3.5.9
|
139
|
+
signing_key:
|
140
140
|
specification_version: 4
|
141
141
|
summary: Back boolean values with timestamps
|
142
142
|
test_files:
|