sequel-bit_fields 0.9.0 → 1.0.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 +24 -5
  2. metadata +7 -4
@@ -13,10 +13,28 @@ module Sequel::Plugins
13
13
  options[:scope] = bit_field_column if options[:scope] == true
14
14
  options[:scope] = options[:scope].to_sym if options[:scope].is_a?(String)
15
15
 
16
+ bit_fields = bit_fields.dup.map do |bit_field|
17
+ if bit_field.is_a?(Hash)
18
+ raise "Unnamed field: #{bit_field.inspect}" unless bit_field[:name]
19
+ bit_field
20
+ else
21
+ { :name => bit_field }
22
+ end
23
+ end
24
+
16
25
  if options[:scope].is_a?(Symbol)
17
- bit_fields = bit_fields.map { |bit_field| "#{options[:scope]}_#{bit_field}".to_sym }
26
+ bit_fields = bit_fields.map do |bit_field|
27
+ bit_field.merge(:name => "#{options[:scope]}_#{bit_field[:name]}".to_sym)
28
+ end
18
29
  end
19
30
 
31
+ bit_fields = bit_fields.map do |bit_field|
32
+ { :description => "Description for '#{bit_field[:name]}' not available." }.merge(bit_field)
33
+ end
34
+
35
+ # at this point, all bit_fields do have the following format:
36
+ # { description => 'something', :name => :something }
37
+
20
38
  @@bit_fields_for_models[model.to_s] ||= {}
21
39
  @@bit_fields_for_models[model.to_s][bit_field_column] = bit_fields
22
40
 
@@ -36,7 +54,7 @@ module Sequel::Plugins
36
54
  hash = {}
37
55
 
38
56
  @@bit_fields_for_models[model.to_s][column_name].each_with_index do |attribute, i|
39
- hash[attribute.to_sym] = 2**i
57
+ hash[attribute[:name].to_sym] = 2**i
40
58
  end
41
59
 
42
60
  hash
@@ -57,7 +75,7 @@ module Sequel::Plugins
57
75
  value = [*args][1]
58
76
 
59
77
  @@bit_fields_for_models[model.to_s][column_name].each do |attribute|
60
- hash[attribute.to_sym] = self.send("#{attribute}?".to_sym)
78
+ hash[attribute[:name].to_sym] = self.send("#{attribute[:name]}?".to_sym)
61
79
  end
62
80
 
63
81
  unless value.nil?
@@ -74,8 +92,9 @@ module Sequel::Plugins
74
92
  end
75
93
  end
76
94
 
77
- bit_fields.each_with_index do |bit_field_name, i|
78
- index = 2**i
95
+ bit_fields.each_with_index do |bit_field, i|
96
+ bit_field_name = bit_field[:name]
97
+ index = 2**i
79
98
 
80
99
  model.class.instance_eval do
81
100
  # inject the sql generator methods
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.9.0
4
+ version: 1.0.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: 2013-02-21 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -49,16 +49,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  segments:
51
51
  - 0
52
- hash: 496838917932258262
52
+ hash: 2545510621308517292
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ! '>='
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
+ segments:
60
+ - 0
61
+ hash: 2545510621308517292
59
62
  requirements: []
60
63
  rubyforge_project:
61
- rubygems_version: 1.8.24
64
+ rubygems_version: 1.8.23
62
65
  signing_key:
63
66
  specification_version: 3
64
67
  summary: A Sequel compatible version of common bit field technique.