bitfields 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +6 -7
- data/VERSION +1 -1
- data/bitfields.gemspec +48 -0
- data/lib/bitfields.rb +4 -3
- metadata +3 -2
data/README.markdown
CHANGED
@@ -21,7 +21,7 @@ e.g. 3 = 1->true 2->true 4->false, 4 = 1->false 2->false 4->true, 5 = 1->true 2-
|
|
21
21
|
Install
|
22
22
|
=======
|
23
23
|
As Gem: ` sudo gem install bitfields `
|
24
|
-
Or as Rails plugin: ` script/
|
24
|
+
Or as Rails plugin: ` script/plugin install git://github.com/grosser/bitfields.git `
|
25
25
|
|
26
26
|
### Migration
|
27
27
|
ALWAYS set a default, bitfield queries will not work for NULL
|
@@ -29,17 +29,16 @@ ALWAYS set a default, bitfield queries will not work for NULL
|
|
29
29
|
OR
|
30
30
|
add_column :users, :my_bits, :integer, :default => 0, :null => false
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# update all users
|
32
|
+
Examples
|
33
|
+
========
|
34
|
+
Update all users
|
36
35
|
User.seller.not_stupid.update_all(User.set_bitfield_sql(:seller => true, :insane => true))
|
37
36
|
|
38
|
-
|
37
|
+
Delete the shop when a user is no longer a seller
|
39
38
|
before_save :delete_shop, :if => lambda{|u| u.changes['seller'] == [true, false]}
|
40
39
|
|
41
40
|
Author
|
42
41
|
======
|
43
42
|
[Michael Grosser](http://pragmatig.wordpress.com)
|
44
43
|
grosser.michael@gmail.com
|
45
|
-
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
44
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bitfields.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bitfields}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Michael Grosser"]
|
12
|
+
s.date = %q{2010-03-06}
|
13
|
+
s.email = %q{grosser.michael@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.markdown"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
"README.markdown",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"bitfields.gemspec",
|
22
|
+
"lib/bitfields.rb",
|
23
|
+
"spec/bitfields_spec.rb",
|
24
|
+
"spec/database.rb",
|
25
|
+
"spec/spec_helper.rb"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/grosser/bitfields}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.6}
|
31
|
+
s.summary = %q{Save migrations and columns by storing multiple booleans in a single integer.}
|
32
|
+
s.test_files = [
|
33
|
+
"spec/spec_helper.rb",
|
34
|
+
"spec/bitfields_spec.rb",
|
35
|
+
"spec/database.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
else
|
44
|
+
end
|
45
|
+
else
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/bitfields.rb
CHANGED
@@ -11,7 +11,8 @@ module Bitfields
|
|
11
11
|
|
12
12
|
def self.extract_bits(options)
|
13
13
|
bitfields = {}
|
14
|
-
options.keys.select{|key| key.is_a?(
|
14
|
+
options.keys.select{|key| key.is_a?(Fixnum) }.each do |bit|
|
15
|
+
raise "#{bit} is not a power of 2 !!" unless bit.to_s(2).scan('1').size == 1
|
15
16
|
bit_name = options.delete(bit).to_sym
|
16
17
|
bitfields[bit_name] = bit
|
17
18
|
end
|
@@ -36,7 +37,7 @@ module Bitfields
|
|
36
37
|
define_method("#{bit_name}?"){ bitfield_value(bit_name) }
|
37
38
|
define_method("#{bit_name}="){|value| set_bitfield_value(bit_name, value) }
|
38
39
|
if options[:scopes] != false
|
39
|
-
scoping_method = (respond_to?(:
|
40
|
+
scoping_method = (respond_to?(:named_scope) ? :named_scope : :scope) # AR 3.0+ uses scope
|
40
41
|
send scoping_method, bit_name, :conditions => bitfield_sql(bit_name => true)
|
41
42
|
send scoping_method, "not_#{bit_name}", :conditions => bitfield_sql(bit_name => false)
|
42
43
|
end
|
@@ -136,4 +137,4 @@ module Bitfields
|
|
136
137
|
]
|
137
138
|
end
|
138
139
|
end
|
139
|
-
end
|
140
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Grosser
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- README.markdown
|
31
31
|
- Rakefile
|
32
32
|
- VERSION
|
33
|
+
- bitfields.gemspec
|
33
34
|
- lib/bitfields.rb
|
34
35
|
- spec/bitfields_spec.rb
|
35
36
|
- spec/database.rb
|