sequel-bit_fields 0.4.0 → 0.5.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 +36 -0
  2. metadata +3 -3
@@ -16,6 +16,42 @@ module Sequel::Plugins
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ unless self.respond_to?(:bit_field_indexes_for)
21
+ define_method("bit_field_indexes_for") do |*args|
22
+ if column_name = [*args].first
23
+ hash = {}
24
+
25
+ @@bit_fields[column_name].each_with_index do |attribute, i|
26
+ hash[attribute.to_sym] = 2**i
27
+ end
28
+
29
+ hash
30
+ else
31
+ raise 'No bit field name was passed!'
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ model.instance_eval do
38
+ unless self.respond_to?(:bit_field_values_for)
39
+ # inject the method bit_field_values_for which
40
+ # returns a hash with all the values of the bit_fields
41
+ define_method("bit_field_values_for") do |*args|
42
+ if column_name = [*args].first
43
+ hash = {}
44
+
45
+ @@bit_fields[column_name].each do |attribute|
46
+ hash[attribute.to_sym] = self.send("#{attribute}?".to_sym)
47
+ end
48
+
49
+ hash
50
+ else
51
+ raise 'No bit field name was passed!'
52
+ end
53
+ end
54
+ end
19
55
  end
20
56
 
21
57
  bit_fields.each_with_index do |bit_field_name, i|
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.4.0
4
+ version: 0.5.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-12 00:00:00.000000000 Z
12
+ date: 2012-11-29 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: 3721716346876275602
52
+ hash: -670273534307927132
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements: