bitmask_attributes 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/CHANGELOG.rdoc +14 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +18 -11
- data/{README.md → README.rdoc} +27 -28
- data/Rakefile +137 -0
- data/bitmask_attributes.gemspec +1 -3
- data/doc/apple-touch-icon.png +0 -0
- data/doc/classes/BitmaskAttributes.html +114 -0
- data/doc/classes/BitmaskAttributes/ClassMethods.html +205 -0
- data/doc/classes/BitmaskAttributes/Definition.html +690 -0
- data/doc/classes/BitmaskAttributes/ValueProxy.html +468 -0
- data/doc/created.rid +7 -0
- data/doc/css/github.css +129 -0
- data/doc/css/main.css +326 -0
- data/doc/css/panel.css +384 -0
- data/doc/css/reset.css +48 -0
- data/doc/favicon.ico +0 -0
- data/doc/files/CHANGELOG_rdoc.html +67 -0
- data/doc/files/README_rdoc.html +224 -0
- data/doc/files/lib/bitmask_attributes/definition_rb.html +83 -0
- data/doc/files/lib/bitmask_attributes/value_proxy_rb.html +83 -0
- data/doc/files/lib/bitmask_attributes/version_rb.html +78 -0
- data/doc/files/lib/bitmask_attributes_rb.html +93 -0
- data/doc/i/arrows.png +0 -0
- data/doc/i/results_bg.png +0 -0
- data/doc/i/tree_bg.png +0 -0
- data/doc/index.html +13 -0
- data/doc/js/highlight.pack.js +1 -0
- data/doc/js/jquery-1.3.2.min.js +19 -0
- data/doc/js/jquery-effect.js +593 -0
- data/doc/js/main.js +24 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searchdoc.js +442 -0
- data/doc/js/searcher.js +228 -0
- data/doc/panel/index.html +73 -0
- data/doc/panel/links.html +18 -0
- data/doc/panel/tree.js +1 -0
- data/lib/bitmask_attributes/definition.rb +4 -4
- data/lib/bitmask_attributes/version.rb +1 -1
- metadata +39 -6
data/.gitignore
CHANGED
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
=== Version 0.2.4 - 2011-11-23 09:37:50 +0000
|
2
|
+
|
3
|
+
Ivan Buiko (3):
|
4
|
+
* add netbeans project files to .gitignore
|
5
|
+
* latest versions in Gemfile.lock
|
6
|
+
* don't validate attribute during creating table
|
7
|
+
|
8
|
+
Joel Moss (3):
|
9
|
+
* Merge pull request #3 from IvanBuiko/master
|
10
|
+
* Added changeling tasks
|
11
|
+
* Created docs
|
12
|
+
|
13
|
+
|
14
|
+
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,34 +1,40 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bitmask_attributes (0.2.
|
4
|
+
bitmask_attributes (0.2.3)
|
5
5
|
activerecord (~> 3.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (3.1.
|
11
|
-
activesupport (= 3.1.
|
10
|
+
activemodel (3.1.3)
|
11
|
+
activesupport (= 3.1.3)
|
12
12
|
builder (~> 3.0.0)
|
13
13
|
i18n (~> 0.6)
|
14
|
-
activerecord (3.1.
|
15
|
-
activemodel (= 3.1.
|
16
|
-
activesupport (= 3.1.
|
14
|
+
activerecord (3.1.3)
|
15
|
+
activemodel (= 3.1.3)
|
16
|
+
activesupport (= 3.1.3)
|
17
17
|
arel (~> 2.2.1)
|
18
18
|
tzinfo (~> 0.3.29)
|
19
|
-
activesupport (3.1.
|
19
|
+
activesupport (3.1.3)
|
20
20
|
multi_json (~> 1.0)
|
21
|
-
ansi (1.
|
21
|
+
ansi (1.4.1)
|
22
22
|
arel (2.2.1)
|
23
23
|
builder (3.0.0)
|
24
24
|
i18n (0.6.0)
|
25
|
+
json (1.6.1)
|
25
26
|
multi_json (1.0.3)
|
26
27
|
rake (0.9.2.2)
|
28
|
+
rdoc (3.11)
|
29
|
+
json (~> 1.4)
|
30
|
+
sdoc (0.3.16)
|
31
|
+
json (>= 1.1.3)
|
32
|
+
rdoc (~> 3.10)
|
27
33
|
shoulda (2.11.3)
|
28
34
|
sqlite3 (1.3.4)
|
29
|
-
turn (0.8.
|
30
|
-
ansi
|
31
|
-
tzinfo (0.3.
|
35
|
+
turn (0.8.3)
|
36
|
+
ansi
|
37
|
+
tzinfo (0.3.31)
|
32
38
|
|
33
39
|
PLATFORMS
|
34
40
|
ruby
|
@@ -36,6 +42,7 @@ PLATFORMS
|
|
36
42
|
DEPENDENCIES
|
37
43
|
bitmask_attributes!
|
38
44
|
rake
|
45
|
+
sdoc
|
39
46
|
shoulda
|
40
47
|
sqlite3 (>= 1.3.4)
|
41
48
|
turn
|
data/{README.md → README.rdoc}
RENAMED
@@ -1,46 +1,45 @@
|
|
1
|
-
BitmaskAttributes
|
2
|
-
=================
|
1
|
+
== BitmaskAttributes
|
3
2
|
|
4
3
|
Transparent manipulation of bitmask attributes for ActiveRecord, based on
|
5
4
|
the bitmask-attribute gem, which has been dormant since 2009. This updated
|
6
5
|
gem work with Rails 3 and up (including Rails 3.1).
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
|
8
|
+
=== Installation
|
10
9
|
|
11
10
|
The best way to install is with RubyGems:
|
12
11
|
|
13
12
|
$ [sudo] gem install bitmask_attributes
|
14
|
-
|
13
|
+
|
15
14
|
Or better still, just add it to your Gemfile:
|
16
15
|
|
17
16
|
gem 'bitmask_attributes'
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
=== Example
|
21
20
|
|
22
21
|
Simply declare an existing integer column as a bitmask with its possible
|
23
22
|
values.
|
24
23
|
|
25
24
|
class User < ActiveRecord::Base
|
26
|
-
bitmask :roles, :as => [:writer, :publisher, :editor, :proofreader]
|
25
|
+
bitmask :roles, :as => [:writer, :publisher, :editor, :proofreader]
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
You can then modify the column using the declared values without resorting
|
30
29
|
to manual bitmasks.
|
31
|
-
|
30
|
+
|
32
31
|
user = User.create(:name => "Bruce", :roles => [:publisher, :editor])
|
33
32
|
user.roles
|
34
33
|
# => [:publisher, :editor]
|
35
34
|
user.roles << :writer
|
36
35
|
user.roles
|
37
36
|
# => [:publisher, :editor, :writer]
|
38
|
-
|
37
|
+
|
39
38
|
It's easy to find out if a record has a given value:
|
40
39
|
|
41
40
|
user.roles?(:editor)
|
42
41
|
# => true
|
43
|
-
|
42
|
+
|
44
43
|
You can check for multiple values (uses an `and` boolean):
|
45
44
|
|
46
45
|
user.roles?(:editor, :publisher)
|
@@ -58,8 +57,8 @@ You can get the list of values for any given attribute:
|
|
58
57
|
User.values_for_roles
|
59
58
|
# => [:writer, :publisher, :editor, :proofreader]
|
60
59
|
|
61
|
-
|
62
|
-
|
60
|
+
|
61
|
+
=== Named Scopes
|
63
62
|
|
64
63
|
A couple useful named scopes are also generated when you use
|
65
64
|
`bitmask`:
|
@@ -87,8 +86,8 @@ Find records without a specific attribute.
|
|
87
86
|
|
88
87
|
Note that "without_" only supports a single attribute argument, and the "no_" method does not support arguments.
|
89
88
|
|
90
|
-
|
91
|
-
|
89
|
+
|
90
|
+
=== Adding Methods
|
92
91
|
|
93
92
|
You can add your own methods to the bitmasked attributes (similar to
|
94
93
|
named scopes):
|
@@ -104,15 +103,14 @@ named scopes):
|
|
104
103
|
# => true
|
105
104
|
|
106
105
|
|
107
|
-
Warning: Modifying possible values
|
108
|
-
----------------------------------
|
106
|
+
=== Warning: Modifying possible values
|
109
107
|
|
110
108
|
IMPORTANT: Once you have data using a bitmask, don't change the order
|
111
109
|
of the values, remove any values, or insert any new values in the `:as`
|
112
110
|
array anywhere except at the end. You won't like the results.
|
113
111
|
|
114
|
-
|
115
|
-
|
112
|
+
|
113
|
+
=== Contributing
|
116
114
|
|
117
115
|
1. Fork it.
|
118
116
|
2. Create a branch (`git checkout -b new-feature`)
|
@@ -120,19 +118,20 @@ Contributing
|
|
120
118
|
4. Run the tests (`bundle install` then `bundle exec rake`)
|
121
119
|
5. Commit your changes (`git commit -am "Created new feature"`)
|
122
120
|
6. Push to the branch (`git push origin new-feature`)
|
123
|
-
7. Create a [
|
121
|
+
7. Create a {pull request}[http://help.github.com/send-pull-requests/] from your branch.
|
124
122
|
8. Promote it. Get others to drop in and +1 it.
|
125
123
|
|
126
|
-
Credits
|
127
|
-
-------
|
128
124
|
|
129
|
-
|
125
|
+
=== Credits
|
126
|
+
|
127
|
+
Thanks to {Bruce Williams}[https://github.com/bruce] and the following contributors
|
130
128
|
of the bitmask-attribute plugin:
|
131
129
|
|
132
|
-
*
|
133
|
-
*
|
130
|
+
* {Jason L Perry}[http://github.com/ambethia]
|
131
|
+
* {Nicolas Fouché}[http://github.com/nfo]
|
132
|
+
* {Ivan Buiko}[http://github.com/IvanBuiko]
|
133
|
+
|
134
134
|
|
135
|
-
Copyright
|
136
|
-
---------
|
135
|
+
=== Copyright
|
137
136
|
|
138
137
|
Copyright (c) 2007-2009 Bruce Williams & 2011 Joel Moss. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -13,4 +13,141 @@ Rake::TestTask.new(:test) do |t|
|
|
13
13
|
t.libs << 'test'
|
14
14
|
t.pattern = 'test/**/*_test.rb'
|
15
15
|
t.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#############################################################################
|
20
|
+
#
|
21
|
+
# Helper functions
|
22
|
+
#
|
23
|
+
#############################################################################
|
24
|
+
|
25
|
+
def name
|
26
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
27
|
+
end
|
28
|
+
|
29
|
+
def version
|
30
|
+
line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
31
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
def gem_file
|
35
|
+
"#{name}-#{version}.gem"
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'rdoc/task'
|
39
|
+
require 'sdoc'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
rdoc.rdoc_dir = 'doc'
|
42
|
+
rdoc.title = "#{name} #{version}"
|
43
|
+
rdoc.options << '-f' << 'sdoc'
|
44
|
+
rdoc.options << '-a'
|
45
|
+
rdoc.options << '--markup' << 'tomdoc'
|
46
|
+
rdoc.options << '-m' << 'README.rdoc'
|
47
|
+
rdoc.rdoc_files.include('CHANGELOG*')
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
#############################################################################
|
54
|
+
#
|
55
|
+
# Changeling
|
56
|
+
#
|
57
|
+
#############################################################################
|
58
|
+
|
59
|
+
namespace :changeling do
|
60
|
+
# desc "Bumps the version by a minor or patch version, depending on what was passed in."
|
61
|
+
task :bump, :part do |t, args|
|
62
|
+
unless `git branch` =~ /^\* master$/
|
63
|
+
puts "You must be on the master branch to bump the version!"
|
64
|
+
exit!
|
65
|
+
end
|
66
|
+
|
67
|
+
# Thanks, Jeweler!
|
68
|
+
if BitmaskAttributes::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
|
69
|
+
major = $1.to_i
|
70
|
+
minor = $2.to_i
|
71
|
+
patch = $3.to_i
|
72
|
+
|
73
|
+
if $4 =~ /([a-z]+)(\d+)?/i
|
74
|
+
pre_name = $1
|
75
|
+
pre_version = ($2 || 0).to_i
|
76
|
+
end
|
77
|
+
else
|
78
|
+
abort
|
79
|
+
end
|
80
|
+
|
81
|
+
case args[:part]
|
82
|
+
when /minor/
|
83
|
+
minor += 1
|
84
|
+
patch = 0
|
85
|
+
when /patch/
|
86
|
+
patch += 1
|
87
|
+
when /pre/
|
88
|
+
pre_version += 1
|
89
|
+
pre = "#{pre_name}#{pre_version}"
|
90
|
+
else
|
91
|
+
abort
|
92
|
+
end
|
93
|
+
|
94
|
+
version = [major, minor, patch, pre].compact.join('.')
|
95
|
+
|
96
|
+
File.open(File.join("lib", name, "version.rb"), "w") do |f|
|
97
|
+
f.write <<EOF
|
98
|
+
module BitmaskAttributes
|
99
|
+
VERSION = "#{version}".freeze
|
100
|
+
end
|
101
|
+
EOF
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# desc "Writes out the new CHANGELOG and prepares the release"
|
106
|
+
task :change do
|
107
|
+
unless `git branch` =~ /^\* master$/
|
108
|
+
puts "You must be on the master branch to update changelog!"
|
109
|
+
exit!
|
110
|
+
end
|
111
|
+
|
112
|
+
load "lib/#{name}/version.rb"
|
113
|
+
file = "CHANGELOG.rdoc"
|
114
|
+
old = File.read(file)
|
115
|
+
message = "Bumping to version #{version}"
|
116
|
+
|
117
|
+
File.open(file, "w") do |f|
|
118
|
+
f.write <<EOF
|
119
|
+
=== Version #{version} - #{Time.now}
|
120
|
+
|
121
|
+
#{`git log $(git tag | tail -1)..HEAD | git shortlog`.gsub /\s{6}/, "\n*"}
|
122
|
+
#{old}
|
123
|
+
EOF
|
124
|
+
end
|
125
|
+
|
126
|
+
Rake::Task['build'].invoke
|
127
|
+
exec ["#{ENV["EDITOR"]} #{file}",
|
128
|
+
"git commit -aqm '#{message}'",
|
129
|
+
"git tag -a -m '#{message}' v#{version}",
|
130
|
+
"git push origin master",
|
131
|
+
"git push origin $(git tag | tail -1)",
|
132
|
+
"gem push pkg/#{name}-#{version}.gem",
|
133
|
+
"echo '\n\033[32mReleased v#{version} /' `git show-ref -s refs/heads/master` '.\033[0m\n'"].join(' && ')
|
134
|
+
end
|
135
|
+
|
136
|
+
desc "Bump by a minor version (1.2.3 => 1.3.0)"
|
137
|
+
task :minor do |t|
|
138
|
+
Rake::Task['changeling:bump'].invoke(t.name)
|
139
|
+
Rake::Task['changeling:change'].invoke
|
140
|
+
end
|
141
|
+
|
142
|
+
desc "Bump by a patch version, (1.2.3 => 1.2.4)"
|
143
|
+
task :patch do |t|
|
144
|
+
Rake::Task['changeling:bump'].invoke(t.name)
|
145
|
+
Rake::Task['changeling:change'].invoke
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "Bump by a pre-release version, (1.0.0.pre1 => 1.0.0.pre2)"
|
149
|
+
task :pre do |t|
|
150
|
+
Rake::Task['changeling:bump'].invoke(t.name)
|
151
|
+
Rake::Task['changeling:change'].invoke
|
152
|
+
end
|
16
153
|
end
|
data/bitmask_attributes.gemspec
CHANGED
@@ -5,16 +5,14 @@ require "bitmask_attributes/version"
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "bitmask_attributes"
|
7
7
|
gem.summary = %Q{Simple bitmask attribute support for ActiveRecord}
|
8
|
-
gem.description = %Q{Simple bitmask attribute support for ActiveRecord}
|
9
8
|
gem.email = "joel@developwithstyle.com"
|
10
9
|
gem.homepage = "http://github.com/joelmoss/bitmask_attributes"
|
11
10
|
gem.authors = ['Joel Moss']
|
12
11
|
|
13
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
12
|
gem.files = `git ls-files`.split("\n")
|
15
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
14
|
gem.require_paths = ['lib']
|
17
|
-
gem.version = BitmaskAttributes::VERSION
|
15
|
+
gem.version = BitmaskAttributes::VERSION.dup
|
18
16
|
|
19
17
|
gem.add_dependency 'activerecord', '~> 3.0'
|
20
18
|
end
|
Binary file
|
@@ -0,0 +1,114 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>BitmaskAttributes</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
|
9
|
+
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
|
10
|
+
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
|
11
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
|
13
|
+
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
|
14
|
+
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="banner">
|
20
|
+
|
21
|
+
<h1>
|
22
|
+
<span class="type">Module</span>
|
23
|
+
BitmaskAttributes
|
24
|
+
|
25
|
+
</h1>
|
26
|
+
<ul class="files">
|
27
|
+
|
28
|
+
<li><a href="../files/lib/bitmask_attributes/definition_rb.html">lib/bitmask_attributes/definition.rb</a></li>
|
29
|
+
|
30
|
+
<li><a href="../files/lib/bitmask_attributes/value_proxy_rb.html">lib/bitmask_attributes/value_proxy.rb</a></li>
|
31
|
+
|
32
|
+
<li><a href="../files/lib/bitmask_attributes/version_rb.html">lib/bitmask_attributes/version.rb</a></li>
|
33
|
+
|
34
|
+
<li><a href="../files/lib/bitmask_attributes_rb.html">lib/bitmask_attributes.rb</a></li>
|
35
|
+
|
36
|
+
</ul>
|
37
|
+
</div>
|
38
|
+
<div id="bodyContent">
|
39
|
+
<div id="content">
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
<!-- Namespace -->
|
52
|
+
<div class="sectiontitle">Namespace</div>
|
53
|
+
<ul>
|
54
|
+
|
55
|
+
<li>
|
56
|
+
<span class="type">MODULE</span>
|
57
|
+
<a href="BitmaskAttributes/ClassMethods.html">BitmaskAttributes::ClassMethods</a>
|
58
|
+
</li>
|
59
|
+
|
60
|
+
<li>
|
61
|
+
<span class="type">CLASS</span>
|
62
|
+
<a href="BitmaskAttributes/Definition.html">BitmaskAttributes::Definition</a>
|
63
|
+
</li>
|
64
|
+
|
65
|
+
<li>
|
66
|
+
<span class="type">CLASS</span>
|
67
|
+
<a href="BitmaskAttributes/ValueProxy.html">BitmaskAttributes::ValueProxy</a>
|
68
|
+
</li>
|
69
|
+
|
70
|
+
</ul>
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
<!-- Section constants -->
|
88
|
+
<div class="sectiontitle">Constants</div>
|
89
|
+
<table border='0' cellpadding='5'>
|
90
|
+
|
91
|
+
<tr valign='top'>
|
92
|
+
<td class="attr-name">VERSION</td>
|
93
|
+
<td>=</td>
|
94
|
+
<td class="attr-value">"0.2.3".freeze</td>
|
95
|
+
</tr>
|
96
|
+
|
97
|
+
<tr valign='top'>
|
98
|
+
<td> </td>
|
99
|
+
<td colspan="2" class="attr-desc"></td>
|
100
|
+
</tr>
|
101
|
+
|
102
|
+
|
103
|
+
</table>
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<!-- Methods -->
|
111
|
+
</div>
|
112
|
+
</div>
|
113
|
+
</body>
|
114
|
+
</html>
|