Skip to content

Commit 6c74e89

Browse files
authored
Added kredis_boolean class method. (#59)
1 parent da08c12 commit 6c74e89

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/kredis/attributes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def kredis_hash(name, key: nil, typed: :string, config: :shared, after_change: n
7070
kredis_connection_with __method__, name, key, typed: typed, config: config, after_change: after_change
7171
end
7272

73+
def kredis_boolean(name, key: nil, config: :shared, after_change: nil, expires_in: nil)
74+
kredis_connection_with __method__, name, key, config: config, after_change: after_change, expires_in: expires_in
75+
end
76+
7377
private
7478
def kredis_connection_with(method, name, key, **options)
7579
ivar_symbol = :"@#{name}_#{method}"

test/attributes_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Person
2525
kredis_counter :amount
2626
kredis_string :temporary_password, expires_in: 1.second
2727
kredis_hash :high_scores, typed: :integer
28+
kredis_boolean :onboarded
2829

2930
def self.name
3031
"Person"
@@ -218,6 +219,14 @@ class AttributesTest < ActiveSupport::TestCase
218219
assert_equal([ 100, 42 ], @person.high_scores.values)
219220
end
220221

222+
test "boolean" do
223+
@person.onboarded.value = true
224+
assert @person.onboarded.value
225+
226+
@person.onboarded.value = false
227+
refute @person.onboarded.value
228+
end
229+
221230
test "missing id to constrain key" do
222231
assert_raise NotImplementedError do
223232
MissingIdPerson.new.anything

0 commit comments

Comments
 (0)