bitmask_attributes_helpers 0.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.
- data/.document +5 -0
- data/.gitignore +11 -0
- data/.rvmrc +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +20 -0
- data/README.rdoc +68 -0
- data/Rakefile +144 -0
- data/bitmask_attributes_helpers.gemspec +18 -0
- data/info/exclude +6 -0
- data/lib/bitmask_attributes_helpers.rb +57 -0
- data/lib/bitmask_attributes_helpers/version.rb +3 -0
- data/spec/bitmask_attributes_helpers_spec.rb +114 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/models.rb +28 -0
- metadata +80 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.3@bitmask_attributes_helpers --create --install
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bitmask_attributes_helpers (0.0.1)
|
5
|
+
bitmask_attributes
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.2.13)
|
11
|
+
activesupport (= 3.2.13)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
activerecord (3.2.13)
|
14
|
+
activemodel (= 3.2.13)
|
15
|
+
activesupport (= 3.2.13)
|
16
|
+
arel (~> 3.0.2)
|
17
|
+
tzinfo (~> 0.3.29)
|
18
|
+
activesupport (3.2.13)
|
19
|
+
i18n (= 0.6.1)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
ansi (1.4.2)
|
22
|
+
arel (3.0.2)
|
23
|
+
bitmask_attributes (0.4.0)
|
24
|
+
activerecord (~> 3.0)
|
25
|
+
builder (3.0.4)
|
26
|
+
diff-lcs (1.2.4)
|
27
|
+
i18n (0.6.1)
|
28
|
+
multi_json (1.7.7)
|
29
|
+
polyamorous (0.5.0)
|
30
|
+
activerecord (~> 3.0)
|
31
|
+
rake (0.9.2.2)
|
32
|
+
rspec (2.13.0)
|
33
|
+
rspec-core (~> 2.13.0)
|
34
|
+
rspec-expectations (~> 2.13.0)
|
35
|
+
rspec-mocks (~> 2.13.0)
|
36
|
+
rspec-core (2.13.1)
|
37
|
+
rspec-expectations (2.13.0)
|
38
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
39
|
+
rspec-mocks (2.13.1)
|
40
|
+
sqlite3 (1.3.5)
|
41
|
+
squeel (1.0.18)
|
42
|
+
activerecord (~> 3.0)
|
43
|
+
activesupport (~> 3.0)
|
44
|
+
polyamorous (~> 0.5.0)
|
45
|
+
turn (0.8.3)
|
46
|
+
ansi
|
47
|
+
tzinfo (0.3.37)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bitmask_attributes
|
54
|
+
bitmask_attributes_helpers!
|
55
|
+
rake
|
56
|
+
rspec
|
57
|
+
sqlite3 (>= 1.3.5)
|
58
|
+
squeel
|
59
|
+
turn
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Ryan Chan
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
BitmaskAttributesHelpers
|
2
|
+
========================
|
3
|
+
|
4
|
+
Quick and simple helpers for Joel Moss' bitmask_attributes gem. These
|
5
|
+
helpers include frequently used checkers, setters, getters, and scopes
|
6
|
+
pertaining to the bitmasks.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation ##
|
10
|
+
|
11
|
+
The best way to install is with RubyGems:
|
12
|
+
|
13
|
+
$ [sudo] gem install bitmask_attributes_helpers
|
14
|
+
|
15
|
+
Or better still, just add it to your Gemfile:
|
16
|
+
|
17
|
+
gem 'bitmask_attributes_helpers'
|
18
|
+
|
19
|
+
|
20
|
+
## Examples/Usage ##
|
21
|
+
|
22
|
+
There are four class methods we use to install the requisite helpers:
|
23
|
+
`bitmask_presence_methods`, `bitmask_scopes`, `bitmask_virtual_attributes`,
|
24
|
+
and `bitmask_helpers`. Each takes the name of the bitmask as an argument.
|
25
|
+
|
26
|
+
```Ruby
|
27
|
+
class Model < ActiveRecord::Base
|
28
|
+
bitmask :colors, as: [:red, :blue, :green]
|
29
|
+
|
30
|
+
bitmask_presence_methods :colors
|
31
|
+
# Enables value checkers, i.e.
|
32
|
+
# model.red? => true if model has the red bitmask attribute set
|
33
|
+
|
34
|
+
bitmask_scopes :colors
|
35
|
+
# Enables scopes to search Model by bitmask values, i.e.
|
36
|
+
# Model.red => all models which have the red bit set to true
|
37
|
+
# Model.not_red => all models which have the red bit set to false
|
38
|
+
|
39
|
+
bitmask_virtual_attributes :colors
|
40
|
+
# Creates a virtual attribute on the model for each value of the bitmask,
|
41
|
+
i.e.
|
42
|
+
# model.red = true => sets the red bitmask to true
|
43
|
+
# model.red => true, as we've sets the bitmask to true
|
44
|
+
|
45
|
+
bitmask_helpers :colors
|
46
|
+
# This is a macro to enable all of the above for a specific bitmask
|
47
|
+
...
|
48
|
+
```
|
49
|
+
|
50
|
+
=== Contributing
|
51
|
+
|
52
|
+
1. Fork it.
|
53
|
+
2. Create a branch (`git checkout -b new-feature`)
|
54
|
+
3. Make your changes
|
55
|
+
4. Run the tests (`bundle install` then `bundle exec rake`)
|
56
|
+
5. Commit your changes (`git commit -am "Created new feature"`)
|
57
|
+
6. Push to the branch (`git push origin new-feature`)
|
58
|
+
7. Create a {pull request}[http://help.github.com/send-pull-requests/] from your branch.
|
59
|
+
8. Promote it. Get others to drop in and +1 it.
|
60
|
+
|
61
|
+
|
62
|
+
=== Credits
|
63
|
+
|
64
|
+
{Joel Moss}[https://github.com/joelmoss] deserves all the credit for his wonderful bitmask_attributes gem
|
65
|
+
|
66
|
+
=== Copyright
|
67
|
+
|
68
|
+
Copyright (c) 2013 Ryan Chan
|
data/Rakefile
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "bundler"
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
desc 'Default: run unit tests.'
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
#############################################################################
|
11
|
+
#
|
12
|
+
# Helper functions
|
13
|
+
#
|
14
|
+
#############################################################################
|
15
|
+
|
16
|
+
def name
|
17
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
18
|
+
end
|
19
|
+
|
20
|
+
def version
|
21
|
+
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
22
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
23
|
+
end
|
24
|
+
|
25
|
+
def gem_file
|
26
|
+
"#{name}-#{version}.gem"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rdoc/task'
|
30
|
+
require 'sdoc'
|
31
|
+
Rake::RDocTask.new do |rdoc|
|
32
|
+
rdoc.rdoc_dir = 'doc'
|
33
|
+
rdoc.title = "#{name} #{version}"
|
34
|
+
rdoc.options << '-f' << 'sdoc'
|
35
|
+
rdoc.options << '-a'
|
36
|
+
rdoc.options << '--markup' << 'tomdoc'
|
37
|
+
rdoc.options << '-m' << 'README.rdoc'
|
38
|
+
rdoc.rdoc_files.include('CHANGELOG*')
|
39
|
+
rdoc.rdoc_files.include('README*')
|
40
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#############################################################################
|
45
|
+
#
|
46
|
+
# Changeling
|
47
|
+
#
|
48
|
+
#############################################################################
|
49
|
+
|
50
|
+
namespace :changeling do
|
51
|
+
# desc "Bumps the version by a minor or patch version, depending on what was passed in."
|
52
|
+
task :bump, :part do |t, args|
|
53
|
+
unless `git branch` =~ /^\* master$/
|
54
|
+
puts "You must be on the master branch to bump the version!"
|
55
|
+
exit!
|
56
|
+
end
|
57
|
+
|
58
|
+
# Thanks, Jeweler!
|
59
|
+
if BitmaskAttributesHelper::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
|
60
|
+
major = $1.to_i
|
61
|
+
minor = $2.to_i
|
62
|
+
patch = $3.to_i
|
63
|
+
|
64
|
+
if $4 =~ /([a-z]+)(\d+)?/i
|
65
|
+
pre_name = $1
|
66
|
+
pre_version = ($2 || 0).to_i
|
67
|
+
end
|
68
|
+
else
|
69
|
+
abort
|
70
|
+
end
|
71
|
+
|
72
|
+
case args[:part]
|
73
|
+
when /minor/
|
74
|
+
minor += 1
|
75
|
+
patch = 0
|
76
|
+
when /patch/
|
77
|
+
patch += 1
|
78
|
+
when /pre/
|
79
|
+
pre_version += 1
|
80
|
+
pre = "#{pre_name}#{pre_version}"
|
81
|
+
else
|
82
|
+
abort
|
83
|
+
end
|
84
|
+
|
85
|
+
version = [major, minor, patch, pre].compact.join('.')
|
86
|
+
|
87
|
+
File.open(File.join("lib", name, "version.rb"), "w") do |f|
|
88
|
+
f.write <<EOF
|
89
|
+
module BitmaskAttributesHelper
|
90
|
+
VERSION = "#{version}".freeze
|
91
|
+
end
|
92
|
+
EOF
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# desc "Writes out the new CHANGELOG and prepares the release"
|
97
|
+
task :change do
|
98
|
+
unless `git branch` =~ /^\* master$/
|
99
|
+
puts "You must be on the master branch to update changelog!"
|
100
|
+
exit!
|
101
|
+
end
|
102
|
+
|
103
|
+
load "lib/#{name}/version.rb"
|
104
|
+
file = "CHANGELOG.md"
|
105
|
+
old = File.read(file)
|
106
|
+
message = "Bumping to version #{version}"
|
107
|
+
|
108
|
+
File.open(file, "w") do |f|
|
109
|
+
f.write <<EOF
|
110
|
+
## Version #{version} - #{Time.now} ##
|
111
|
+
|
112
|
+
#{`git log $(git tag | tail -1)..HEAD | git shortlog`.gsub /\s{6}/, "\n*"}
|
113
|
+
#{old}
|
114
|
+
EOF
|
115
|
+
end
|
116
|
+
|
117
|
+
Rake::Task['build'].invoke
|
118
|
+
exec ["#{ENV["EDITOR"]} #{file}",
|
119
|
+
"git commit -aqm '#{message}'",
|
120
|
+
"git tag -a -m '#{message}' v#{version}",
|
121
|
+
"git push origin master",
|
122
|
+
"git push origin $(git tag | tail -1)",
|
123
|
+
"gem push pkg/#{name}-#{version}.gem",
|
124
|
+
"echo '\n\033[32mReleased v#{version} /' `git show-ref -s refs/heads/master` '.\033[0m\n'"].join(' && ')
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Bump by a minor version (1.2.3 => 1.3.0)"
|
128
|
+
task :minor do |t|
|
129
|
+
Rake::Task['changeling:bump'].invoke(t.name)
|
130
|
+
Rake::Task['changeling:change'].invoke
|
131
|
+
end
|
132
|
+
|
133
|
+
desc "Bump by a patch version, (1.2.3 => 1.2.4)"
|
134
|
+
task :patch do |t|
|
135
|
+
Rake::Task['changeling:bump'].invoke(t.name)
|
136
|
+
Rake::Task['changeling:change'].invoke
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "Bump by a pre-release version, (1.0.0.pre1 => 1.0.0.pre2)"
|
140
|
+
task :pre do |t|
|
141
|
+
Rake::Task['changeling:bump'].invoke(t.name)
|
142
|
+
Rake::Task['changeling:change'].invoke
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bitmask_attributes_helpers/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "bitmask_attributes_helpers"
|
7
|
+
gem.summary = %Q{Getters, setters, and scopes for Joel Moss's bitmask_attributes gem}
|
8
|
+
gem.email = "ryan@ryanlchan"
|
9
|
+
gem.homepage = "http://github.com/ryanlchan/bitmask_attributes_helpers"
|
10
|
+
gem.authors = ['Ryan Chan']
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = BitmaskAttributesHelpers::VERSION.dup
|
16
|
+
|
17
|
+
gem.add_dependency 'bitmask_attributes'
|
18
|
+
end
|
data/info/exclude
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module BitmaskAttributesHelpers
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
# Helps set up presence + scopes for bitmasked attributes
|
6
|
+
|
7
|
+
# Setup presence checking methods for Bitmask attributes
|
8
|
+
#
|
9
|
+
# Presence attributes are setup as the possible values suffixed by a
|
10
|
+
# question mark, and return true or false
|
11
|
+
# @arg [Symbol] bitmask the name of the bitmask attribute
|
12
|
+
def bitmask_presence_methods(bitmask)
|
13
|
+
send("values_for_#{bitmask}").each do |value|
|
14
|
+
define_method "#{value}?" do
|
15
|
+
send("#{bitmask}?", value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Setup scopes for Bitmask attributes
|
21
|
+
#
|
22
|
+
# Scopes are setup with the same name as the value, and include both
|
23
|
+
# .value and .not_value versions
|
24
|
+
# @arg [Symbol] bitmask the name of the bitmask attribute
|
25
|
+
def bitmask_scopes(bitmask)
|
26
|
+
send("values_for_#{bitmask}").each do |value|
|
27
|
+
scope value, send("with_#{bitmask}", value)
|
28
|
+
scope "not_#{value}", send("without_#{bitmask}", value)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Setup virtual attributes for Bitmask attributes
|
33
|
+
#
|
34
|
+
# Allows you to set and read Bitmask attributes using #value= and
|
35
|
+
# #value methods
|
36
|
+
# @arg [Symbol] bitmask the name of the bitmask attribute
|
37
|
+
def bitmask_virtual_attributes(bitmask)
|
38
|
+
send("values_for_#{bitmask}").each do |value|
|
39
|
+
define_method("#{value}") { send("#{bitmask}?", value) }
|
40
|
+
define_method("#{value}=") { |arg| send("#{bitmask}=", arg.blank? || arg == "0" ? send("#{bitmask}") - [value] : send("#{bitmask}") << value) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Set up all bitmask helpers: Virtual Attributes, scopes, and presence
|
46
|
+
# checkers
|
47
|
+
#
|
48
|
+
# @arg [Symbol] bitmask the name of the bitmask attribute
|
49
|
+
def bitmask_helpers(bitmask)
|
50
|
+
bitmask_presence_methods(bitmask)
|
51
|
+
bitmask_scopes(bitmask)
|
52
|
+
bitmask_virtual_attributes(bitmask)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
ActiveRecord::Base.send :include, BitmaskAttributesHelpers
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Shared examples
|
4
|
+
|
5
|
+
##
|
6
|
+
# Shared examples for checker methods
|
7
|
+
# @arg [Model] model_class the model class to run the presence methods on
|
8
|
+
# @arg [String] bitmask the name of the bitmask
|
9
|
+
# @arg [String] true_value the name of the value which should be true
|
10
|
+
# @arg [String] false_value the name of the value which should be false
|
11
|
+
shared_examples_for "a bitmask with presence methods" do
|
12
|
+
describe '#value?' do
|
13
|
+
let(:model) { model_class.new({ "#{bitmask}" => [true_value.to_sym] }) }
|
14
|
+
context 'if the model has the bitmask attribute set' do
|
15
|
+
it 'returns true' do
|
16
|
+
model.send("#{true_value}?").should be
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'if the model does not have the bitmask attribute set' do
|
21
|
+
it 'returns false' do
|
22
|
+
model.send("#{false_value}?").should_not be
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Shared examples for scope methods
|
30
|
+
# @arg [Model] model_class the model class to run the checkers on
|
31
|
+
# @arg [String] true_value the name of the value which should be true
|
32
|
+
# @arg [String] false_value the name of the value which should be false
|
33
|
+
shared_examples_for "a bitmask with scopes" do
|
34
|
+
describe '.value' do
|
35
|
+
context 'when there are models with the value set' do
|
36
|
+
before(:each) { model_class.create({ "#{bitmask}" => [true_value.to_sym] }) }
|
37
|
+
it 'returns those models' do
|
38
|
+
model_class.send(true_value).should have_at_least(1).result
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when there are no models with the value set' do
|
43
|
+
before(:each) { model_class.create({ "#{bitmask}" => [true_value.to_sym] }) }
|
44
|
+
it 'returns an empty array' do
|
45
|
+
model_class.send(false_value).should have(0).results
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Shared examples for virtual attributes
|
53
|
+
# @arg [Model] model_class the model class to run the checkers on
|
54
|
+
# @arg [String] true_value the name of the value which should be true
|
55
|
+
# @arg [String] false_value the name of the value which should be false
|
56
|
+
shared_examples_for "a bitmask with virtual attributes" do
|
57
|
+
describe '#value' do
|
58
|
+
let(:model) { model_class.new({ "#{bitmask}" => [true_value.to_sym] }) }
|
59
|
+
context 'if the model has the bitmask attribute set' do
|
60
|
+
it 'returns true' do
|
61
|
+
model.send("#{true_value}").should be
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'if the model does not have the bitmask attribute set' do
|
66
|
+
it 'returns false' do
|
67
|
+
model.send("#{false_value}").should_not be
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#value=' do
|
73
|
+
let(:model) { model_class.new }
|
74
|
+
it 'can set the bitmask attribute to true' do
|
75
|
+
model.send("#{false_value}=", true)
|
76
|
+
model.send("#{false_value}").should be
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'can set the bitmask attribute to false' do
|
80
|
+
model.send("#{true_value}=", false)
|
81
|
+
model.send("#{true_value}").should_not be
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Running tests
|
87
|
+
|
88
|
+
describe BitmaskAttributesHelpers do
|
89
|
+
let(:bitmask) { :colors }
|
90
|
+
let(:true_value) { :raw_umber }
|
91
|
+
let(:false_value) { :pet_shop }
|
92
|
+
|
93
|
+
context 'with a bitmask with presence methods' do
|
94
|
+
let(:model_class) { CrayonWithPresenceMethods }
|
95
|
+
it_behaves_like 'a bitmask with presence methods'
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'with a bitmask with scopes' do
|
99
|
+
let(:model_class) { CrayonWithScopes }
|
100
|
+
it_behaves_like 'a bitmask with scopes'
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'with a bitmask with virtual attributes' do
|
104
|
+
let(:model_class) { CrayonWithVirtualAttributes }
|
105
|
+
it_behaves_like 'a bitmask with virtual attributes'
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'with a bitmask with helpers' do
|
109
|
+
let(:model_class) { CrayonWithHelpers }
|
110
|
+
it_behaves_like 'a bitmask with presence methods'
|
111
|
+
it_behaves_like 'a bitmask with scopes'
|
112
|
+
it_behaves_like 'a bitmask with virtual attributes'
|
113
|
+
end
|
114
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require 'active_record'
|
6
|
+
require 'squeel'
|
7
|
+
begin; require 'turn'; rescue LoadError; end
|
8
|
+
|
9
|
+
require 'bitmask_attributes'
|
10
|
+
require 'bitmask_attributes_helpers'
|
11
|
+
|
12
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
13
|
+
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection(
|
16
|
+
:adapter => 'sqlite3',
|
17
|
+
:database => ':memory:'
|
18
|
+
)
|
19
|
+
|
20
|
+
|
21
|
+
# Load support files
|
22
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
create_table :crayons do |t|
|
3
|
+
t.integer :colors
|
4
|
+
t.string :type # STI
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
# Pseudo models for testing purposes
|
9
|
+
|
10
|
+
class Crayon < ActiveRecord::Base
|
11
|
+
bitmask :colors, as: [:raw_umber, :pet_shop, :super_green, :periwinkle, :fuzzy_wuzzy_brown]
|
12
|
+
end
|
13
|
+
|
14
|
+
class CrayonWithPresenceMethods < Crayon
|
15
|
+
bitmask_presence_methods :colors
|
16
|
+
end
|
17
|
+
|
18
|
+
class CrayonWithScopes < Crayon
|
19
|
+
bitmask_scopes :colors
|
20
|
+
end
|
21
|
+
|
22
|
+
class CrayonWithVirtualAttributes < Crayon
|
23
|
+
bitmask_virtual_attributes :colors
|
24
|
+
end
|
25
|
+
|
26
|
+
class CrayonWithHelpers < Crayon
|
27
|
+
bitmask_helpers :colors
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitmask_attributes_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Chan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bitmask_attributes
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description:
|
31
|
+
email: ryan@ryanlchan
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- .document
|
37
|
+
- .gitignore
|
38
|
+
- .rvmrc
|
39
|
+
- .travis.yml
|
40
|
+
- CHANGELOG.md
|
41
|
+
- Gemfile
|
42
|
+
- Gemfile.lock
|
43
|
+
- LICENSE
|
44
|
+
- README.rdoc
|
45
|
+
- Rakefile
|
46
|
+
- bitmask_attributes_helpers.gemspec
|
47
|
+
- info/exclude
|
48
|
+
- lib/bitmask_attributes_helpers.rb
|
49
|
+
- lib/bitmask_attributes_helpers/version.rb
|
50
|
+
- spec/bitmask_attributes_helpers_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- spec/support/models.rb
|
53
|
+
homepage: http://github.com/ryanlchan/bitmask_attributes_helpers
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.25
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Getters, setters, and scopes for Joel Moss's bitmask_attributes gem
|
77
|
+
test_files:
|
78
|
+
- spec/bitmask_attributes_helpers_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spec/support/models.rb
|