has-bit-field 1.1.2 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d034fe72970e551a8353183549dd8cf92269792
4
- data.tar.gz: 50819ec9369f0fe9c0bc209ee689bc1255858e8e
3
+ metadata.gz: a96b5f28841290a879e97c9221cf6c082fe9ca1b
4
+ data.tar.gz: 8d2bbaa533f544bd63ea3a2f8ebc08fe46aae943
5
5
  SHA512:
6
- metadata.gz: c816a11939309384ba5849a4e7e117f9124880a0a87ef0aa4222741d1eb3d8cad8464cef30ea0927106d9a9ee3093b92600f2f670de4ec518fabe2085ea3453b
7
- data.tar.gz: b1cb839609aabfe996e387480b02b887e7343a7d4d208e457f64337648fb29c81e8b51b41e7ad7f5bf49bd3214d66638ac90cc35216fffe733c065a125e748fa
6
+ metadata.gz: e7e93b3644141de4d0321dd026948eda410fe94028e8c4dcec321b0b9bc99685bcf1463419f88fff5acf756d1ca49f0eb7f8fa26757dc51cea81abf5875eb059
7
+ data.tar.gz: d7e7028d4e4a0602388fb32670ae1ad72a25882512b5587e45751fac3997887e423f7e9e3ca9fcb10de071307ecf91e8965003d100bb5196b6957c929b05dc65
@@ -1,33 +1,41 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- has-bit-field (1.1.0)
4
+ has-bit-field (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- activemodel (3.2.11)
10
- activesupport (= 3.2.11)
11
- builder (~> 3.0.0)
12
- activerecord (3.2.11)
13
- activemodel (= 3.2.11)
14
- activesupport (= 3.2.11)
15
- arel (~> 3.0.2)
16
- tzinfo (~> 0.3.29)
17
- activesupport (3.2.11)
18
- i18n (~> 0.6)
19
- multi_json (~> 1.0)
20
- arel (3.0.2)
21
- builder (3.0.4)
22
- i18n (0.6.1)
23
- multi_json (1.5.0)
9
+ activemodel (4.0.2)
10
+ activesupport (= 4.0.2)
11
+ builder (~> 3.1.0)
12
+ activerecord (4.0.2)
13
+ activemodel (= 4.0.2)
14
+ activerecord-deprecated_finders (~> 1.0.2)
15
+ activesupport (= 4.0.2)
16
+ arel (~> 4.0.0)
17
+ activerecord-deprecated_finders (1.0.3)
18
+ activesupport (4.0.2)
19
+ i18n (~> 0.6, >= 0.6.4)
20
+ minitest (~> 4.2)
21
+ multi_json (~> 1.3)
22
+ thread_safe (~> 0.1)
23
+ tzinfo (~> 0.3.37)
24
+ arel (4.0.1)
25
+ atomic (1.1.14)
26
+ builder (3.1.4)
27
+ i18n (0.6.9)
28
+ minitest (4.7.5)
29
+ multi_json (1.8.4)
24
30
  sqlite3 (1.3.7)
25
- tzinfo (0.3.35)
31
+ thread_safe (0.1.3)
32
+ atomic
33
+ tzinfo (0.3.38)
26
34
 
27
35
  PLATFORMS
28
36
  ruby
29
37
 
30
38
  DEPENDENCIES
31
- activerecord (~> 3.0)
39
+ activerecord (~> 4.0)
32
40
  has-bit-field!
33
41
  sqlite3
data/README.md CHANGED
@@ -1,20 +1,13 @@
1
- has-bit-field
2
- =============
1
+ # has-bit-field
3
2
 
4
- has-bit-field allows you to use one attribute of an object to store a bit field which stores the boolean state for multiple flags.
3
+ has-bit-field allows you to use one attribute of an object to store a bit field which stores the boolean state for multiple flags. Requires Rails 3.0 or greater.
5
4
 
6
- **Rails 3.0.x**
5
+ ## Usage
7
6
 
8
7
  Add the gem to your Gemfile.
9
8
 
10
9
  gem 'has-bit-field'
11
10
 
12
- **Rails 2.3.x**
13
-
14
- To use this with Active Record, you would first require this gem in `config/environment.rb`:
15
-
16
- config.gem "has-bit-field"
17
-
18
11
  Now in one of your models, you define a bit field like this:
19
12
 
20
13
  class Person < ActiveRecord::Base
@@ -24,9 +17,8 @@ Now in one of your models, you define a bit field like this:
24
17
 
25
18
  This means that your database will have an integer column called `bit_field` which will hold the actual bit field. This will generate getter and setter methods for each of the fields. It will also generate a method that has `_bit` as a suffix which will give you the decimal value of the bit that that field is represented by in the bit field. Also there will be a named scope for that field, as well as a named scope prefixed with `not_`, if class you are adding the bit field to responds to `named_scope`. You can use it like this:
26
19
 
27
- $ script/console
28
- Loading development environment (Rails 2.3.2)
29
- p =>> p = Person.new
20
+ $ rails c
21
+ >> p = Person.new
30
22
  => #<Person id: nil, bit_field: nil, created_at: nil, updated_at: nil>
31
23
  >> p.likes_ice_cream = "true"
32
24
  => "true"
@@ -62,7 +54,6 @@ Another gotcha to be aware of is when combining a bit field with Active Record's
62
54
  has_bit_field :bit_field, :likes_ice_cream, :plays_golf, :watches_tv, :reads_books
63
55
  end
64
56
 
65
- Copyright
66
- ---------
57
+ ## Copyright
67
58
 
68
59
  Copyright (c) 2009 Paul Barry. See LICENSE for details.
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "has-bit-field"
16
16
  s.add_development_dependency "sqlite3"
17
- s.add_development_dependency "activerecord", "~> 3.0"
17
+ s.add_development_dependency "activerecord", "~> 4.0"
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -43,17 +43,21 @@ module HasBitField
43
43
  end
44
44
  }
