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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a3bb9cd0c1bdeac2c776ab13a310d764948c9568b0b0d6fb0e3a676c2c7faf8
4
- data.tar.gz: a523f6badd39d1db5870455a80d317a5521413a464845625ccc79ae0e2d82841
3
+ metadata.gz: 1bb99bf4bf5e25c2c0d87a856baaa977888ad8290a0bb6fdbb7841acd8226d6c
4
+ data.tar.gz: 76939f1b0087d1fc8ee4a061888555a0dc5b4891d9a4e687558749883bfa7be7
5
5
  SHA512:
6
- metadata.gz: 55549134ee122845bc33c7fe60dbb61ea584242c121867f9fe21906b4989c183bf48aabf427e8431ed075440fe8fb461c4e977b90c1289362ab48713716b7a50
7
- data.tar.gz: 1bbce1b57ced8f1f2d786b32dbe231ea72f726e3537cc969c1e2a27ed41b3e48dacc3d77970173ff4a91c6606f254be73c0d3114e49fefae558739aa97ddfeac
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
- post.published!
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 `!` and `?` method to your timestamps without `_at` prefix
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.current : nil)
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") }
@@ -1,3 +1,3 @@
1
1
  module BoolAt
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
@@ -23,16 +23,18 @@ RSpec.describe BoolAt::Macro do
23
23
  end
24
24
  end
25
25
 
26
- context "#bool! method" do
27
- it "sets published_at when banging bool_at method" do
26
+ describe "setter" do
27
+ it "sets time on current value" do
28
28
  post = Post.new
29
- expect { post.published! }.to change { post.published_at }.from(nil)
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 "sets date now" do
33
- post = Post.new
34
- post.published!
35
- expect(post.published_at).to be_a(Time)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bool_at
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chong Hui