time_for_a_boolean 0.2.0 → 0.2.2

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: '0901b7d1345001ec725cbb1b9a8611d8014f611f539631f6a71bfdf03c6bbc3a'
4
+ data.tar.gz: 9a202da422fad3672d96941d6d5c7b3578f742ec0c5253ef42617217d65013e5
5
5
  SHA512:
6
- metadata.gz: 2bd9a2ed4952d33d5a85f47b146f90d1d646078f36cc94052e8fbd76fa20ebcb6ea182351ca9f11436146996fd292d8f9feeeb3b3ce7a9418948e614dfe442be
7
- data.tar.gz: 48d4a07e21aa180fe8117115bb23f1a6bb21e1e94376926f36872ac4d3e52ea0df53c16e427ea49e69bfb2c52be2fc0cc0d2d9bc9a9ae7b5261fb1477c5e5aa9
6
+ metadata.gz: 17bb87c43aa0d9b10e83001f206105bf89ca36f4ce62569ad6eb2d8f9bdc9c51b06c3824f5700c3d5dabb91431908a819d8138b65cc400685732418ee985586d
7
+ data.tar.gz: 83f9c14b99d5c6c432708a67f155b65a641cfff762e94e2f6757e53fb8240abef572e6ccf98a0141cd2847a3123d4c9ee03ca7594dd3a68b8fc38bf0355a66dc
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
@@ -1,3 +1,3 @@
1
1
  module TimeForABoolean
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -1,3 +1,4 @@
1
+ require "active_support"
1
2
  require "active_support/core_ext/module/delegation"
2
3
  require "active_support/core_ext/time/calculations"
3
4
  require "active_model/type"
@@ -5,20 +6,24 @@ require "time_for_a_boolean/version"
5
6
  require "time_for_a_boolean/railtie"
6
7
 
7
8
  module TimeForABoolean
8
- def time_for_a_boolean(attribute, field="#{attribute}_at")
9
+ def time_for_a_boolean(attribute, field=:"#{attribute}_at")
9
10
  define_method(attribute) do
10
11
  !send(field).nil? && send(field) <= -> { Time.current }.()
11
12
  end
12
13
 
13
- alias_method "#{attribute}?", attribute
14
+ alias_method :"#{attribute}?", attribute
14
15
 
15
- setter_attribute = "#{field}="
16
- define_method("#{attribute}=") do |value|
16
+ setter_attribute = :"#{field}="
17
+ define_method(:"#{attribute}=") do |value|
17
18
  if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value)
18
19
  send(setter_attribute, nil)
19
20
  else
20
21
  send(setter_attribute, -> { Time.current }.())
21
22
  end
22
23
  end
24
+
25
+ define_method(:"#{attribute}!") do
26
+ send(:"#{attribute}=", true)
27
+ end
23
28
  end
24
29
  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
@@ -6,20 +6,24 @@ require "time_for_a_boolean/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "time_for_a_boolean"
8
8
  spec.version = TimeForABoolean::VERSION
9
- spec.authors = ["Caleb Thompson"]
10
- spec.email = ["caleb@calebthompson.io"]
9
+ spec.authors = ["Caleb Hearth"]
10
+ spec.email = ["caleb@calebhearth.com"]
11
11
  spec.description = <<-DESCRIPTION
12
12
  Use timestamp values to represent boolean data such as deleted, published,
13
13
  or subscribed.
14
14
  DESCRIPTION
15
15
  spec.summary = "Back boolean values with timestamps"
16
- spec.homepage = "https://github.com/calebthompson/time_for_a_boolean"
16
+ spec.homepage = "https://github.com/calebhearth/time_for_a_boolean"
17
17
  spec.license = "MIT"
18
18
 
19
19
  spec.files = `git ls-files`.split($/)
20
20
  spec.test_files = spec.files.grep(%r{^spec/})
21
21
  spec.require_paths = ["lib"]
22
22
 
23
+ spec.metadata = {
24
+ "funding-uri" => "https://github.com/sponsors/calebhearth"
25
+ }
26
+
23
27
  spec.add_dependency "activerecord"
24
28
  spec.add_dependency "railties"
25
29
 
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.2
5
5
  platform: ruby
6
6
  authors:
7
- - Caleb Thompson
8
- autorequire:
7
+ - Caleb Hearth
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -98,7 +98,7 @@ description: |2
98
98
  Use timestamp values to represent boolean data such as deleted, published,
99
99
  or subscribed.
100
100
  email:
101
- - caleb@calebthompson.io
101
+ - caleb@calebhearth.com
102
102
  executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
@@ -115,11 +115,12 @@ files:
115
115
  - lib/time_for_a_boolean/version.rb
116
116
  - spec/time_for_a_boolean_spec.rb
117
117
  - time_for_a_boolean.gemspec
118
- homepage: https://github.com/calebthompson/time_for_a_boolean
118
+ homepage: https://github.com/calebhearth/time_for_a_boolean
119
119
  licenses:
120
120
  - MIT
121
- metadata: {}
122
- post_install_message:
121
+ metadata:
122
+ funding-uri: https://github.com/sponsors/calebhearth
123
+ post_install_message:
123
124
  rdoc_options: []
124
125
  require_paths:
125
126
  - lib
@@ -134,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.6.14
139
- signing_key:
138
+ rubygems_version: 3.5.9
139
+ signing_key:
140
140
  specification_version: 4
141
141
  summary: Back boolean values with timestamps
142
142
  test_files: