bitfield_attribute 1.0.0 → 1.0.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/lib/bitfield_attribute/base.rb +11 -2
- data/lib/bitfield_attribute/version.rb +1 -1
- data/spec/lib/activerecord_spec.rb +32 -16
- 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: e0f68aa834bb8f150a4bfcaa0534ad9b6693c004
|
4
|
+
data.tar.gz: 0808aa68a9a40ab6255baa675883b64222adb4a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8a40e0f86dc4f80a1cd04169c8ad7b178e84d3b8cd456afca7dde20db0629420d5b5887fce04837253a1b0ba01d8f218de3be68f7f3e90bf759cbcc92316171
|
7
|
+
data.tar.gz: 31613ce6251d03270fd5d9a5c3829c99b29dc35cc70b3dfce9da1858f2c9ee0b60f9ec9c3d057af019e19aea83b80d7a4fe919f692f3d2e2fbb10701145ebe9d
|
@@ -95,7 +95,10 @@ module BitfieldAttribute
|
|
95
95
|
end
|
96
96
|
write_bits
|
97
97
|
end
|
98
|
+
end
|
98
99
|
|
100
|
+
def as_json(options = nil)
|
101
|
+
attributes
|
99
102
|
end
|
100
103
|
|
101
104
|
private
|
@@ -108,8 +111,10 @@ module BitfieldAttribute
|
|
108
111
|
end
|
109
112
|
end
|
110
113
|
|
111
|
-
def write_bits(
|
112
|
-
if
|
114
|
+
def write_bits(predefined_bits = nil)
|
115
|
+
if predefined_bits.present?
|
116
|
+
bits = predefined_bits
|
117
|
+
else
|
113
118
|
bits = 0
|
114
119
|
@values.keys.each.with_index do |name, index|
|
115
120
|
bits = bits | (2 ** index) if @values[name]
|
@@ -117,6 +122,10 @@ module BitfieldAttribute
|
|
117
122
|
end
|
118
123
|
|
119
124
|
@instance[@attribute] = bits
|
125
|
+
|
126
|
+
if predefined_bits
|
127
|
+
read_bits
|
128
|
+
end
|
120
129
|
end
|
121
130
|
|
122
131
|
def true_value?(value)
|
@@ -10,22 +10,38 @@ describe BitField::DatabaseUser do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
describe "#update" do
|
14
|
+
it "works with initial attributes" do
|
15
|
+
BitField::DatabaseUser.create!(
|
16
|
+
name: "Artem",
|
17
|
+
bitfield: { first: true, second: false, last: true }
|
18
|
+
)
|
19
|
+
|
20
|
+
record = BitField::DatabaseUser.first
|
21
|
+
expect(record.bitfield.first?).to eq true
|
22
|
+
expect(record.bitfield.second?).to eq false
|
23
|
+
expect(record.bitfield.last?).to eq true
|
24
|
+
|
25
|
+
record.update!(record.attributes)
|
26
|
+
|
27
|
+
expect(record.bitfield.first?).to eq true
|
28
|
+
expect(record.bitfield.second?).to eq false
|
29
|
+
expect(record.bitfield.last?).to eq true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "works with changed attributes" do
|
33
|
+
BitField::DatabaseUser.create!(
|
34
|
+
name: "Artem",
|
35
|
+
bitfield: { first: true, second: true, last: true }
|
36
|
+
)
|
37
|
+
|
38
|
+
record = BitField::DatabaseUser.first
|
39
|
+
record.update!(bitfield: 7)
|
40
|
+
|
41
|
+
expect(record.bitfield.first?).to eq true
|
42
|
+
expect(record.bitfield.second?).to eq true
|
43
|
+
expect(record.bitfield.last?).to eq true
|
44
|
+
end
|
29
45
|
end
|
30
46
|
|
31
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitfield_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viktor Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|