45
45
 
46
- scope_sym = respond_to?(:validates) ? :scope : :named_scope
47
-
48
46
  if columns_hash[bit_field_attribute.to_s].null
49
- class_eval %{
50
- send scope_sym, :#{field}, :conditions => ["#{table_name}.#{bit_field_attribute} IS NOT NULL AND (#{table_name}.#{bit_field_attribute} & ?) != 0", #{field}_bit]
51
- send scope_sym, :not_#{field}, :conditions => ["#{table_name}.#{bit_field_attribute} IS NULL OR (#{table_name}.#{bit_field_attribute} & ?) = 0", #{field}_bit]
47
+ scope field, lambda {
48
+ where(arel_table[bit_field_attribute].not_eq(nil).
49
+ and(Arel::Nodes::InfixOperation.new(:&, arel_table[bit_field_attribute], 1<<i).not_eq(0)))
50
+ }
51
+ scope "not_#{field}", lambda {
52
+ where(arel_table[bit_field_attribute].eq(nil).
53
+ or(Arel::Nodes::InfixOperation.new(:&, arel_table[bit_field_attribute], 1<<i).eq(0)))
52
54
  }
53
55
  else
54
- class_eval %{
55
- send scope_sym, :#{field}, :conditions => ["(#{table_name}.#{bit_field_attribute} & ?) != 0", #{field}_bit]
56
- send scope_sym, :not_#{field}, :conditions => ["(#{table_name}.#{bit_field_attribute} & ?) = 0", #{field}_bit]
56
+ scope field, lambda {
57
+ where(Arel::Nodes::InfixOperation.new(:&, arel_table[bit_field_attribute], 1<<i).not_eq(0))
58
+ }
59
+ scope "not_#{field}", lambda {
60
+ where(Arel::Nodes::InfixOperation.new(:&, arel_table[bit_field_attribute], 1<<i).eq(0))
57
61
  }
58
62
  end
59
63
 
@@ -1,7 +1,7 @@
1
1
  module Has
2
2
  module Bit
3
3
  module Field
4
- VERSION = "1.1.2"
4
+ VERSION = "2.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -103,17 +103,17 @@ class HasBitFieldTest < Test::Unit::TestCase
103
103
 
104
104
  c = Person.create! :bit_field => 0
105
105
 
106
- assert_equal [b], Person.likes_ice_cream.all(:order => "id")
107
- assert_equal [a,c], Person.not_likes_ice_cream.all(:order => "id")
106
+ assert_equal [b], Person.likes_ice_cream.order("id").to_a
107
+ assert_equal [a,c], Person.not_likes_ice_cream.order("id").to_a
108
108
 
109
- assert_equal [a], Person.plays_golf.all(:order => "id")
110
- assert_equal [b,c], Person.not_plays_golf.all(:order => "id")
109
+ assert_equal [a], Person.plays_golf.order("id").to_a
110
+ assert_equal [b,c], Person.not_plays_golf.order("id").to_a
111
111
 
112
- assert_equal [b], Person.watches_tv.all(:order => "id")
113
- assert_equal [a,c], Person.not_watches_tv.all(:order => "id")
112
+ assert_equal [b], Person.watches_tv.order("id").to_a
113
+ assert_equal [a,c], Person.not_watches_tv.order("id").to_a
114
114
 
115
- assert_equal [a], Person.reads_books.all(:order => "id")
116
- assert_equal [b,c], Person.not_reads_books.all(:order => "id")
115
+ assert_equal [a], Person.reads_books.order("id").to_a
116
+ assert_equal [b,c], Person.not_reads_books.order("id").to_a
117
117
  end
118
118
 
119
119
  def test_named_scopes_on_non_nullable_column
@@ -132,14 +132,14 @@ class HasBitFieldTest < Test::Unit::TestCase
132
132
 
133
133
  c = Skill.create! :plays_piano => true, :chops_trees => true
134
134
 
135
- assert_equal [a,b,c], Skill.plays_piano.all(:order => "id")
136
- assert_equal [], Skill.not_plays_piano.all(:order => "id")
135
+ assert_equal [a,b,c], Skill.plays_piano.order("id").to_a
136
+ assert_equal [], Skill.not_plays_piano.order("id").to_a
137
137
 
138
- assert_equal [a], Skill.mops_floors.all(:order => "id")
139
- assert_equal [b,c], Skill.not_mops_floors.all(:order => "id")
138
+ assert_equal [a], Skill.mops_floors.order("id").to_a
139
+ assert_equal [b,c], Skill.not_mops_floors.order("id").to_a
140
140
 
141
- assert_equal [b], Skill.makes_soup.all(:order => "id")
142
- assert_equal [a,c], Skill.not_makes_soup.all(:order => "id")
141
+ assert_equal [b], Skill.makes_soup.order("id").to_a
142
+ assert_equal [a,c], Skill.not_makes_soup.order("id").to_a
143
143
  end
144
144
 
145
145
  def test_dirty_attributes
@@ -11,3 +11,4 @@ require File.join(File.dirname(__FILE__), "../rails/init")
11
11
  require 'has-bit-field'
12
12
 
13
13
  #ActiveRecord::Base.logger = Logger.new($stdout)
14
+ I18n.enforce_available_locales = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has-bit-field
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-22 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '4.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: '4.0'
41
41
  description: Provides an easy way to work with bit fields in active record
42
42
  email:
43
43
  - mail@paulbarry.com
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project: has-bit-field
81
- rubygems_version: 2.0.3
81
+ rubygems_version: 2.0.14
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: Provides an easy way to work with bit fields in active record