mongoid-state_bits 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19044835ee724da47afa719178fcfb3bad1c51a2
4
- data.tar.gz: ade16ed0092d23e1d3eab400603e832a9bfa3b3e
3
+ metadata.gz: dc47a18577d1b54147c910d1b0d3f3ea8d500f80
4
+ data.tar.gz: 7f83d569607f74170184fc84b63888c26a8021d5
5
5
  SHA512:
6
- metadata.gz: 68f38ced9d72c32f6721ef4d2cc9c58ebf0b7926d5839faf5dc65be076dbb8ce035a3e4ca6fb3a2b63090132eb2f4181320248a55045a316d5d85d275cfea833
7
- data.tar.gz: 6a15429a9d66a481bed7e2e8e51f25b0812166f3e61bc791223e6dcf16940150ec3ca702789cab5c8e7d7e907fb0a4bbdcf601a97c1e40e6fcc383d62d918202
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 to deal directly with these flag bits will be a headache, and such code does not look elegant.
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 )
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module StateBits
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -32,7 +32,7 @@ module Mongoid
32
32
  # define methods
33
33
  bits.each_with_index do |bit, index|
34
34
  define_method "#{bit}=" do |bool|
35
- if bool
35
+ if ["true", true, "1", 1].include?(bool)
36
36
  self.state_bits |= 2**index
37
37
  else
38
38
  self.state_bits -= (self.state_bits & 2**index)
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.0
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-06-21 00:00:00.000000000 Z
11
+ date: 2014-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler