bool_at 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/README.md +13 -2
- data/lib/bool_at/macro.rb +1 -6
- data/lib/bool_at/version.rb +1 -1
- data/spec/bool_at/macro_spec.rb +9 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bb99bf4bf5e25c2c0d87a856baaa977888ad8290a0bb6fdbb7841acd8226d6c
|
4
|
+
data.tar.gz: 76939f1b0087d1fc8ee4a061888555a0dc5b4891d9a4e687558749883bfa7be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65f89958d3c8a3ecf3361569b5eda5872fabef82bfce698cf90746c46ce56bb12fbf9730d6362a1a760b529f2ae83162d4f309ccc8da7949f2460aee1aedd81a
|
7
|
+
data.tar.gz: 0ffdef8c0a29f55d92dfc38f4e634e65b4891f937e8d5094f46b771b57e4da6c2428c7b0c24da4bca5ec0e7a75ae173544c1bae22be9a5842bb8c00978d252e1
|
data/README.md
CHANGED
@@ -34,13 +34,24 @@ These methods will be available
|
|
34
34
|
```
|
35
35
|
post = Post.new
|
36
36
|
post.published? #=> false
|
37
|
-
|
37
|
+
|
38
|
+
post.published = true
|
38
39
|
post.published? #=> true
|
40
|
+
post.published_at #=> Will be set when published was assigned true
|
41
|
+
```
|
42
|
+
|
43
|
+
It also adds scope to your Rails model.
|
44
|
+
|
45
|
+
```
|
46
|
+
Post.published
|
47
|
+
Post.not_published
|
48
|
+
Post.order_published
|
49
|
+
Post.reverse_published
|
39
50
|
```
|
40
51
|
|
41
52
|
### Methods
|
42
53
|
|
43
|
-
It adds
|
54
|
+
It adds and `?` method to your timestamps without `_at` prefix
|
44
55
|
|
45
56
|
## Development
|
46
57
|
|
data/lib/bool_at/macro.rb
CHANGED
@@ -9,7 +9,6 @@ module BoolAt
|
|
9
9
|
at_setter = "#{attr}_at="
|
10
10
|
setter = "#{attr}="
|
11
11
|
predicate = "#{attr}?"
|
12
|
-
bang = "#{attr}!"
|
13
12
|
|
14
13
|
attribute attr, :boolean, default: false
|
15
14
|
|
@@ -20,7 +19,7 @@ module BoolAt
|
|
20
19
|
# Changes dirty state in virtual attribute
|
21
20
|
define_method setter do |value|
|
22
21
|
super(value)
|
23
|
-
send(at_setter, self[attr] ? Time.
|
22
|
+
send(at_setter, self[attr] ? Time.now : nil)
|
24
23
|
end
|
25
24
|
|
26
25
|
define_method attr do
|
@@ -32,10 +31,6 @@ module BoolAt
|
|
32
31
|
super(value)
|
33
32
|
end
|
34
33
|
|
35
|
-
define_method bang do
|
36
|
-
send(setter, Time.current)
|
37
|
-
end
|
38
|
-
|
39
34
|
alias_method predicate, attr
|
40
35
|
|
41
36
|
scope attr, -> { where("#{table_name}.#{attr}_at IS NOT NULL") }
|
data/lib/bool_at/version.rb
CHANGED
data/spec/bool_at/macro_spec.rb
CHANGED
@@ -23,16 +23,18 @@ RSpec.describe BoolAt::Macro do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
it "sets
|
26
|
+
describe "setter" do
|
27
|
+
it "sets time on current value" do
|
28
28
|
post = Post.new
|
29
|
-
|
29
|
+
post.published = true
|
30
|
+
expect(post.published?).to be true
|
31
|
+
expect(post.published_at).to be_a(Time)
|
30
32
|
end
|
31
33
|
|
32
|
-
it "
|
33
|
-
post = Post.new
|
34
|
-
post.published
|
35
|
-
expect(post.
|
34
|
+
it "removes value if nil" do
|
35
|
+
post = Post.new(published_at: Time.current)
|
36
|
+
post.published = false
|
37
|
+
expect(post.published?).to be false
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|