ar_binary_flag_attributes 0.0.0 → 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/README.rdoc +68 -1
- data/VERSION +1 -1
- data/lib/ar_binary_flag_attributes.rb +2 -1
- metadata +13 -13
data/README.rdoc
CHANGED
@@ -1,6 +1,73 @@
|
|
1
1
|
= ar_binary_flag_attributes
|
2
2
|
|
3
|
-
|
3
|
+
Adds many binary/flag attributes to your AR model using only one integer field.
|
4
|
+
|
5
|
+
|
6
|
+
== How to use
|
7
|
+
|
8
|
+
Simply as hell :) First, add integer column called 'flags' (default) or whatever you like.
|
9
|
+
|
10
|
+
class AddFlagsToUserMigration < ActiveRecord::Migration
|
11
|
+
def self.run
|
12
|
+
add_column :users, :flags, :integer
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Then add one line to your model so it should look like this:
|
17
|
+
|
18
|
+
class User < ActiveRecord::Base
|
19
|
+
binary_attributes [:a, :b, :c]
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
== Custom 'flags' field
|
24
|
+
|
25
|
+
You can divide all flags into more integer columns, or use non default column name.
|
26
|
+
|
27
|
+
class AnotherMigration < ActiveRecord::Migration
|
28
|
+
def self.run
|
29
|
+
add_column :phones, :features, :integer
|
30
|
+
add_column :phones, :minor_features, :integer
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Phone < ActiveRecord::Base
|
35
|
+
binary_attributes [:camera, :wlan, :touchscreen], :features
|
36
|
+
binary_attributes [:sd_card_slot, :qwerty_keyboard], :minor_features
|
37
|
+
end
|
38
|
+
|
39
|
+
And try:
|
40
|
+
|
41
|
+
p = Phone.new
|
42
|
+
p.camera = true
|
43
|
+
p.qwerty_keyboard = true
|
44
|
+
p.save
|
45
|
+
|
46
|
+
p.features => 1
|
47
|
+
p.minor_features => 2
|
48
|
+
|
49
|
+
|
50
|
+
== Custom masks
|
51
|
+
|
52
|
+
You can specify custom masks if you want to:
|
53
|
+
|
54
|
+
class Building < ActiveRecord::Base
|
55
|
+
flag_attributes(
|
56
|
+
"overdriven" => 0b00000001,
|
57
|
+
"with_points" => 0b00000010
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
== Check also
|
63
|
+
|
64
|
+
There is a more powerful tool here https://github.com/pboling/flag_shih_tzu
|
65
|
+
|
66
|
+
== Author
|
67
|
+
|
68
|
+
Core author - Artūras Šlajus (https://github.com/arturaz/ar_binary_flag_attributes/blob/master/init.rb).
|
69
|
+
I just added spec, and made a gem :]
|
70
|
+
|
4
71
|
|
5
72
|
== Copyright
|
6
73
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_binary_flag_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-22 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
17
|
-
requirement: &
|
17
|
+
requirement: &27014200 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *27014200
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &27013700 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 2.3.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *27013700
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &27013220 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.0.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *27013220
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: jeweler
|
50
|
-
requirement: &
|
50
|
+
requirement: &27012700 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 1.6.4
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *27012700
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: sqlite3
|
61
|
-
requirement: &
|
61
|
+
requirement: &27012120 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *27012120
|
70
70
|
description: Add binary flag attributes to AR model using one DB field.
|
71
71
|
email: bobikx@poczta.fm
|
72
72
|
executables: []
|
@@ -97,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
segments:
|
99
99
|
- 0
|
100
|
-
hash:
|
100
|
+
hash: -3296919735079165990
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
102
|
none: false
|
103
103
|
requirements:
|