sequel-bit_fields 0.5.1 → 0.5.2

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 +28 -22
  2. metadata +2 -2
@@ -2,47 +2,53 @@ require 'sequel'
2
2
 
3
3
  module Sequel::Plugins
4
4
  module BitFields
5
+ @@bit_fields_for_models = {}
6
+
7
+ def self.bit_fields_for_models
8
+ @@bit_fields_for_models
9
+ end
10
+
5
11
  def self.configure(model, bit_field_column, bit_fields, options = {})
6
12
  model.class_eval do
7
- @@bit_fields ||= {}
8
- @@bit_fields[bit_field_column] = bit_fields
9
- end
13
+ @@bit_fields_for_models[model.to_s] ||= {}
14
+ @@bit_fields_for_models[model.to_s][bit_field_column] = bit_fields
10
15
 
11
- unless model.respond_to?(:bit_fields)
12
- model.send(:define_singleton_method, :bit_fields) do |*args|
13
- if column_name = [*args].first
14
- @@bit_fields[column_name]
15
- else
16
- @@bit_fields
16
+ unless respond_to?(:bit_fields)
17
+ define_singleton_method(:bit_fields) do |*args|
18
+ if column_name = [*args].first
19
+ @@bit_fields_for_models[model.to_s][column_name]
20
+ else
21
+ @@bit_fields_for_models[model.to_s]
22
+ end
17
23
  end
18
24
  end
19
- end
20
25
 
21
- unless model.respond_to?(:bit_field_indexes_for)
22
- model.send(:define_singleton_method, :bit_field_indexes_for) do |*args|
23
- if column_name = [*args].first
24
- hash = {}
26
+ unless respond_to?(:bit_field_indexes_for)
27
+ define_singleton_method(:bit_field_indexes_for) do |*args|
28
+ if column_name = [*args].first
29
+ hash = {}
25
30
 
26
- @@bit_fields[column_name].each_with_index do |attribute, i|
27
- hash[attribute.to_sym] = 2**i
28
- end
31
+ @@bit_fields_for_models[model.to_s][column_name].each_with_index do |attribute, i|
32
+ hash[attribute.to_sym] = 2**i
33
+ end
29
34
 
30
- hash
31
- else
32
- raise 'No bit field name was passed!'
35
+ hash
36
+ else
37
+ raise 'No bit field name was passed!'
38
+ end
33
39
  end
34
40
  end
35
41
  end
36
42
 
37
43
  model.instance_eval do
38
- unless self.respond_to?(:bit_field_values_for)
44
+ unless respond_to?(:bit_field_values_for)
39
45
  # inject the method bit_field_values_for which
40
46
  # returns a hash with all the values of the bit_fields
41
47
  define_method("bit_field_values_for") do |*args|
42
48
  if column_name = [*args].first
43
49
  hash = {}
44
50
 
45
- @@bit_fields[column_name].each do |attribute|
51
+ @@bit_fields_for_models[model.to_s][column_name].each do |attribute|
46
52
  hash[attribute.to_sym] = self.send("#{attribute}?".to_sym)
47
53
  end
48
54
 
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.1
4
+ version: 0.5.2
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: 1844713943839378308
52
+ hash: 4547982542808219160
53
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements: