symbolize 3.0.0 → 3.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 +30 -22
- data/Rakefile +11 -11
- data/VERSION +1 -1
- data/lib/symbolize.rb +10 -8
- data/spec/locales/en.yml +16 -0
- data/spec/spec_helper.rb +8 -6
- data/spec/symbolize_spec.rb +8 -4
- data/symbolize.gemspec +5 -4
- metadata +9 -4
data/README.rdoc
CHANGED
@@ -24,7 +24,7 @@ Github: http://github.com/zargony/activerecord_symbolize
|
|
24
24
|
|
25
25
|
== Install
|
26
26
|
|
27
|
-
Gem
|
27
|
+
=== Gem
|
28
28
|
|
29
29
|
gem install symbolize
|
30
30
|
config.gem "symbolize", :source => 'http://gemcutter.org'
|
@@ -35,13 +35,14 @@ Rails 3+ Gemfile
|
|
35
35
|
gem "symbolize"
|
36
36
|
|
37
37
|
|
38
|
-
Plugin:
|
38
|
+
=== Plugin:
|
39
39
|
|
40
40
|
./script/plugin install git://github.com/nofxx/symbolize.git
|
41
41
|
|
42
|
-
or
|
42
|
+
or in Rails3+
|
43
|
+
|
44
|
+
rails plugin install ..
|
43
45
|
|
44
|
-
rails plugin install in Rails3+
|
45
46
|
|
46
47
|
== Rails 3 (beta)
|
47
48
|
|
@@ -59,9 +60,10 @@ validates_inclusion_of to restrict the possible values (just like an enum).
|
|
59
60
|
:linux => "Linux",
|
60
61
|
:mac => "Mac OS X"
|
61
62
|
}, :scopes => true
|
62
|
-
symbolize :gui,
|
63
|
+
symbolize :gui, :in => [:gnome, :kde, :xfce], :allow_blank => true
|
63
64
|
symbolize :browser, :in => [:firefox, :opera], :i18n => false, :methods => true
|
64
65
|
symbolize :angry, :in => [true, false], :scopes => true
|
66
|
+
symbolize :lang, :in => [:ruby, :c, :erlang], :validate => false
|
65
67
|
end
|
66
68
|
|
67
69
|
|
@@ -74,24 +76,10 @@ Booleans are also supported. See below.
|
|
74
76
|
allow_(blank|nil): What you expect.
|
75
77
|
|
76
78
|
|
77
|
-
===
|
79
|
+
=== validate
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
activerecord:
|
82
|
-
attributes:
|
83
|
-
user:
|
84
|
-
enums:
|
85
|
-
gui:
|
86
|
-
gnome: Gnome Desktop Enviroment
|
87
|
-
kde: K Desktop Enviroment
|
88
|
-
xfce: XFCE4
|
89
|
-
gender:
|
90
|
-
female: Girl
|
91
|
-
male: Boy
|
92
|
-
|
93
|
-
You can skip i18n lookup with :i18n => false
|
94
|
-
symbolize :gender, :in => [:female, :male], :i18n => false
|
81
|
+
Set to false to avoid the validation of the input.
|
82
|
+
Useful for a dropdown with an "other" option textfield.
|
95
83
|
|
96
84
|
|
97
85
|
=== method
|
@@ -115,6 +103,26 @@ Its possible to use boolean fields also.
|
|
115
103
|
"nil": Unknown
|
116
104
|
|
117
105
|
|
106
|
+
=== i18n
|
107
|
+
|
108
|
+
If you don`t provide a hash with values, it will try i18n:
|
109
|
+
|
110
|
+
activerecord:
|
111
|
+
attributes:
|
112
|
+
user:
|
113
|
+
enums:
|
114
|
+
gui:
|
115
|
+
gnome: Gnome Desktop Enviroment
|
116
|
+
kde: K Desktop Enviroment
|
117
|
+
xfce: XFCE4
|
118
|
+
gender:
|
119
|
+
female: Girl
|
120
|
+
male: Boy
|
121
|
+
|
122
|
+
You can skip i18n lookup with :i18n => false
|
123
|
+
symbolize :gender, :in => [:female, :male], :i18n => false
|
124
|
+
|
125
|
+
|
118
126
|
=== scopes (BETA)
|
119
127
|
|
120
128
|
If you provide the scopes option, some fancy named scopes will be added:
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require 'spec/rake/spectask'
|
3
|
+
#require 'spec/rake/spectask'
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'jeweler'
|
@@ -19,17 +19,17 @@ rescue LoadError
|
|
19
19
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
20
|
end
|
21
21
|
|
22
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
# Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
# spec.libs << 'lib' << 'spec'
|
24
|
+
# spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
# end
|
26
26
|
|
27
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
task :default => :spec
|
27
|
+
# Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
# spec.libs << 'lib' << 'spec'
|
29
|
+
# spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
# spec.rcov = true
|
31
|
+
# end
|
32
|
+
# task :default => :spec
|
33
33
|
|
34
34
|
# desc 'Generate documentation for the activerecord_symbolize plugin.'
|
35
35
|
# Rake::RDocTask.new(:rdoc) do |rdoc|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.1
|
data/lib/symbolize.rb
CHANGED
@@ -67,21 +67,23 @@ module Symbolize
|
|
67
67
|
|
68
68
|
attr_names.each do |attr_name|
|
69
69
|
attr_name = attr_name.to_s
|
70
|
+
const = "#{attr_name}_values"
|
70
71
|
if enum.instance_of?(Hash)
|
71
72
|
values = enum
|
72
73
|
else
|
73
|
-
|
74
|
-
values = hsh[*enum.map { |v| [v, I18n.translate("activerecord.attributes.#{ActiveSupport::Inflector.underscore(self)}.enums.#{attr_name}.#{v}")] }.flatten]
|
75
|
-
else
|
76
|
-
values = hsh[*enum.map { |v| [v, (configuration[:capitalize] ? v.to_s.capitalize : v.to_s)] }.flatten]
|
77
|
-
end
|
74
|
+
values = hsh[*enum.map { |v| [v, (configuration[:capitalize] ? v.to_s.capitalize : v.to_s)] }.flatten]
|
78
75
|
end
|
79
76
|
|
80
77
|
# Get the values of :in
|
81
|
-
const = "#{attr_name}_values"
|
82
78
|
const_set const.upcase, values unless const_defined? const.upcase
|
83
|
-
|
84
|
-
|
79
|
+
ev = if i18n
|
80
|
+
# This one is a dropdown helper
|
81
|
+
code = "#{const.upcase}.map { |k,v| [I18n.translate(\"activerecord.attributes.\#{ActiveSupport::Inflector.underscore(self)}.enums.#{attr_name}.\#{k}\"), k] }" #.to_sym rescue nila
|
82
|
+
"def self.get_#{const}; #{code}; end;"
|
83
|
+
else
|
84
|
+
"def self.get_#{const}; #{const.upcase}.map(&:reverse); end"
|
85
|
+
end
|
86
|
+
class_eval(ev)
|
85
87
|
|
86
88
|
if methods
|
87
89
|
values.each do |value|
|
data/spec/locales/en.yml
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
2
|
+
begin
|
3
|
+
require 'spec'
|
4
|
+
rescue LoadError
|
5
|
+
require 'rspec'
|
6
|
+
end
|
3
7
|
|
4
8
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
9
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -15,8 +19,6 @@ I18n.load_path += Dir[File.join(File.dirname(__FILE__), "locales", "*.{rb,yml}")
|
|
15
19
|
I18n.default_locale = "pt"
|
16
20
|
CreateTestingStructure.migrate(:up)
|
17
21
|
|
18
|
-
|
19
|
-
Spec::Runner.configure do |config|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
22
|
+
puts "Running AR #{ActiveRecord::VERSION::MAJOR}"
|
23
|
+
# Spec::Runner.configure do |config|
|
24
|
+
# end
|
data/spec/symbolize_spec.rb
CHANGED
@@ -36,9 +36,7 @@ User.create(:name => 'Bob' , :other => :bar,:status => :inactive, :so => :mac, :
|
|
36
36
|
|
37
37
|
describe "Symbolize" do
|
38
38
|
|
39
|
-
|
40
39
|
it "should respond to symbolize" do
|
41
|
-
p ActiveRecord::VERSION::MAJOR
|
42
40
|
ActiveRecord::Base.should respond_to :symbolize
|
43
41
|
end
|
44
42
|
|
@@ -152,6 +150,9 @@ describe "Symbolize" do
|
|
152
150
|
|
153
151
|
describe "ActiveRecord stuff" do
|
154
152
|
|
153
|
+
#
|
154
|
+
# ActiveRecord < 3
|
155
|
+
#
|
155
156
|
if ActiveRecord::VERSION::MAJOR < 3
|
156
157
|
|
157
158
|
it "test_symbolized_finder" do
|
@@ -165,6 +166,9 @@ describe "Symbolize" do
|
|
165
166
|
end
|
166
167
|
end
|
167
168
|
|
169
|
+
#
|
170
|
+
# ActiveRecord >= 3
|
171
|
+
#
|
168
172
|
else
|
169
173
|
|
170
174
|
it "test_symbolized_finder" do
|
@@ -261,7 +265,7 @@ describe "Symbolize" do
|
|
261
265
|
end
|
262
266
|
|
263
267
|
it "should get the correct values" do
|
264
|
-
User::LANGUAGE_VALUES.should eql({:pt
|
268
|
+
User::LANGUAGE_VALUES.should eql({:pt=>"pt", :en=>"en"})
|
265
269
|
end
|
266
270
|
|
267
271
|
it "should test boolean" do
|
@@ -273,7 +277,7 @@ describe "Symbolize" do
|
|
273
277
|
end
|
274
278
|
|
275
279
|
it "should get the correct values" do
|
276
|
-
User::SEX_VALUES.should eql({
|
280
|
+
User::SEX_VALUES.should eql({true=>"true", false=>"false"})
|
277
281
|
end
|
278
282
|
|
279
283
|
it "should translate a multiword class" do
|
data/symbolize.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{symbolize}
|
8
|
-
s.version = "3.0.
|
8
|
+
s.version = "3.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marcos Piccinini"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-09}
|
13
13
|
s.description = %q{ActiveRecord enums with i18n}
|
14
14
|
s.email = %q{x@nofxx.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/symbolize_helper.rb",
|
28
28
|
"rails/init.rb",
|
29
29
|
"spec/db/create_testing_structure.rb",
|
30
|
+
"spec/locales/en.yml",
|
30
31
|
"spec/locales/pt.yml",
|
31
32
|
"spec/spec_helper.rb",
|
32
33
|
"spec/symbolize_spec.rb",
|
@@ -35,7 +36,7 @@ Gem::Specification.new do |s|
|
|
35
36
|
s.homepage = %q{http://github.com/nofxx/symbolize}
|
36
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
38
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
39
40
|
s.summary = %q{ActiveRecord enums with i18n}
|
40
41
|
s.test_files = [
|
41
42
|
"spec/db/create_testing_structure.rb",
|
@@ -47,7 +48,7 @@ Gem::Specification.new do |s|
|
|
47
48
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
49
|
s.specification_version = 3
|
49
50
|
|
50
|
-
if Gem::Version.new(Gem::
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
52
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
52
53
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
53
54
|
else
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 3
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 3.0.
|
8
|
+
- 1
|
9
|
+
version: 3.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Marcos Piccinini
|
@@ -14,13 +14,14 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-09 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
@@ -33,6 +34,7 @@ dependencies:
|
|
33
34
|
name: sqlite3
|
34
35
|
prerelease: false
|
35
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
36
38
|
requirements:
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
@@ -61,6 +63,7 @@ files:
|
|
61
63
|
- lib/symbolize_helper.rb
|
62
64
|
- rails/init.rb
|
63
65
|
- spec/db/create_testing_structure.rb
|
66
|
+
- spec/locales/en.yml
|
64
67
|
- spec/locales/pt.yml
|
65
68
|
- spec/spec_helper.rb
|
66
69
|
- spec/symbolize_spec.rb
|
@@ -75,6 +78,7 @@ rdoc_options:
|
|
75
78
|
require_paths:
|
76
79
|
- lib
|
77
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
78
82
|
requirements:
|
79
83
|
- - ">="
|
80
84
|
- !ruby/object:Gem::Version
|
@@ -82,6 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
86
|
- 0
|
83
87
|
version: "0"
|
84
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
85
90
|
requirements:
|
86
91
|
- - ">="
|
87
92
|
- !ruby/object:Gem::Version
|
@@ -91,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
96
|
requirements: []
|
92
97
|
|
93
98
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.3.
|
99
|
+
rubygems_version: 1.3.7
|
95
100
|
signing_key:
|
96
101
|
specification_version: 3
|
97
102
|
summary: ActiveRecord enums with i18n
|