bitmask_attribute 1.0.1 → 1.0.2

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: d0c71c63655e415f12efd67775d0a4b78595c476
4
- data.tar.gz: 613e986dd470ea0c496adea31917833ccfcdd50c
3
+ metadata.gz: 76ed99a443101270e21db0422f0b070f7ad281db
4
+ data.tar.gz: 26f8ece67e57f3d935c3c2697eab86a87f6298f9
5
5
  SHA512:
6
- metadata.gz: 1cb14946f64b7a8dab3e5deca483cca5dc146a77df669ba38affe0391d114d1a01b449f6094d840f160d54bdf8443148eadb25a4d34c31302f535b01d8cc9cbe
7
- data.tar.gz: 9c0cb231bb95b5f7484a72a16d782c453c91dd0fc89ac9b44f53a644b958a8b90138cdcaadc10517fcd5e14002c886ab8c7c0f5b587bb0e596b9ab41ba97870a
6
+ metadata.gz: 598ed1eec15354a30c4bad937074359c0bbc8763ff06a6b5e263e8fb46353b7d67041f6312bde51d85369f31335f2c6fc5ef22abc96bc44524cca9d0cbc4b9e1
7
+ data.tar.gz: ad5e1b39000e8b02dacedaf2de8c445e10a912766a6413b47da909fcada454d5889a7dcf8f83543094fc8ad29b7b70f5346f0fa641e70df8c41721218b4ac6ea
@@ -7,7 +7,7 @@ module BitmaskAttribute
7
7
 
8
8
  module ClassMethods
9
9
 
10
- def bitmask_attribute(name)
10
+ def bitmask_attribute(name, options_hash)
11
11
  single_name = name.to_s.singularize
12
12
  define_method "#{single_name}_present?" do |bit_sequence|
13
13
  send(name) & bit_sequence == bit_sequence
@@ -22,6 +22,12 @@ module BitmaskAttribute
22
22
  current_bits = send(name)
23
23
  send("#{name}=", current_bits & ~bit_sequence)
24
24
  end
25
+
26
+ options_hash.each do |key, value|
27
+ define_method "#{key}=" do |bool_value|
28
+ bool_value ? send("add_#{single_name}", value) : send("remove_#{single_name}", value)
29
+ end
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -1,3 +1,3 @@
1
1
  module BitmaskAttribute
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -63,11 +63,31 @@ RSpec.describe BitmaskAttribute::Concern do
63
63
  end
64
64
  end
65
65
 
66
+ describe "setting options" do
67
+ before { foo.bitmask_attributes = 1 }
68
+
69
+ describe "turning an option on" do
70
+ it "updates the attribute" do
71
+ foo.option_2 = true
72
+ expect(foo.bitmask_attributes).to eql(3)
73
+ end
74
+ end
75
+
76
+ describe "turning an option off" do
77
+ it "updates the attribute" do
78
+ foo.option_1 = false
79
+ expect(foo.bitmask_attributes).to eql(0)
80
+ end
81
+ end
82
+ end
83
+
66
84
  class Foo
67
85
  include BitmaskAttribute::Concern
68
86
 
69
87
  attr_accessor :bitmask_attributes
70
88
 
71
- bitmask_attribute :bitmask_attributes
89
+ OPTIONS = { option_1: 1, option_2: 2 }
90
+
91
+ bitmask_attribute :bitmask_attributes, OPTIONS
72
92
  end
73
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitmask_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Madeline Carson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler