time_for_a_boolean 0.0.4 → 0.0.5
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/README.md +2 -2
- data/lib/time_for_a_boolean.rb +2 -2
- data/lib/time_for_a_boolean/version.rb +1 -1
- data/spec/time_for_a_boolean_spec.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30d3d6fb61fadfe42cb1b68e28ee31febc5c14db
|
|
4
|
+
data.tar.gz: 3413a70030888435ed32146dba0e8e3ddc379560
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8ce3a5d10696968948d50b41e3762e2afd698987439a5c7ac58b6c8b268f9d806cb0fefdafb6d84c40255220add9e659a64c5f1e622d2f66b9b7a843ab288854
|
|
7
|
+
data.tar.gz: 8ef16ab77d836e6fb0ca32871c6f70f68f99366abd9a6f9720d7e359a9acecab1b0a7a845dc9f42d6766dcf6d4bdfe7966df2d783f56d994bd128412d36e5546
|
data/README.md
CHANGED
|
@@ -63,9 +63,9 @@ methods are defined:
|
|
|
63
63
|
|
|
64
64
|
| Method | Description
|
|
65
65
|
| --------------- | -----------
|
|
66
|
-
| `Post#deleted` | `true` if `Post#deleted_at` is set
|
|
66
|
+
| `Post#deleted` | `true` if `Post#deleted_at` is set to a value greater than `Time.current`, `false` otherwise
|
|
67
67
|
| `Post#deleted?` | Alias for `Post#deleted`
|
|
68
|
-
| `Post#deleted=` | Sets the timestamp to `
|
|
68
|
+
| `Post#deleted=` | Sets the timestamp to `Time.current` if the new value is true, and `nil` otherwise
|
|
69
69
|
|
|
70
70
|
These methods allow you to use a timestamp as you would a boolean value in your
|
|
71
71
|
application.
|
data/lib/time_for_a_boolean.rb
CHANGED
|
@@ -6,12 +6,12 @@ module TimeForABoolean
|
|
|
6
6
|
def time_for_a_boolean(attribute)
|
|
7
7
|
define_method(attribute) do
|
|
8
8
|
!send("#{attribute}_at").nil? &&
|
|
9
|
-
send("#{attribute}_at") <= -> {
|
|
9
|
+
send("#{attribute}_at") <= -> { Time.current }.()
|
|
10
10
|
end
|
|
11
11
|
alias_method "#{attribute}?", attribute
|
|
12
12
|
define_method("#{attribute}=") do |value|
|
|
13
13
|
if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
|
|
14
|
-
send("#{attribute}_at=", -> {
|
|
14
|
+
send("#{attribute}_at=", -> { Time.current }.())
|
|
15
15
|
else
|
|
16
16
|
send("#{attribute}_at=", nil)
|
|
17
17
|
end
|
|
@@ -35,7 +35,7 @@ describe TimeForABoolean do
|
|
|
35
35
|
|
|
36
36
|
it 'is true if the attribute is not nil' do
|
|
37
37
|
klass.time_for_a_boolean :attribute
|
|
38
|
-
allow(object).to receive(:attribute_at).and_return(
|
|
38
|
+
allow(object).to receive(:attribute_at).and_return(Time.now - 10)
|
|
39
39
|
|
|
40
40
|
expect(object.attribute).to be_truthy
|
|
41
41
|
end
|
|
@@ -70,14 +70,14 @@ describe TimeForABoolean do
|
|
|
70
70
|
|
|
71
71
|
object.attribute = true
|
|
72
72
|
|
|
73
|
-
expect(object.attribute_at).to be_kind_of(
|
|
73
|
+
expect(object.attribute_at).to be_kind_of(Time)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it 'sets the timestamp to nil if value is false' do
|
|
77
77
|
klass.time_for_a_boolean :attribute
|
|
78
78
|
klass.send(:attr_accessor, :attribute_at)
|
|
79
79
|
|
|
80
|
-
object.attribute_at =
|
|
80
|
+
object.attribute_at = Time.now
|
|
81
81
|
object.attribute = false
|
|
82
82
|
|
|
83
83
|
expect(object.attribute_at).to be_nil
|
|
@@ -89,14 +89,14 @@ describe TimeForABoolean do
|
|
|
89
89
|
|
|
90
90
|
object.attribute = '1'
|
|
91
91
|
|
|
92
|
-
expect(object.attribute_at).to be_kind_of(
|
|
92
|
+
expect(object.attribute_at).to be_kind_of(Time)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it 'works with other representations of false' do
|
|
96
96
|
klass.time_for_a_boolean :attribute
|
|
97
97
|
klass.send(:attr_accessor, :attribute_at)
|
|
98
98
|
|
|
99
|
-
object.attribute_at =
|
|
99
|
+
object.attribute_at = Time.now
|
|
100
100
|
object.attribute = '0'
|
|
101
101
|
|
|
102
102
|
expect(object.attribute_at).to be_nil
|
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.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Caleb Thompson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|