preferable 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -5
- data/lib/preferable/field.rb +1 -1
- data/lib/preferable/schema.rb +3 -6
- data/lib/preferable/set.rb +1 -1
- metadata +5 -4
data/README.markdown
CHANGED
@@ -14,23 +14,23 @@ Then, bundle:
|
|
14
14
|
|
15
15
|
Add a new migration to your project. Example:
|
16
16
|
|
17
|
-
$ rails g migration AddPreferencesToUsers
|
17
|
+
$ rails g migration AddPreferencesToUsers preferences:text
|
18
18
|
|
19
19
|
# Rails 2 & 3.0
|
20
20
|
class AddPreferencesToUsers < ActiveRecord::Migration
|
21
21
|
def self.up
|
22
|
-
add_column :users, :
|
22
|
+
add_column :users, :preferences, :text
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.down
|
26
|
-
remove_column :users, :
|
26
|
+
remove_column :users, :preferences, :text
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
# Rails >=3.1
|
31
31
|
class AddPreferencesToUsers < ActiveRecord::Migration
|
32
32
|
def change
|
33
|
-
add_column :users, :
|
33
|
+
add_column :users, :preferences, :text
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -64,7 +64,7 @@ Read and write preferences:
|
|
64
64
|
# Makes preferences persistent
|
65
65
|
user.save
|
66
66
|
|
67
|
-
Specify
|
67
|
+
Specify conditions (if/unless):
|
68
68
|
|
69
69
|
class User < ActiveRecord::Base
|
70
70
|
|
data/lib/preferable/field.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Preferable::Field
|
2
2
|
TYPES = [:string, :integer, :float, :boolean, :date, :datetime, :array].to_set.freeze
|
3
|
-
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
|
3
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set.freeze
|
4
4
|
|
5
5
|
attr_reader :name, :type, :options, :default
|
6
6
|
|
data/lib/preferable/schema.rb
CHANGED
@@ -2,18 +2,15 @@ require 'set'
|
|
2
2
|
|
3
3
|
class Preferable::Schema < Hash
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
9
5
|
def field(name, type, options = {})
|
10
6
|
item = Preferable::Field.new(name, type, options)
|
11
7
|
self[item.name] = item
|
12
8
|
end
|
13
9
|
|
14
10
|
Preferable::Field::TYPES.each do |sym|
|
15
|
-
define_method sym do |
|
16
|
-
|
11
|
+
define_method sym do |*args|
|
12
|
+
options = args.extract_options!
|
13
|
+
args.each {|name| field(name, sym, options) }
|
17
14
|
end
|
18
15
|
end
|
19
16
|
|
data/lib/preferable/set.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Preferable::Set < Hash
|
2
2
|
MODEL_KEY = "_".freeze
|
3
|
-
PRIVATE = [:rehash, :fetch, :store, :shift, :delete, :delete_if, :keep_if].to_set
|
3
|
+
PRIVATE = [:rehash, :fetch, :store, :shift, :delete, :delete_if, :keep_if].to_set.freeze
|
4
4
|
|
5
5
|
# Make destructive methods private
|
6
6
|
(public_instance_methods - Hash.superclass.public_instance_methods).each do |m|
|
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: preferable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dimitrij Denissenko
|
14
|
+
- Evgeniy Dolzhenko
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-07-
|
19
|
+
date: 2011-07-19 00:00:00 +01:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|