sequel-bit-fields 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sequel-bit-fields.rb +27 -0
- metadata +46 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
|
3
|
+
module Sequel::Plugins
|
4
|
+
module BitFields
|
5
|
+
def self.configure(model, bit_field_column, bit_fields, options = {})
|
6
|
+
bit_fields.each_with_index do |bit_field_name, i|
|
7
|
+
model.instance_eval do
|
8
|
+
define_method("#{bit_field_name}=") do |value|
|
9
|
+
self[bit_field_column] = if value
|
10
|
+
self[bit_field_column] | (2**i)
|
11
|
+
else
|
12
|
+
self[bit_field_column] ^ (2**i)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method("#{bit_field_name}?") do
|
17
|
+
self[bit_field_column] & (2**i) == (2**i)
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method("#{bit_field_name}_sql") do
|
21
|
+
"#{bit_field_column} & #{2**i} = #{2**i}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sequel-bit-fields
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sascha Depold
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Use this plugin to add flags/bits to your Sequel based models.
|
15
|
+
email: sascha@depold.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/sequel-bit-fields.rb
|
21
|
+
homepage: https://github.com/sdepold/sequel-bit-fields
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.24
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: A Sequel compatible version of common bit field technique.
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|