time_for_a_boolean 0.2.0 → 0.2.1
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.rb +8 -4
- data/lib/time_for_a_boolean/version.rb +1 -1
- data/spec/time_for_a_boolean_spec.rb +17 -0
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af337b26f0dc5ce70747c5146b92e0a115d987ed835cd3131e42aca5611bb58c
|
4
|
+
data.tar.gz: 59329bac85be78bad931c35fd629278d5676419f2ae8aeaba13c1e7312f55695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a78da81585e4c74ec3a3560308020390b3a089726d9461796a9a9b0481f38f9f5de88710e276a9a08d241059942542e8bfa0630d317e8a55be18ef1a800d2eb
|
7
|
+
data.tar.gz: e9ae065b1573973fc993ec6a918a770261383baa36b41cd0b09dbc77cab9cf40e917bd3c2fffb032c58246585e109e22f379997826d1457150e6901b502164b3
|
data/Rakefile
CHANGED
data/lib/time_for_a_boolean.rb
CHANGED
@@ -5,20 +5,24 @@ require "time_for_a_boolean/version"
|
|
5
5
|
require "time_for_a_boolean/railtie"
|
6
6
|
|
7
7
|
module TimeForABoolean
|
8
|
-
def time_for_a_boolean(attribute, field
|
8
|
+
def time_for_a_boolean(attribute, field=:"#{attribute}_at")
|
9
9
|
define_method(attribute) do
|
10
10
|
!send(field).nil? && send(field) <= -> { Time.current }.()
|
11
11
|
end
|
12
12
|
|
13
|
-
alias_method "#{attribute}?", attribute
|
13
|
+
alias_method :"#{attribute}?", attribute
|
14
14
|
|
15
|
-
setter_attribute = "#{field}="
|
16
|
-
define_method("#{attribute}=") do |value|
|
15
|
+
setter_attribute = :"#{field}="
|
16
|
+
define_method(:"#{attribute}=") do |value|
|
17
17
|
if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
|
18
18
|
send(setter_attribute, nil)
|
19
19
|
else
|
20
20
|
send(setter_attribute, -> { Time.current }.())
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
define_method(:"#{attribute}!") do
|
25
|
+
send(:"#{attribute}=", true)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
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
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Thompson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -119,7 +119,7 @@ homepage: https://github.com/calebthompson/time_for_a_boolean
|
|
119
119
|
licenses:
|
120
120
|
- MIT
|
121
121
|
metadata: {}
|
122
|
-
post_install_message:
|
122
|
+
post_install_message:
|
123
123
|
rdoc_options: []
|
124
124
|
require_paths:
|
125
125
|
- lib
|
@@ -134,9 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
|
138
|
-
|
139
|
-
signing_key:
|
137
|
+
rubygems_version: 3.1.2
|
138
|
+
signing_key:
|
140
139
|
specification_version: 4
|
141
140
|
summary: Back boolean values with timestamps
|
142
141
|
test_files:
|