sequel-bit_fields 0.6.0 → 0.7.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 +11 -1
  2. metadata +3 -3
@@ -10,6 +10,13 @@ module Sequel::Plugins
10
10
 
11
11
  def self.configure(model, bit_field_column, bit_fields, options = {})
12
12
  model.class_eval do
13
+ options[:scope] = bit_field_column if options[:scope] == true
14
+ options[:scope] = options[:scope].to_sym if options[:scope].is_a?(String)
15
+
16
+ if options[:scope].is_a?(Symbol)
17
+ bit_fields = bit_fields.map { |bit_field| "#{options[:scope]}_#{bit_field}".to_sym }
18
+ end
19
+
13
20
  @@bit_fields_for_models[model.to_s] ||= {}
14
21
  @@bit_fields_for_models[model.to_s][bit_field_column] = bit_fields
15
22
 
@@ -90,6 +97,9 @@ module Sequel::Plugins
90
97
  value = [true, 1, '1', 'true'].include?(value)
91
98
  current = self.send("#{bit_field_name}?".to_sym)
92
99
 
100
+ # init the bit_field with 0 if not yet set
101
+ self[bit_field_column] = 0 if self[bit_field_column].nil?
102
+
93
103
  self[bit_field_column] = if value && !current
94
104
  # value is true and current value is false
95
105
  self[bit_field_column] | index
@@ -109,7 +119,7 @@ module Sequel::Plugins
109
119
  # model.finished? # == false
110
120
  #
111
121
  define_method("#{bit_field_name}?") do
112
- self[bit_field_column] & index == index
122
+ (self[bit_field_column] || 0) & index == index
113
123
  end
114
124
  end
115
125
  end
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.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -49,7 +49,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  segments:
51
51
  - 0
52
- hash: 4121557822367938720
52
+ hash: -1276415395791307039
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements: