flag_shih_tzu 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/README.rdoc +10 -3
- data/Rakefile +2 -9
- data/flag_shih_tzu.gemspec +0 -1
- data/gemfiles/Gemfile.activerecord-3.2.x +5 -0
- data/lib/flag_shih_tzu.rb +13 -0
- data/lib/flag_shih_tzu/version.rb +1 -1
- data/test/flag_shih_tzu_test.rb +29 -14
- data/test/test_helper.rb +1 -0
- metadata +88 -109
data/.travis.yml
CHANGED
data/README.rdoc
CHANGED
@@ -35,9 +35,9 @@ http://en.wikipedia.org/wiki/Shih_Tzu
|
|
35
35
|
|
36
36
|
The gem is actively being tested with:
|
37
37
|
|
38
|
-
* ActiveRecord versions 2.3.x, 3.0.x, 3.1.x
|
38
|
+
* ActiveRecord versions 2.3.x, 3.0.x, 3.1.x, 3.2.x
|
39
39
|
* MySQL, PostgreSQL and SQLite3 databases
|
40
|
-
* Ruby 1.8.7 and 1.9.
|
40
|
+
* Ruby 1.8.7, 1.9.2 and 1.9.3
|
41
41
|
|
42
42
|
|
43
43
|
==Installation
|
@@ -163,6 +163,13 @@ on Spaceship:
|
|
163
163
|
Spaceship#electrolytes=
|
164
164
|
Spaceship#electrolytes_changed?
|
165
165
|
|
166
|
+
Opionally, you can set the <tt>:bang_methods</tt> option to true to enable the bang methods:
|
167
|
+
|
168
|
+
Spaceship#electrolytes!
|
169
|
+
Spaceship#not_electrolytes!
|
170
|
+
|
171
|
+
which respectively enables or disables the electrolytes flag.
|
172
|
+
|
166
173
|
|
167
174
|
===Generated named scopes
|
168
175
|
|
@@ -292,7 +299,7 @@ and a helpful group of
|
|
292
299
|
Thanks!
|
293
300
|
|
294
301
|
Please find out more about our work in our
|
295
|
-
{
|
302
|
+
{Devblog}[http://devblog.xing.com/].
|
296
303
|
|
297
304
|
|
298
305
|
==License
|
data/Rakefile
CHANGED
@@ -27,16 +27,9 @@ end
|
|
27
27
|
namespace :test do
|
28
28
|
desc 'Test against all supported ActiveRecord versions'
|
29
29
|
task :all do
|
30
|
-
%w(2.3.x 3.0.x 3.1.x).each do |version|
|
31
|
-
sh "BUNDLE_GEMFILE='gemfiles/Gemfile.activerecord-#{version}' bundle"
|
30
|
+
%w(2.3.x 3.0.x 3.1.x 3.2.x).each do |version|
|
31
|
+
sh "BUNDLE_GEMFILE='gemfiles/Gemfile.activerecord-#{version}' bundle --quiet"
|
32
32
|
sh "BUNDLE_GEMFILE='gemfiles/Gemfile.activerecord-#{version}' bundle exec rake test"
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
36
|
-
desc 'Measures test coverage'
|
37
|
-
task :coverage do
|
38
|
-
rm_f "coverage"
|
39
|
-
system("rcov -Ilib test/*_test.rb")
|
40
|
-
system("open coverage/index.html") if PLATFORM['darwin']
|
41
|
-
end
|
42
35
|
end
|
data/flag_shih_tzu.gemspec
CHANGED
data/lib/flag_shih_tzu.rb
CHANGED
@@ -77,6 +77,19 @@ module FlagShihTzu
|
|
77
77
|
end
|
78
78
|
EVAL
|
79
79
|
|
80
|
+
# Define bancg methods when requested
|
81
|
+
if flag_options[colmn][:bang_methods]
|
82
|
+
class_eval <<-EVAL
|
83
|
+
def #{flag_name}!
|
84
|
+
enable_flag(:#{flag_name}, '#{colmn}')
|
85
|
+
end
|
86
|
+
|
87
|
+
def not_#{flag_name}!
|
88
|
+
disable_flag(:#{flag_name}, '#{colmn}')
|
89
|
+
end
|
90
|
+
EVAL
|
91
|
+
end
|
92
|
+
|
80
93
|
# Define the named scopes if the user wants them and AR supports it
|
81
94
|
if flag_options[colmn][:named_scopes] && respond_to?(named_scope_method)
|
82
95
|
class_eval <<-EVAL
|
data/test/flag_shih_tzu_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/test_helper.rb')
|
2
2
|
|
3
3
|
class Spaceship < ActiveRecord::Base
|
4
|
-
|
4
|
+
self.table_name = 'spaceships'
|
5
5
|
include FlagShihTzu
|
6
6
|
|
7
7
|
has_flags 1 => :warpdrive,
|
@@ -10,35 +10,35 @@ class Spaceship < ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class SpaceshipWithoutNamedScopes < ActiveRecord::Base
|
13
|
-
|
13
|
+
self.table_name = 'spaceships'
|
14
14
|
include FlagShihTzu
|
15
15
|
|
16
16
|
has_flags(1 => :warpdrive, :named_scopes => false)
|
17
17
|
end
|
18
18
|
|
19
19
|
class SpaceshipWithoutNamedScopesOldStyle < ActiveRecord::Base
|
20
|
-
|
20
|
+
self.table_name = 'spaceships'
|
21
21
|
include FlagShihTzu
|
22
22
|
|
23
23
|
has_flags({1 => :warpdrive}, :named_scopes => false)
|
24
24
|
end
|
25
25
|
|
26
26
|
class SpaceshipWithCustomFlagsColumn < ActiveRecord::Base
|
27
|
-
|
27
|
+
self.table_name = 'spaceships_with_custom_flags_column'
|
28
28
|
include FlagShihTzu
|
29
29
|
|
30
30
|
has_flags(1 => :warpdrive, 2 => :hyperspace, :column => 'bits')
|
31
31
|
end
|
32
32
|
|
33
33
|
class SpaceshipWithColumnNameAsSymol < ActiveRecord::Base
|
34
|
-
|
34
|
+
self.table_name = 'spaceships_with_custom_flags_column'
|
35
35
|
include FlagShihTzu
|
36
36
|
|
37
37
|
has_flags(1 => :warpdrive, 2 => :hyperspace, :column => :bits)
|
38
38
|
end
|
39
39
|
|
40
40
|
class SpaceshipWith2CustomFlagsColumn < ActiveRecord::Base
|
41
|
-
|
41
|
+
self.table_name = 'spaceships_with_2_custom_flags_column'
|
42
42
|
include FlagShihTzu
|
43
43
|
|
44
44
|
has_flags({ 1 => :warpdrive, 2 => :hyperspace }, :column => 'bits')
|
@@ -46,12 +46,19 @@ class SpaceshipWith2CustomFlagsColumn < ActiveRecord::Base
|
|
46
46
|
end
|
47
47
|
|
48
48
|
class SpaceshipWithBitOperatorQueryMode < ActiveRecord::Base
|
49
|
-
|
49
|
+
self.table_name = 'spaceships'
|
50
50
|
include FlagShihTzu
|
51
51
|
|
52
52
|
has_flags(1 => :warpdrive, 2 => :shields, :flag_query_mode => :bit_operator)
|
53
53
|
end
|
54
54
|
|
55
|
+
class SpaceshipWithBangMethods < ActiveRecord::Base
|
56
|
+
self.table_name = 'spaceships'
|
57
|
+
include FlagShihTzu
|
58
|
+
|
59
|
+
has_flags(1 => :warpdrive, 2 => :shields, :bang_methods => true)
|
60
|
+
end
|
61
|
+
|
55
62
|
class SpaceCarrier < Spaceship
|
56
63
|
end
|
57
64
|
|
@@ -69,7 +76,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
|
|
69
76
|
assert_raises ArgumentError do
|
70
77
|
eval(<<-EOF
|
71
78
|
class SpaceshipWithInvalidFlagKey < ActiveRecord::Base
|
72
|
-
|
79
|
+
self.table_name = 'spaceships'
|
73
80
|
include FlagShihTzu
|
74
81
|
|
75
82
|
has_flags({ -1 => :error })
|
@@ -83,7 +90,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
|
|
83
90
|
assert_raises ArgumentError do
|
84
91
|
eval(<<-EOF
|
85
92
|
class SpaceshipWithAlreadyUsedFlag < ActiveRecord::Base
|
86
|
-
|
93
|
+
self.table_name = 'spaceships_with_2_custom_flags_column'
|
87
94
|
include FlagShihTzu
|
88
95
|
|
89
96
|
has_flags({ 1 => :jeanluckpicard }, :column => 'bits')
|
@@ -98,7 +105,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
|
|
98
105
|
assert_raises ArgumentError do
|
99
106
|
eval(<<-EOF
|
100
107
|
class SpaceshipWithAlreadyUsedMethod < ActiveRecord::Base
|
101
|
-
|
108
|
+
self.table_name = 'spaceships_with_2_custom_flags_column'
|
102
109
|
include FlagShihTzu
|
103
110
|
|
104
111
|
def jeanluckpicard; end
|
@@ -114,7 +121,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
|
|
114
121
|
assert_nothing_raised ArgumentError do
|
115
122
|
eval(<<-EOF
|
116
123
|
class SpaceshipWithAlreadyUsedMethodByFlagshitzu < ActiveRecord::Base
|
117
|
-
|
124
|
+
self.table_name = 'spaceships_with_2_custom_flags_column'
|
118
125
|
include FlagShihTzu
|
119
126
|
|
120
127
|
has_flags({ 1 => :jeanluckpicard }, :column => 'bits')
|
@@ -129,7 +136,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
|
|
129
136
|
assert_raises ArgumentError do
|
130
137
|
eval(<<-EOF
|
131
138
|
class SpaceshipWithInvalidFlagName < ActiveRecord::Base
|
132
|
-
|
139
|
+
self.table_name = 'spaceships'
|
133
140
|
include FlagShihTzu
|
134
141
|
|
135
142
|
has_flags({ 1 => 'error' })
|
@@ -422,7 +429,7 @@ class FlagShihTzuInstanceMethodsTest < Test::Unit::TestCase
|
|
422
429
|
assert_nothing_raised do
|
423
430
|
eval(<<-EOF
|
424
431
|
class SpaceshipWithoutFlagsColumn < ActiveRecord::Base
|
425
|
-
|
432
|
+
self.table_name = 'spaceships_without_flags_column'
|
426
433
|
include FlagShihTzu
|
427
434
|
|
428
435
|
has_flags 1 => :warpdrive,
|
@@ -440,7 +447,7 @@ class FlagShihTzuInstanceMethodsTest < Test::Unit::TestCase
|
|
440
447
|
assert_raises FlagShihTzu::IncorrectFlagColumnException do
|
441
448
|
eval(<<-EOF
|
442
449
|
class SpaceshipWithNonIntegerColumn < ActiveRecord::Base
|
443
|
-
|
450
|
+
self.table_name ='spaceships_with_non_integer_column'
|
444
451
|
include FlagShihTzu
|
445
452
|
|
446
453
|
has_flags 1 => :warpdrive,
|
@@ -538,4 +545,12 @@ class FlagShihTzuDerivedClassTest < Test::Unit::TestCase
|
|
538
545
|
assert !@spaceship.warpdrive
|
539
546
|
end
|
540
547
|
end
|
548
|
+
|
549
|
+
def test_should_define_bang_methods
|
550
|
+
spaceship = SpaceshipWithBangMethods.new
|
551
|
+
spaceship.warpdrive!
|
552
|
+
assert spaceship.warpdrive
|
553
|
+
spaceship.not_warpdrive!
|
554
|
+
assert !spaceship.warpdrive
|
555
|
+
end
|
541
556
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,6 +4,7 @@ require "logger"
|
|
4
4
|
require "flag_shih_tzu"
|
5
5
|
|
6
6
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
7
|
+
ActiveRecord::Migration.verbose = false
|
7
8
|
|
8
9
|
configs = YAML.load_file(File.dirname(__FILE__) + "/database.yml")
|
9
10
|
ActiveRecord::Base.configurations = configs
|
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: flag_shih_tzu
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 3
|
10
|
-
version: 0.2.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Patryk Peszko
|
14
9
|
- Sebastian Roebke
|
15
10
|
- David Anderson
|
@@ -17,112 +12,104 @@ authors:
|
|
17
12
|
autorequire:
|
18
13
|
bindir: bin
|
19
14
|
cert_chain: []
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- !ruby/object:Gem::Dependency
|
15
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
24
18
|
name: activerecord
|
25
|
-
|
26
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
27
20
|
none: false
|
28
|
-
requirements:
|
29
|
-
- -
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
hash: 3
|
32
|
-
segments:
|
33
|
-
- 2
|
34
|
-
- 3
|
35
|
-
- 0
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
36
24
|
version: 2.3.0
|
37
25
|
type: :runtime
|
38
|
-
version_requirements: *id001
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
-
name: bundler
|
41
26
|
prerelease: false
|
42
|
-
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
28
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.3.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
51
41
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rdoc
|
55
42
|
prerelease: false
|
56
|
-
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
44
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rdoc
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
66
56
|
version: 2.4.2
|
67
57
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
58
|
prerelease: false
|
72
|
-
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
60
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.4.2
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rake
|
67
|
+
requirement: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
81
73
|
type: :development
|
82
|
-
version_requirements: *id004
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rcov
|
85
74
|
prerelease: false
|
86
|
-
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
76
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
|
93
|
-
- 0
|
94
|
-
version: "0"
|
95
|
-
type: :development
|
96
|
-
version_requirements: *id005
|
97
|
-
- !ruby/object:Gem::Dependency
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
98
82
|
name: sqlite3
|
99
|
-
|
100
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
101
84
|
none: false
|
102
|
-
requirements:
|
103
|
-
- -
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
version: "0"
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
109
89
|
type: :development
|
110
|
-
|
111
|
-
|
112
|
-
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: ! 'Bit fields for ActiveRecord:
|
98
|
+
|
113
99
|
This gem lets you use a single integer column in an ActiveRecord model
|
100
|
+
|
114
101
|
to store a collection of boolean attributes (flags). Each flag can be used
|
102
|
+
|
115
103
|
almost in the same way you would use any boolean attribute on an
|
104
|
+
|
116
105
|
ActiveRecord object.
|
117
106
|
|
107
|
+
'
|
118
108
|
email:
|
119
109
|
executables: []
|
120
|
-
|
121
110
|
extensions: []
|
122
|
-
|
123
111
|
extra_rdoc_files: []
|
124
|
-
|
125
|
-
files:
|
112
|
+
files:
|
126
113
|
- .gitignore
|
127
114
|
- .travis.yml
|
128
115
|
- Gemfile
|
@@ -132,6 +119,7 @@ files:
|
|
132
119
|
- gemfiles/Gemfile.activerecord-2.3.x
|
133
120
|
- gemfiles/Gemfile.activerecord-3.0.x
|
134
121
|
- gemfiles/Gemfile.activerecord-3.1.x
|
122
|
+
- gemfiles/Gemfile.activerecord-3.2.x
|
135
123
|
- init.rb
|
136
124
|
- lib/flag_shih_tzu.rb
|
137
125
|
- lib/flag_shih_tzu/version.rb
|
@@ -141,38 +129,29 @@ files:
|
|
141
129
|
- test/test_helper.rb
|
142
130
|
homepage: https://github.com/xing/flag_shih_tzu
|
143
131
|
licenses: []
|
144
|
-
|
145
132
|
post_install_message:
|
146
133
|
rdoc_options: []
|
147
|
-
|
148
|
-
require_paths:
|
134
|
+
require_paths:
|
149
135
|
- lib
|
150
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
137
|
none: false
|
152
|
-
requirements:
|
153
|
-
- -
|
154
|
-
- !ruby/object:Gem::Version
|
155
|
-
|
156
|
-
|
157
|
-
- 0
|
158
|
-
version: "0"
|
159
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
143
|
none: false
|
161
|
-
requirements:
|
162
|
-
- -
|
163
|
-
- !ruby/object:Gem::Version
|
164
|
-
|
165
|
-
segments:
|
166
|
-
- 0
|
167
|
-
version: "0"
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
168
148
|
requirements: []
|
169
|
-
|
170
149
|
rubyforge_project:
|
171
|
-
rubygems_version: 1.8.
|
150
|
+
rubygems_version: 1.8.24
|
172
151
|
signing_key:
|
173
152
|
specification_version: 3
|
174
153
|
summary: Bit fields for ActiveRecord
|
175
|
-
test_files:
|
154
|
+
test_files:
|
176
155
|
- test/database.yml
|
177
156
|
- test/flag_shih_tzu_test.rb
|
178
157
|
- test/schema.rb
|