mongoid-state_bits 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +9 -1
- data/lib/mongoid/state_bits/version.rb +1 -1
- data/lib/mongoid/state_bits.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc47a18577d1b54147c910d1b0d3f3ea8d500f80
|
4
|
+
data.tar.gz: 7f83d569607f74170184fc84b63888c26a8021d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46a121def0da67af613a2a9b177016e42e53c6eb5de55cbfed7ee48c51a4254172d4bc7a81765d590672eb699c80b169025ff0f9207f6f3440371510f28e476c
|
7
|
+
data.tar.gz: 65bfa4ec8ecbf3e8827f1a95f46b5cd90accd69bbecc126822f3c057a0a2ad240c48f6c62d66aed4eba224da031c96d60b6ed928f50074af89a1a4dad2cc1c20
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
When making the database design, we often need to add a lot of Boolean type field, such as whether to open an article, whether to allow comments, whether original and so on. When only a Boolean field, direct statement of Boolean type is OK; When there are a lot of field, it is clear eleven declarations harm than good, a waste of space and will bring a lot of duplicate code.
|
4
4
|
|
5
|
-
A common solution is that these boolean field are integrated into an integer field, a binary bit represents a Boolean field. For an article, if 1 (the first bit) means open, 2 (second bit) means commentable, 4 means original, then an open, commentable, original article was marked as 7 (1 +2 +4), open, does not allow comments, original articles marked as 5 (1 +0 +4). field can be marked with an integer instead of multiple Boolean attributes, obviously it is good, but doing so will cause inconvenience on code management. For a programmer
|
5
|
+
A common solution is that these boolean field are integrated into an integer field, a binary bit represents a Boolean field. For an article, if 1 (the first bit) means open, 2 (second bit) means commentable, 4 means original, then an open, commentable, original article was marked as 7 (1 +2 +4), open, does not allow comments, original articles marked as 5 (1 +0 +4). field can be marked with an integer instead of multiple Boolean attributes, obviously it is good, but doing so will cause inconvenience on code management. For a programmer, dealing directly with these flag bits will be a headache, and such code does not look elegant.
|
6
6
|
|
7
7
|
Mongoid::StateBits provides an elegant way to manage such situation.
|
8
8
|
|
@@ -33,6 +33,14 @@ Three state_bits statement of three boolean field will generate three methods fo
|
|
33
33
|
|
34
34
|
If you need to add field, just push it on to the end of this array %w{deleted commentable original}, the default value of all field is false(Boolean).
|
35
35
|
|
36
|
+
Now(v0.2.0) it supports default values:
|
37
|
+
|
38
|
+
class Post
|
39
|
+
include Mongoid::Document
|
40
|
+
include Mongoid::StateBits
|
41
|
+
state_bits deleted:false, commentable: true, original: true
|
42
|
+
end
|
43
|
+
|
36
44
|
## Contributing
|
37
45
|
|
38
46
|
1. Fork it ( http://github.com/Slacken/mongoid-state_bits/fork )
|
data/lib/mongoid/state_bits.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-state_bits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Binz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|