Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/click_house/type/boolean_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ module Type
class BooleanType < BaseType
TRUE_VALUE = 1
FALSE_VALUE = 0
TRUE_VALUES = Set[1, '1', true].freeze

def cast(value)
case value
when TrueClass, FalseClass
value
else
value.to_i == TRUE_VALUE
end
TRUE_VALUES.include?(value)
end

def serialize(value)
value ? TRUE_VALUE : FALSE_VALUE
TRUE_VALUES.include?(value) ? TRUE_VALUE : FALSE_VALUE
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/click_house/integration/boolean_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
expect(got.fetch('a')).to be_a(TrueClass)
expect(got.fetch('b')).to be_a(FalseClass)
expect(got.fetch('c')).to be_a(TrueClass)
expect(got.fetch('b')).to be_a(FalseClass)
expect(got.fetch('d')).to be_a(FalseClass)
expect(got.fetch('e')).to be_a(NilClass)
end
end
Expand All @@ -58,7 +58,7 @@
expect(got.fetch('a')).to be_a(TrueClass)
expect(got.fetch('b')).to be_a(FalseClass)
expect(got.fetch('c')).to be_a(TrueClass)
expect(got.fetch('b')).to be_a(FalseClass)
expect(got.fetch('d')).to be_a(FalseClass)
expect(got.fetch('e')).to be_a(NilClass)
end
end
Expand Down