banditmask 0.3.0 → 0.3.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 +1 -132
- data/banditmask.gemspec +7 -0
- data/lib/banditmask.rb +3 -0
- data/lib/banditmask/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bc728e7282f48a7f2b68abe40960893619622ab
|
4
|
+
data.tar.gz: e364832686de46d7229a5b72a39a786338f0dc1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb4c9763f19f7ffbc936a2f49ab59569bd04277c9d54b151a1f51c4a5cad1bfb5cc865fad8e2b51a89acc24487f51a57f83f2825af8838da697ecc6ee690bb4
|
7
|
+
data.tar.gz: 06260ac70e9fc1ce9d4a2fab8951adda40443d044a7a4e898cc669915522eafc52e702d73d0b85e7dc70647e30d5e00c0c2995a79e2536b3d291becbddf8caae
|
data/README.md
CHANGED
@@ -1,134 +1,3 @@
|
|
1
|
-
# [](http://badge.fury.io/rb/banditmask) [](https://travis-ci.org/jparker/banditmask)
|
2
|
-
|
3
1
|
# BanditMask
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'banditmask'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install banditmask
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
### BanditMask
|
26
|
-
|
27
|
-
Create a class which inherits from BanditMask, and declare the available bit
|
28
|
-
names and their corresponding values.
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
class ChmodMask < BanditMask
|
32
|
-
bit :read, 0b001
|
33
|
-
bit :write, 0b010
|
34
|
-
bit :execute, 0b100
|
35
|
-
end
|
36
|
-
|
37
|
-
ChmodMask.bits # => { :read => 1, :write => 2, :execute => 4 }
|
38
|
-
```
|
39
|
-
|
40
|
-
Instantiate a new mask class:
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
mask = ChmodMask.new
|
44
|
-
# or
|
45
|
-
current_bitmask = 0b001 | 0b010
|
46
|
-
mask = ChmodMask.new current_bitmask
|
47
|
-
```
|
48
|
-
|
49
|
-
Enable bits by name.
|
50
|
-
|
51
|
-
```ruby
|
52
|
-
mask << :read << :execute
|
53
|
-
```
|
54
|
-
|
55
|
-
Ask whether specific bits are enabled.
|
56
|
-
|
57
|
-
```ruby
|
58
|
-
mask.include? :read # => true
|
59
|
-
mask.include? :write # => false
|
60
|
-
mask.include? :execute # => true
|
61
|
-
mask.include? :read, :write # => false
|
62
|
-
mask.include? :read, :execute # => true
|
63
|
-
```
|
64
|
-
|
65
|
-
Retrieve a list of all currently enabled bits.
|
66
|
-
|
67
|
-
```ruby
|
68
|
-
mask.bits # => [:read, :execute]
|
69
|
-
```
|
70
|
-
|
71
|
-
### BanditMask::Banditry
|
72
|
-
|
73
|
-
In a class with a bitmask attribute, extend BanditMask::Banditry and call
|
74
|
-
BanditMask::Banditry.bandit_mask to add accessor methods for working with the
|
75
|
-
bitmask attribute.
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
class ObjectWithBitmaskAttribute
|
79
|
-
attr_accessor :bitmask
|
80
|
-
|
81
|
-
extend BanditMask::Banditry
|
82
|
-
bandit_mask :bitmask, as: :bits, with: ChmodMask
|
83
|
-
end
|
84
|
-
|
85
|
-
obj = ObjectWithBitmaskAttribute.new
|
86
|
-
obj.bitmask = 0b001
|
87
|
-
```
|
88
|
-
|
89
|
-
This gives you a reader method which returns the BanditMask representation
|
90
|
-
of the bitmask attribute.
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
obj.bits # => #<ChmodMask:0x007f941b9518c8 @bitmask=1>
|
94
|
-
```
|
95
|
-
|
96
|
-
It also gives you a writer method which lets you modify the bitmask. The
|
97
|
-
writer accepts BanditMask objects or an Array of bits.
|
98
|
-
|
99
|
-
```ruby
|
100
|
-
obj.bits |= :write
|
101
|
-
obj.bitmask # => 3
|
102
|
-
obj.bits = [:read, :execute]
|
103
|
-
obj.bitmask # => 5
|
104
|
-
```
|
105
|
-
|
106
|
-
Finally, it gives you a query method for checking whether particular bits are
|
107
|
-
set on the bitmask.
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
obj.bits? :read # => true
|
111
|
-
obj.bits? :write # => false
|
112
|
-
obj.bits? :execute # => true
|
113
|
-
obj.bits? :read, :write # => false
|
114
|
-
obj.bits? :read, :execute # => true
|
115
|
-
```
|
116
|
-
|
117
|
-
## Development
|
118
|
-
|
119
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
120
|
-
`bin/console` for an interactive prompt that will allow you to experiment.
|
121
|
-
|
122
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
123
|
-
release a new version, update the version number in `version.rb`, and then run
|
124
|
-
`bundle exec rake release` to create a git tag for the version, push git
|
125
|
-
commits and tags, and push the `.gem` file to
|
126
|
-
[rubygems.org](https://rubygems.org).
|
127
|
-
|
128
|
-
## Contributing
|
129
|
-
|
130
|
-
1. Fork it ( https://github.com/[my-github-username]/banditmask/fork )
|
131
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
132
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
133
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
134
|
-
5. Create a new Pull Request
|
3
|
+
Moved to [banditry](https://github.com/jparker/banditry).
|
data/banditmask.gemspec
CHANGED
@@ -26,4 +26,11 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency 'minitest', '~> 5.7'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'pry'
|
29
|
+
|
30
|
+
spec.post_install_message = <<-END
|
31
|
+
! The 'banditmask' gem has been deprecated and has been replaced by 'banditry'.
|
32
|
+
!
|
33
|
+
! See: https://rubygems.org/gems/banditry
|
34
|
+
! And: https://github.com/jparker/banditry
|
35
|
+
END
|
29
36
|
end
|
data/lib/banditmask.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Parker
|
@@ -89,7 +89,11 @@ homepage: https://github.com/jparker/banditmask
|
|
89
89
|
licenses:
|
90
90
|
- MIT
|
91
91
|
metadata: {}
|
92
|
-
post_install_message:
|
92
|
+
post_install_message: |
|
93
|
+
! The 'banditmask' gem has been deprecated and has been replaced by 'banditry'.
|
94
|
+
!
|
95
|
+
! See: https://rubygems.org/gems/banditry
|
96
|
+
! And: https://github.com/jparker/banditry
|
93
97
|
rdoc_options: []
|
94
98
|
require_paths:
|
95
99
|
- lib
|