bitmask_attribute 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0c71c63655e415f12efd67775d0a4b78595c476
4
+ data.tar.gz: 613e986dd470ea0c496adea31917833ccfcdd50c
5
+ SHA512:
6
+ metadata.gz: 1cb14946f64b7a8dab3e5deca483cca5dc146a77df669ba38affe0391d114d1a01b449f6094d840f160d54bdf8443148eadb25a4d34c31302f535b01d8cc9cbe
7
+ data.tar.gz: 9c0cb231bb95b5f7484a72a16d782c453c91dd0fc89ac9b44f53a644b958a8b90138cdcaadc10517fcd5e14002c886ab8c7c0f5b587bb0e596b9ab41ba97870a
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bitmask_attribute.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Madeline Carson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # BitmaskAttribute
2
+
3
+ This gem adds helper methods to your class to facilitate the use of bitmask attributes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bitmask_attribute'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bitmask_attribute
20
+
21
+ ## Usage
22
+
23
+ Include the concern in your class, and define which attribute is the bitmask attribute.
24
+ This attribute is expected to be an integer type.
25
+
26
+ ```
27
+ # has int attribute called actions
28
+ Class Foo
29
+ include BitmaskAttribute::Concern
30
+
31
+ ...
32
+
33
+ bitmask_attribute :actions
34
+ ```
35
+
36
+ You now get the following methods at your disposal:
37
+
38
+ `foo_instance.action_present?(1)`
39
+ -> returns boolean describing whether the actions attribute includes the input bit flag.
40
+
41
+ `foo_instance.add_action(1)`
42
+ -> adds the input bit flag to the mask
43
+
44
+ `foo_instance.remove_action(1)`
45
+ -> removes the input bit flag from the mask
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( https://github.com/[my-github-username]/bitmask_attribute/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bitmask_attribute/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitmask_attribute"
8
+ spec.version = BitmaskAttribute::VERSION
9
+ spec.authors = ["Madeline Carson"]
10
+ spec.email = ["madeline.carson@gmail.com"]
11
+ spec.summary = %q{Bitmask attribute helper methods for Rails models.}
12
+ spec.description = %q{Bitmask attribute helper methods for Rails models. Gives model access to methods to
13
+ check, add, and remove flags.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| f[3..-1] }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_dependency "activesupport", "~> 4.2"
26
+ end
@@ -0,0 +1,6 @@
1
+ require "bitmask_attribute/version"
2
+ require "bitmask_attribute/concern"
3
+
4
+ module BitmaskAttribute
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,28 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/inflector'
3
+
4
+ module BitmaskAttribute
5
+ module Concern
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+
10
+ def bitmask_attribute(name)
11
+ single_name = name.to_s.singularize
12
+ define_method "#{single_name}_present?" do |bit_sequence|
13
+ send(name) & bit_sequence == bit_sequence
14
+ end
15
+
16
+ define_method "add_#{single_name}" do |bit_sequence|
17
+ current_bits = send(name)
18
+ send("#{name}=", current_bits | bit_sequence)
19
+ end
20
+
21
+ define_method "remove_#{single_name}" do |bit_sequence|
22
+ current_bits = send(name)
23
+ send("#{name}=", current_bits & ~bit_sequence)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module BitmaskAttribute
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+ require "bitmask_attribute/concern"
3
+
4
+ RSpec.describe BitmaskAttribute::Concern do
5
+ let(:foo) { Foo.new }
6
+
7
+ describe "bitmask attribute present" do
8
+
9
+ context "where bit is present" do
10
+ before { foo.bitmask_attributes = 3 }
11
+
12
+ it "returns true" do
13
+ expect(foo.bitmask_attribute_present?(1)).to eql(true)
14
+ end
15
+ end
16
+
17
+ context "where bit is not present" do
18
+ before { foo.bitmask_attributes = 2 }
19
+
20
+ it "returns false" do
21
+ expect(foo.bitmask_attribute_present?(1)).to eql(false)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "add bitmask attribute" do
27
+ context "where the bit isn't present" do
28
+ before { foo.bitmask_attributes = 2 }
29
+
30
+ it "adds the bit to the bitmask" do
31
+ foo.add_bitmask_attribute(1)
32
+ expect(foo.bitmask_attributes).to eql(3)
33
+ end
34
+ end
35
+
36
+ context "where the bit is present" do
37
+ before { foo.bitmask_attributes = 3 }
38
+
39
+ it "doesn't add the bit to the bitmask" do
40
+ foo.add_bitmask_attribute(1)
41
+ expect(foo.bitmask_attributes).to eql(3)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "remove bitmask attribute" do
47
+ context "where the bit is present" do
48
+ before { foo.bitmask_attributes = 3 }
49
+
50
+ it "removes the bit from the bitmask" do
51
+ foo.remove_bitmask_attribute(1)
52
+ expect(foo.bitmask_attributes).to eql(2)
53
+ end
54
+ end
55
+
56
+ context "where the bit isn't present" do
57
+ before { foo.bitmask_attributes = 2 }
58
+
59
+ it "doesn't remove the bit from the bitmask" do
60
+ foo.remove_bitmask_attribute(1)
61
+ expect(foo.bitmask_attributes).to eql(2)
62
+ end
63
+ end
64
+ end
65
+
66
+ class Foo
67
+ include BitmaskAttribute::Concern
68
+
69
+ attr_accessor :bitmask_attributes
70
+
71
+ bitmask_attribute :bitmask_attributes
72
+ end
73
+ end
@@ -0,0 +1,103 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = 'doc'
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitmask_attribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Madeline Carson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.2'
69
+ description: |-
70
+ Bitmask attribute helper methods for Rails models. Gives model access to methods to
71
+ check, add, and remove flags.
72
+ email:
73
+ - madeline.carson@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bitmask_attribute.gemspec
85
+ - lib/bitmask_attribute.rb
86
+ - lib/bitmask_attribute/concern.rb
87
+ - lib/bitmask_attribute/version.rb
88
+ - spec/bitmask_attribute/concern_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Bitmask attribute helper methods for Rails models.
114
+ test_files:
115
+ - spec/bitmask_attribute/concern_spec.rb
116
+ - spec/spec_helper.rb
117
+ has_rdoc: