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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5acc839630f48b9206cd7dd07d15f4563e3d43eefc039a4fd069df0e2cc0aa21
4
- data.tar.gz: 0aaf6fa56776b9b934c7a317f9eea6eada121dd24da494b3a1a0294b97d30771
3
+ metadata.gz: af337b26f0dc5ce70747c5146b92e0a115d987ed835cd3131e42aca5611bb58c
4
+ data.tar.gz: 59329bac85be78bad931c35fd629278d5676419f2ae8aeaba13c1e7312f55695
5
5
  SHA512:
6
- metadata.gz: 2bd9a2ed4952d33d5a85f47b146f90d1d646078f36cc94052e8fbd76fa20ebcb6ea182351ca9f11436146996fd292d8f9feeeb3b3ce7a9418948e614dfe442be
7
- data.tar.gz: 48d4a07e21aa180fe8117115bb23f1a6bb21e1e94376926f36872ac4d3e52ea0df53c16e427ea49e69bfb2c52be2fc0cc0d2d9bc9a9ae7b5261fb1477c5e5aa9
6
+ metadata.gz: 4a78da81585e4c74ec3a3560308020390b3a089726d9461796a9a9b0481f38f9f5de88710e276a9a08d241059942542e8bfa0630d317e8a55be18ef1a800d2eb
7
+ data.tar.gz: e9ae065b1573973fc993ec6a918a770261383baa36b41cd0b09dbc77cab9cf40e917bd3c2fffb032c58246585e109e22f379997826d1457150e6901b502164b3
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -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="#{attribute}_at")
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
@@ -1,3 +1,3 @@
1
1
  module TimeForABoolean
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  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.0
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: 2017-12-12 00:00:00.000000000 Z
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
- rubyforge_project:
138
- rubygems_version: 2.6.14
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: