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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22148454d826a5aed539e10565456317fde44ce0
4
- data.tar.gz: c058f6722461be8857e46fd06877566b759be544
3
+ metadata.gz: e0f68aa834bb8f150a4bfcaa0534ad9b6693c004
4
+ data.tar.gz: 0808aa68a9a40ab6255baa675883b64222adb4a9
5
5
  SHA512:
6
- metadata.gz: 999ab9f3495bf06de562a9d3ecdebcaf4939b2277bf454dc1b8a686b1f9f570cf98d80d72acf7a5d5995236623aa369402bb7eb31c94cdb5a48e9b82f4503271
7
- data.tar.gz: cdfd13539d75cd867d8dc9c9148856fb262bf16d8432e362bf4721fd38afc037d3e5aef1aab99f8d7c267203f0c721a54b79e8ea66f7dcf6876a57b4dd1c3f1a
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(bits = nil)
112
- if bits.nil?
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)
@@ -1,3 +1,3 @@
1
1
  module BitfieldAttribute
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -10,22 +10,38 @@ describe BitField::DatabaseUser do
10
10
  end
11
11
  end
12
12
 
13
- it "works" do
14
- BitField::DatabaseUser.create!(
15
- name: "Artem",
16
- bitfield: { first: true, second: false, last: true }
17
- )
18
-
19
- record = BitField::DatabaseUser.first
20
- expect(record.bitfield.first?).to eq true
21
- expect(record.bitfield.second?).to eq false
22
- expect(record.bitfield.last?).to eq true
23
-
24
- record.update!(record.attributes)
25
-
26
- expect(record.bitfield.first?).to eq true
27
- expect(record.bitfield.second?).to eq false
28
- expect(record.bitfield.last?).to eq true
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.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-20 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler