bitmask_attributes 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bitmask_attributes (0.1.1)
4
+ bitmask_attributes (0.2.1)
5
5
  activerecord (~> 3.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -53,6 +53,11 @@ Or, just check if any values are present:
53
53
  user.roles?
54
54
  # => true
55
55
 
56
+ You can get the list of values for any given attribute:
57
+
58
+ User.values_for_roles
59
+ # => [:writer, :publisher, :editor, :proofreader]
60
+
56
61
  Named Scopes
57
62
  ------------
58
63
 
@@ -19,7 +19,7 @@ module BitmaskAttributes
19
19
 
20
20
  def bitmasks
21
21
  @bitmasks ||= {}
22
- end
22
+ end
23
23
  end
24
24
  end
25
25
 
@@ -15,6 +15,7 @@ module BitmaskAttributes
15
15
  create_convenience_class_method_on model
16
16
  create_convenience_instance_methods_on model
17
17
  create_scopes_on model
18
+ create_attribute_methods_on model
18
19
  end
19
20
 
20
21
  private
@@ -60,6 +61,15 @@ module BitmaskAttributes
60
61
  )
61
62
  end
62
63
 
64
+ # Returns the defined values as an Array.
65
+ def create_attribute_methods_on(model)
66
+ model.class_eval %(
67
+ def self.values_for_#{attribute} # def self.values_for_numbers
68
+ #{values} # [:one, :two, :three]
69
+ end # end
70
+ )
71
+ end
72
+
63
73
  def create_convenience_class_method_on(model)
64
74
  model.class_eval %(
65
75
  def self.bitmask_for_#{attribute}(*values)
@@ -1,3 +1,3 @@
1
1
  module BitmaskAttributes
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -8,6 +8,10 @@ class BitmaskAttributesTest < ActiveSupport::TestCase
8
8
  Campaign.destroy_all
9
9
  end
10
10
 
11
+ should "return all defined values of a given bitmask attribute" do
12
+ assert_equal Campaign.values_for_medium, [:web, :print, :email, :phone]
13
+ end
14
+
11
15
  should "can assign single value to bitmask" do
12
16
  assert_stored Campaign.new(:medium => :web), :web
13
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmask_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-25 00:00:00.000000000 +01:00
13
- default_executable:
12
+ date: 2011-08-04 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
- requirement: &2151792720 !ruby/object:Gem::Requirement
16
+ requirement: &2153477300 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,7 +21,7 @@ dependencies:
22
21
  version: '3.0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2151792720
24
+ version_requirements: *2153477300
26
25
  description: Simple bitmask attribute support for ActiveRecord
27
26
  email: joel@developwithstyle.com
28
27
  executables: []
@@ -46,7 +45,6 @@ files:
46
45
  - test/support/helpers.rb
47
46
  - test/support/models.rb
48
47
  - test/test_helper.rb
49
- has_rdoc: true
50
48
  homepage: http://github.com/joelmoss/bitmask_attributes
51
49
  licenses: []
52
50
  post_install_message:
@@ -67,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
65
  version: '0'
68
66
  requirements: []
69
67
  rubyforge_project:
70
- rubygems_version: 1.3.9.2
68
+ rubygems_version: 1.8.6
71
69
  signing_key:
72
70
  specification_version: 3
73
71
  summary: Simple bitmask attribute support for ActiveRecord