sequel-bit_fields 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sequel/plugins/bit_fields.rb +10 -2
  2. metadata +2 -2
@@ -87,10 +87,18 @@ module Sequel::Plugins
87
87
  # model.finished = false
88
88
  #
89
89
  define_method("#{bit_field_name}=") do |value|
90
- self[bit_field_column] = if value
90
+ value = [true, 1, '1', 'true'].include?(value)
91
+ current = self.send("#{bit_field_name}?".to_sym)
92
+
93
+ self[bit_field_column] = if value && !current
94
+ # value is true and current value is false
91
95
  self[bit_field_column] | index
92
- else
96
+ elsif !value && current
97
+ # value is false and current value is true
93
98
  self[bit_field_column] ^ index
99
+ else
100
+ # don't do anything
101
+ self[bit_field_column]
94
102
  end
95
103
  end
96
104
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-bit_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -49,7 +49,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  segments:
51
51
  - 0
52
- hash: 4547982542808219160
52
+ hash: 4121557822367938720
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements: