acts_as_flags 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,10 @@ module ActsAsFlags
10
10
  end
11
11
  end
12
12
 
13
+ (class << self; self; end).send(:define_method, "available_#{field}") do
14
+ flags
15
+ end
16
+
13
17
  define_method "#{field}=" do |new_flags|
14
18
  self.send("#{field}_mask=", (new_flags & flags).map { |r| 2**flags.index(r) }.sum )
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsFlags
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/readme.md CHANGED
@@ -9,7 +9,7 @@ Installation
9
9
  How to use it
10
10
  ---------------
11
11
  **Add it to your model**
12
- > acts_as_flags :flags, %w[ sent re-sent ]
12
+ > acts_as_flags :flags, %w[ sent re_sent ]
13
13
 
14
14
  **Add flag mask to your table**
15
15
  > \#rails g migration AddFlagsMaskToFoo
@@ -29,6 +29,23 @@ Instance Methods
29
29
  >
30
30
  > => [ "sent" ]
31
31
 
32
+ Class Methods
33
+ ----------------
34
+
35
+ **Searching records by flags**
36
+
37
+ It will create a method for each possible flag
38
+
39
+ **ex:**
40
+
41
+ > Foo.only_sent
42
+ >
43
+ > => Return all foos with the flagged sent
44
+ >
45
+ > Foo.only_re_sent
46
+ >
47
+ > => Return all foos with the flagged re_sent
48
+
32
49
 
33
50
 
34
51
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000 Z
12
+ date: 2012-05-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Make ActiveRecord Attributes to act as flags
15
15
  email: