bitfields 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  Save migrations and columns by storing multiple booleans in a single integer.
2
- e.g. 3 = 1->true 2->true 4->false, 4 = 1->false 2->false 4->true, 5 = 1->true 2->false 4->true
2
+ e.g. true-false-false = 1, false-true-false = 2, true-false-true = 5 (1,2,4,8,..)
3
3
 
4
4
  class User < ActiveRecord::Base
5
5
  include Bitfields
@@ -9,13 +9,14 @@ e.g. 3 = 1->true 2->true 4->false, 4 = 1->false 2->false 4->true, 5 = 1->true 2-
9
9
  user = User.new(:seller => true, :insane => true)
10
10
  user.seller == true
11
11
  user.stupid? == false
12
- user.my_bits == 9
12
+ user.my_bits == 3
13
13
 
14
14
  - records changes `user.chamges == {:seller => [false, true]}`
15
15
  - adds scopes `User.seller.stupid.first` (deactivate with `bitfield ..., :scopes => false`)
16
16
  - builds sql `User.bitfield_sql(:insane => true, :stupid => false) == 'users.my_bits IN (2, 3)'` (2 and 1+2)
17
17
  - builds not-index-using sql with `bitfield ... ,:query_mode => :bit_operator` and `User.bitfield_sql(:insane => true, :stupid => false) == '(users.my_bits & 3) = 1'`, always slower than IN() sql, since it will not use an existing index (tested for up to 64 values)
18
18
  - builds update sql `User.set_bitfield_sql(:insane => true, :stupid => false) == 'my_bits = (my_bits | 6) - 4'`
19
+ - **faster sql than any other bitfield lib** through combination of multiple bits into a single sql statement
19
20
  - gives access to bits `User.bitfields[:my_bits][:stupid] == 4`
20
21
 
21
22
  Install
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bitfields}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-03-06}
12
+ s.date = %q{2010-04-25}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
@@ -53,7 +53,9 @@ module Bitfields
53
53
  end
54
54
 
55
55
  def bitfield_column(bit_name)
56
- bitfields.detect{|c, bits| bits.keys.include?(bit_name.to_sym) }.first
56
+ found = bitfields.detect{|c, bits| bits.keys.include?(bit_name.to_sym) }
57
+ raise "Unknown bitfield #{bit_name}" unless found
58
+ found.first
57
59
  end
58
60
 
59
61
  def bitfield_sql(bit_values)
@@ -57,6 +57,14 @@ describe Bitfields do
57
57
  end
58
58
  end
59
59
 
60
+ describe :bitfield_column do
61
+ it "raises a nice error when i use a unknown bitfield" do
62
+ lambda{
63
+ User.bitfield_column(:xxx)
64
+ }.should raise_error(RuntimeError, 'Unknown bitfield xxx')
65
+ end
66
+ end
67
+
60
68
  describe 'attribute accessors' do
61
69
  it "has everything on false by default" do
62
70
  User.new.seller.should == false
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-06 00:00:00 +01:00
17
+ date: 2010-04-25 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20