symbolize 4.3.4 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{README.rdoc → README.md} +37 -16
- data/lib/symbolize/version.rb +1 -1
- data/spec/spec_helper.rb +63 -2
- data/spec/symbolize/active_record_spec.rb +1 -1
- data/spec/symbolize/mongoid_spec.rb +1 -1
- metadata +15 -100
- data/spec/spec_helper_ar.rb +0 -29
- data/spec/spec_helper_mongoid.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a34f33f4e60648c8bcf7d03d1400d0aa44570ba
|
4
|
+
data.tar.gz: 768e4513510775f2813c06e5a6f35460d18c2dbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a1be12ae2d942a32324670be1436ecfb0ac2c8899e3a2d4110ef94a0f52bb32eb2f8cf90f7e7a24d91a07c81c16de9eeda340bbd156405bff67dfec7fd6397b
|
7
|
+
data.tar.gz: d166d74516a9d8dd3aae15c485b0c00a3b0ec881c1a80462297b494d5053009715ec8b9753e15f802a9de5ef4a2ce8b8ab3961713dd3d8620c0f7226fd94a36d
|
data/{README.rdoc → README.md}
RENAMED
@@ -1,22 +1,32 @@
|
|
1
|
-
|
1
|
+
Symbolize (attribute values)
|
2
|
+
=========
|
2
3
|
|
3
4
|
This plugin introduces an easy way to use symbols for values of attributes.
|
4
5
|
Symbolized attributes return a ruby symbol (or nil) as their value
|
5
6
|
and can be set using :symbols or "strings".
|
6
7
|
|
7
|
-
|
8
|
+
[![Gem Version](https://badge.fury.io/rb/symbolize.png)](http://badge.fury.io/rb/symbolize)
|
9
|
+
[![Code Climate](https://codeclimate.com/github/nofxx/symbolize.png)](https://codeclimate.com/github/nofxx/symbolize)
|
10
|
+
[![Coverage Status](https://coveralls.io/repos/nofxx/symbolize/badge.png)](https://coveralls.io/r/nofxx/symbolize)
|
11
|
+
[![Build Status](https://travis-ci.org/nofxx/symbolize.png?branch=master)](https://travis-ci.org/nofxx/symbolize)
|
12
|
+
|
13
|
+
|
14
|
+
Install
|
15
|
+
-------
|
16
|
+
|
17
|
+
Gem
|
8
18
|
|
9
|
-
=== Gem
|
10
19
|
|
11
20
|
gem install symbolize
|
12
21
|
|
13
22
|
|
14
|
-
|
23
|
+
Gemfile
|
15
24
|
|
16
25
|
gem 'symbolize'
|
17
26
|
|
18
27
|
|
19
|
-
|
28
|
+
About
|
29
|
+
-----
|
20
30
|
|
21
31
|
Just use "symbolize :attribute" in your model, and the specified
|
22
32
|
attribute will return symbol values and can be set using symbols
|
@@ -25,7 +35,8 @@ attribute will return symbol values and can be set using symbols
|
|
25
35
|
On schema DBs, the attribute should be a string (varchar) column.
|
26
36
|
|
27
37
|
|
28
|
-
|
38
|
+
Usage
|
39
|
+
-----
|
29
40
|
|
30
41
|
|
31
42
|
ActiveRecord:
|
@@ -67,14 +78,16 @@ Other examples:
|
|
67
78
|
symbolize :kind, :in => [:admin, :manager, :user], :default => :user
|
68
79
|
|
69
80
|
|
70
|
-
|
81
|
+
in/within
|
82
|
+
---------
|
71
83
|
|
72
84
|
You can provide a hash like for values allowed on the field, e.g.:
|
73
85
|
{:value => "Human text"} or an array of keys to run i18n on.
|
74
86
|
Booleans are also supported. See below.
|
75
87
|
|
76
88
|
|
77
|
-
|
89
|
+
Validate
|
90
|
+
--------
|
78
91
|
|
79
92
|
Set to false to avoid the validation of the input.
|
80
93
|
Useful for a dropdown with an "other" option textfield.
|
@@ -84,7 +97,8 @@ Useful for a dropdown with an "other" option textfield.
|
|
84
97
|
There's is also allow_(blank|nil): As you expect.
|
85
98
|
|
86
99
|
|
87
|
-
|
100
|
+
method
|
101
|
+
------
|
88
102
|
|
89
103
|
If you provide the method option, some fancy boolean methods will be added:
|
90
104
|
In our User example, browser has this option, so you can do:
|
@@ -93,7 +107,8 @@ In our User example, browser has this option, so you can do:
|
|
93
107
|
@user.opera?
|
94
108
|
|
95
109
|
|
96
|
-
|
110
|
+
Booleans
|
111
|
+
--------
|
97
112
|
|
98
113
|
Its possible to use boolean fields also. Looks better in Mongoid.
|
99
114
|
|
@@ -110,7 +125,8 @@ Its possible to use boolean fields also. Looks better in Mongoid.
|
|
110
125
|
"nil": Unknown
|
111
126
|
|
112
127
|
|
113
|
-
|
128
|
+
i18n
|
129
|
+
----
|
114
130
|
|
115
131
|
If you don`t provide a hash with values, it will try i18n:
|
116
132
|
|
@@ -133,7 +149,8 @@ You can skip i18n lookup with :i18n => false
|
|
133
149
|
symbolize :style, :in => [:rock, :punk, :funk, :jazz], :i18n => false
|
134
150
|
|
135
151
|
|
136
|
-
|
152
|
+
Scopes
|
153
|
+
------
|
137
154
|
|
138
155
|
With the ':scopes => true' option, you may filter/read/write easily:
|
139
156
|
|
@@ -159,7 +176,8 @@ For boolean colums you can use
|
|
159
176
|
( or with_[attribute] and without_[attribute] )
|
160
177
|
|
161
178
|
|
162
|
-
|
179
|
+
Default
|
180
|
+
-------
|
163
181
|
|
164
182
|
As the name suggest, the symbol you choose as default will be set
|
165
183
|
in new objects automatically. Mongoid only for now.
|
@@ -169,7 +187,8 @@ in new objects automatically. Mongoid only for now.
|
|
169
187
|
User.new.mood # It may print :happy
|
170
188
|
|
171
189
|
|
172
|
-
|
190
|
+
Rails Form Example
|
191
|
+
------------------
|
173
192
|
|
174
193
|
You may call `Class.get_<attribute>_values` anywhere to get a nice array.
|
175
194
|
Works nice with dropdowns. Examples:
|
@@ -186,7 +205,8 @@ Somewhere on a view:
|
|
186
205
|
|
187
206
|
= select_tag :kind, Coffee.get_genetic_values
|
188
207
|
|
189
|
-
|
208
|
+
Specs
|
209
|
+
-----
|
190
210
|
|
191
211
|
Run the adapter independently:
|
192
212
|
|
@@ -194,7 +214,8 @@ Run the adapter independently:
|
|
194
214
|
$ rspec spec/symbolize/active_record_spec.rb
|
195
215
|
|
196
216
|
|
197
|
-
|
217
|
+
Notes
|
218
|
+
-----
|
198
219
|
|
199
220
|
This fork:
|
200
221
|
http://github.com/nofxx/symbolize
|
data/lib/symbolize/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -8,9 +8,70 @@ end
|
|
8
8
|
|
9
9
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
10
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
-
require 'i18n'
|
12
|
-
|
13
11
|
|
12
|
+
require 'i18n'
|
14
13
|
I18n.load_path += Dir[File.join(File.dirname(__FILE__), "locales", "*.{rb,yml}")]
|
15
14
|
I18n.default_locale = "pt"
|
16
15
|
|
16
|
+
if ENV["CI"]
|
17
|
+
require 'coveralls'
|
18
|
+
Coveralls.wear!
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Mongoid
|
23
|
+
#
|
24
|
+
unless ENV["ONLY_AR"]
|
25
|
+
|
26
|
+
require 'mongoid'
|
27
|
+
puts "Using Mongoid v#{Mongoid::VERSION}"
|
28
|
+
|
29
|
+
Mongoid.configure do |config|
|
30
|
+
#config.master = Mongo::Connection.new.db("symbolize_test")
|
31
|
+
config.connect_to('symbolize_test')
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'symbolize/mongoid'
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
config.before(:each) do
|
38
|
+
Mongoid.purge!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#
|
45
|
+
# ActiveRecord
|
46
|
+
#
|
47
|
+
unless ENV["ONLY_MONGOID"]
|
48
|
+
|
49
|
+
require 'active_record'
|
50
|
+
require 'symbolize/active_record'
|
51
|
+
|
52
|
+
puts "Using ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
53
|
+
|
54
|
+
ActiveRecord::Base.send :include, Symbolize::ActiveRecord # this is normally done by the railtie
|
55
|
+
|
56
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") #'postgresql', :database => 'symbolize_test', :username => 'postgres')
|
57
|
+
|
58
|
+
|
59
|
+
if ActiveRecord::VERSION::STRING >= "3.1"
|
60
|
+
ActiveRecord::Migrator.migrate("spec/db")
|
61
|
+
else
|
62
|
+
require "db/001_create_testing_structure"
|
63
|
+
CreateTestingStructure.migrate(:up)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Spec::Runner.configure do |config|
|
68
|
+
# end
|
69
|
+
|
70
|
+
RSpec.configure do |config|
|
71
|
+
|
72
|
+
config.after(:each) do
|
73
|
+
[User, Permission].each { |klass| klass.delete_all }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,127 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symbolize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '3.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 2.8.0
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.8.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: mongoid
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.1.1
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.1.1
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bson_ext
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.5.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.5.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sqlite3
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - '>='
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 1.3.0
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.3.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pg
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.12.2
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - '>='
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.12.2
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: activerecord
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '>='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 3.2.1
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '>='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 3.2.1
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rake
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - '>='
|
31
|
+
- - ~>
|
116
32
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
118
|
-
type: :
|
33
|
+
version: '3.2'
|
34
|
+
type: :runtime
|
119
35
|
prerelease: false
|
120
36
|
version_requirements: !ruby/object:Gem::Requirement
|
121
37
|
requirements:
|
122
|
-
- -
|
38
|
+
- - ~>
|
123
39
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
40
|
+
version: '3.2'
|
125
41
|
description: ActiveRecord/Mongoid enums with i18n
|
126
42
|
email: x@nofxx.com
|
127
43
|
executables: []
|
@@ -133,18 +49,17 @@ files:
|
|
133
49
|
- lib/symbolize/version.rb
|
134
50
|
- lib/symbolize/active_record.rb
|
135
51
|
- lib/symbolize/railtie.rb
|
136
|
-
- spec/spec_helper_ar.rb
|
137
52
|
- spec/locales/en.yml
|
138
53
|
- spec/locales/pt.yml
|
139
|
-
- spec/spec_helper_mongoid.rb
|
140
54
|
- spec/spec_helper.rb
|
141
55
|
- spec/symbolize/mongoid_spec.rb
|
142
56
|
- spec/symbolize/active_record_spec.rb
|
143
57
|
- spec/db/001_create_testing_structure.rb
|
144
|
-
- README.
|
58
|
+
- README.md
|
145
59
|
- Rakefile
|
146
60
|
homepage: http://github.com/nofxx/symbolize
|
147
|
-
licenses:
|
61
|
+
licenses:
|
62
|
+
- MIT
|
148
63
|
metadata: {}
|
149
64
|
post_install_message:
|
150
65
|
rdoc_options: []
|
data/spec/spec_helper_ar.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
require 'active_record'
|
4
|
-
require 'symbolize/active_record'
|
5
|
-
ActiveRecord::Base.send :include, Symbolize::ActiveRecord # this is normally done by the railtie
|
6
|
-
|
7
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") #'postgresql', :database => 'symbolize_test', :username => 'postgres')
|
8
|
-
|
9
|
-
|
10
|
-
if ActiveRecord::VERSION::STRING >= "3.1"
|
11
|
-
ActiveRecord::Migrator.migrate("spec/db")
|
12
|
-
else
|
13
|
-
require "db/001_create_testing_structure"
|
14
|
-
CreateTestingStructure.migrate(:up)
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
puts "Running AR #{ActiveRecord::VERSION::STRING}"
|
19
|
-
# Spec::Runner.configure do |config|
|
20
|
-
# end
|
21
|
-
|
22
|
-
RSpec.configure do |config|
|
23
|
-
|
24
|
-
config.after(:each) do
|
25
|
-
[User, Permission].each { |klass| klass.delete_all }
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
data/spec/spec_helper_mongoid.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
require 'mongoid'
|
3
|
-
require 'mongoid/version'
|
4
|
-
|
5
|
-
Mongoid.configure do |config|
|
6
|
-
#config.master = Mongo::Connection.new.db("symbolize_test")
|
7
|
-
config.connect_to('symbolize_test')
|
8
|
-
end
|
9
|
-
|
10
|
-
puts "Running Mongoid #{Mongoid::VERSION}"
|
11
|
-
|
12
|
-
require 'symbolize/mongoid'
|
13
|
-
|
14
|
-
RSpec.configure do |config|
|
15
|
-
config.before(:each) do
|
16
|
-
Mongoid.purge!
|
17
|
-
end
|
18
|
-
end
|