banditmask 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 +2 -2
- data/banditmask.gemspec +2 -0
- data/bin/console +4 -4
- data/lib/banditmask.rb +17 -10
- data/lib/banditmask/banditry.rb +3 -7
- data/lib/banditmask/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89f4119902ba1674931d97b169c39ce1037ae2ae
|
4
|
+
data.tar.gz: a5db82f06d10b4bdc8ff6927d9cc872df3f89721
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec236a1784b37496fde1b63972587ff6bd57249dd7e68b3ae57107b52092274172fc99b188b31e2a0b7b97f04cf4da1f955356c339fb4c47fdb0bb3c0a5a91ce
|
7
|
+
data.tar.gz: 280fb89f74711b141be7a505e4f05756443276322407df26a326681a705116583089af90b4b66aa98349f35238fb9e101b0f775542fd4ece051ceb4d1a1629a2
|
data/README.md
CHANGED
@@ -61,7 +61,7 @@ mask.include? :execute # => false
|
|
61
61
|
Retrieve a list of all currently enabled bits.
|
62
62
|
|
63
63
|
```ruby
|
64
|
-
mask.
|
64
|
+
mask.bits # => [:read, :write]
|
65
65
|
```
|
66
66
|
|
67
67
|
In an class with a bitmask attribute, extend `BanditMask::Banditry` and call
|
@@ -80,7 +80,7 @@ obj = ObjectWithBitmaskAttribute.new
|
|
80
80
|
obj.bitmask = 0b011
|
81
81
|
```
|
82
82
|
|
83
|
-
This gives you a reader method which delegates to `BanditMask#
|
83
|
+
This gives you a reader method which delegates to `BanditMask#bits`.
|
84
84
|
|
85
85
|
```ruby
|
86
86
|
obj.bits # => [:read, :write]
|
data/banditmask.gemspec
CHANGED
data/bin/console
CHANGED
@@ -7,8 +7,8 @@ require "banditmask"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
12
|
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start
|
data/lib/banditmask.rb
CHANGED
@@ -72,20 +72,27 @@ class BanditMask
|
|
72
72
|
end
|
73
73
|
|
74
74
|
##
|
75
|
-
# Returns
|
76
|
-
#
|
77
|
-
# that was previously declared with BanditMask.bit.
|
75
|
+
# Returns false if any bit in +bits+ is not enabled. Returns true otherwise.
|
76
|
+
# Raises +ArgumentError+ if +bits+ is empty or if any element in +bits+ does
|
77
|
+
# not correspond to bit that was previously declared with BanditMask.bit.
|
78
78
|
#
|
79
79
|
# class BanditMask
|
80
|
-
# bit :read,
|
81
|
-
# bit :write,
|
80
|
+
# bit :read, 0b001
|
81
|
+
# bit :write, 0b010
|
82
|
+
# bit :execute, 0b100
|
82
83
|
# end
|
83
84
|
#
|
84
|
-
# mask = BanditMask.new
|
85
|
-
#
|
86
|
-
# mask.include? :
|
87
|
-
|
88
|
-
|
85
|
+
# mask = BanditMask.new 0b101
|
86
|
+
#
|
87
|
+
# mask.include? :read # => true
|
88
|
+
# mask.include? :write # => false
|
89
|
+
# mask.include? :execute # => true
|
90
|
+
#
|
91
|
+
# mask.include? :read, :write # => false
|
92
|
+
# mask.include? :read, :execute # => true
|
93
|
+
def include?(*bits)
|
94
|
+
raise ArgumentError, 'wrong number of arguments (0 for 1+)' if bits.empty?
|
95
|
+
bits.all? { |bit| bitmask & bit_value(bit) != 0 }
|
89
96
|
end
|
90
97
|
|
91
98
|
private
|
data/lib/banditmask/banditry.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
1
|
class BanditMask
|
4
2
|
module Banditry
|
5
|
-
def self.extended(cls) # :nodoc:
|
6
|
-
cls.extend Forwardable
|
7
|
-
end
|
8
|
-
|
9
3
|
##
|
10
4
|
# Creates wrapper methods for reading and writing the bitmask stored in
|
11
5
|
# +attribute+ using the class +with+. +with+ defaults to BanditMask, but
|
@@ -52,7 +46,9 @@ class BanditMask
|
|
52
46
|
send :"#{attribute}=", Integer(mask)
|
53
47
|
end
|
54
48
|
|
55
|
-
|
49
|
+
define_method :has? do |*bits|
|
50
|
+
cls.new(send(attribute)).include? *bits
|
51
|
+
end
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
data/lib/banditmask/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banditmask
|
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
|
- John Parker
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: BanditMask provides a generic wrapper class to manage a bitmask attribute.
|
56
70
|
email:
|
57
71
|
- jparker@urgetopunt.com
|