bitmask_attributes 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ rdoc
5
5
  pkg
6
6
  \#*
7
7
  .#*
8
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitmask_attributes (0.1.0)
4
+ bitmask_attributes (0.1.1)
5
5
  activerecord (~> 3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -65,11 +65,8 @@ A couple useful named scopes are also generated when you use
65
65
  # => (all editors)
66
66
  User.with_roles(:editor, :writer)
67
67
  # => (all users who are BOTH editors and writers)
68
-
69
- Later we'll support an `or` boolean; for now, do something like:
70
-
71
- User.with_roles(:editor) + User.with_roles(:writer)
72
- # => (all users who are EITHER editors and writers)
68
+ User.with_any_roles(:editor, :writer)
69
+ # => (all users who are editors OR writers)
73
70
 
74
71
  Find records without any bitmask set:
75
72
 
@@ -110,11 +110,24 @@ module BitmaskAttributes
110
110
  }
111
111
  scope :without_#{attribute}, :conditions => "#{attribute} = 0 OR #{attribute} IS NULL"
112
112
  scope :no_#{attribute}, :conditions => "#{attribute} = 0 OR #{attribute} IS NULL"
113
+
114
+ scope :with_any_#{attribute},
115
+ proc { |*values|
116
+ if values.blank?
117
+ {:conditions => '#{attribute} > 0 OR #{attribute} IS NOT NULL'}
118
+ else
119
+ sets = values.map do |value|
120
+ mask = #{model}.bitmask_for_#{attribute}(value)
121
+ "#{attribute} & \#{mask} <> 0"
122
+ end
123
+ {:conditions => sets.join(' OR ')}
124
+ end
125
+ }
113
126
  )
114
127
  values.each do |value|
115
128
  model.class_eval %(
116
129
  scope :#{attribute}_for_#{value},
117
- :conditions => ['#{attribute} & ? <> 0', #{model}.bitmask_for_#{attribute}(:#{value})]
130
+ :conditions => ['#{attribute} & ? <> 0', #{model}.bitmask_for_#{attribute}(:#{value})]
118
131
  )
119
132
  end
120
133
  end
@@ -1,3 +1,3 @@
1
1
  module BitmaskAttributes
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -137,6 +137,10 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
137
137
  assert_equal [@campaign1], @company.campaigns.with_medium(:print)
138
138
  end
139
139
 
140
+ should "support retrieval by any matching value (OR)" do
141
+ assert_equal [@campaign1, @campaign3], @company.campaigns.with_any_medium(:print, :email)
142
+ end
143
+
140
144
  should "support retrieval by all matching values" do
141
145
  assert_equal [@campaign1], @company.campaigns.with_medium(:web, :print)
142
146
  assert_equal [@campaign3], @company.campaigns.with_medium(:web, :email)
@@ -149,11 +153,9 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
149
153
 
150
154
  should "can check if at least one value is set" do
151
155
  campaign = Campaign.new(:medium => [:web, :print])
152
-
153
156
  assert campaign.medium?
154
157
 
155
158
  campaign = Campaign.new
156
-
157
159
  assert !campaign.medium?
158
160
  end
159
161
 
metadata CHANGED
@@ -1,38 +1,34 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bitmask_attributes
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
4
5
  prerelease:
5
- version: 0.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Joel Moss
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-05 00:00:00 +01:00
12
+ date: 2011-07-25 00:00:00.000000000 +01:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: activerecord
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2151792720 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
19
+ requirements:
22
20
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: "3.0"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
25
23
  type: :runtime
26
- version_requirements: *id001
24
+ prerelease: false
25
+ version_requirements: *2151792720
27
26
  description: Simple bitmask attribute support for ActiveRecord
28
27
  email: joel@developwithstyle.com
29
28
  executables: []
30
-
31
29
  extensions: []
32
-
33
30
  extra_rdoc_files: []
34
-
35
- files:
31
+ files:
36
32
  - .document
37
33
  - .gitignore
38
34
  - .rvmrc
@@ -41,7 +37,6 @@ files:
41
37
  - LICENSE
42
38
  - README.md
43
39
  - Rakefile
44
- - VERSION
45
40
  - bitmask_attributes.gemspec
46
41
  - lib/bitmask_attributes.rb
47
42
  - lib/bitmask_attributes/definition.rb
@@ -54,32 +49,29 @@ files:
54
49
  has_rdoc: true
55
50
  homepage: http://github.com/joelmoss/bitmask_attributes
56
51
  licenses: []
57
-
58
52
  post_install_message:
59
53
  rdoc_options: []
60
-
61
- require_paths:
54
+ require_paths:
62
55
  - lib
63
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
64
57
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
63
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: "0"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
75
68
  requirements: []
76
-
77
69
  rubyforge_project:
78
- rubygems_version: 1.3.9.1
70
+ rubygems_version: 1.3.9.2
79
71
  signing_key:
80
72
  specification_version: 3
81
73
  summary: Simple bitmask attribute support for ActiveRecord
82
- test_files:
74
+ test_files:
83
75
  - test/bitmask_attributes_test.rb
84
76
  - test/support/helpers.rb
85
77
  - test/support/models.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0