symbolize 4.0.4 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -33,33 +33,46 @@ On schema DBs, the attribute should be a string (varchar) column.
33
33
 
34
34
  == Usage
35
35
 
36
+ ActiveRecord:
36
37
 
37
38
  class User < ActiveRecord::Base
38
- or Mongoid::Document
39
39
 
40
40
  symbolize :gender, :in => [:female, :male], :scopes => true
41
41
 
42
- symbolize :so, :in => {
42
+ end
43
+
44
+ Mongoid:
45
+
46
+ class User
47
+
48
+ include Mongoid::Document
49
+ include Mongoid::Symbolize
50
+
51
+ symbolize :gender, :in => [:female, :male], :scopes => true
52
+
53
+ end
54
+
55
+ Other examples:
56
+
57
+ symbolize :so, :in => {
43
58
  :linux => "Linux",
44
59
  :mac => "Mac OS X"
45
- }, :scopes => true
46
-
47
- # Allow blank
48
- symbolize :gui, :in => [:gnome, :kde, :xfce], :allow_blank => true
60
+ }, :scopes => true
49
61
 
50
- # Don`t i18n
51
- symbolize :browser, :in => [:firefox, :opera], :i18n => false, :methods => true
62
+ # Allow blank
63
+ symbolize :gui, :in => [:gnome, :kde, :xfce], :allow_blank => true
52
64
 
53
- # Scopes
54
- symbolize :angry, :in => [true, false], :scopes => true
65
+ # Don`t i18n
66
+ symbolize :browser, :in => [:firefox, :opera], :i18n => false, :methods => true
55
67
 
56
- # Don`t validate
57
- symbolize :lang, :in => [:ruby, :js, :c, :erlang], :validate => false
68
+ # Scopes
69
+ symbolize :angry, :in => [true, false], :scopes => true
58
70
 
59
- # Default
60
- symbolize :kind, :in => [:admin, :manager, :user], :default => :user
71
+ # Don`t validate
72
+ symbolize :lang, :in => [:ruby, :js, :c, :erlang], :validate => false
61
73
 
62
- end
74
+ # Default
75
+ symbolize :kind, :in => [:admin, :manager, :user], :default => :user
63
76
 
64
77
 
65
78
  === in/within
data/Rakefile CHANGED
@@ -1,14 +1,13 @@
1
1
  require 'bundler'
2
2
  Bundler.setup
3
3
 
4
- #require "rake"
5
- # require "rdoc/task"
6
4
  require "rspec"
7
5
  require "rspec/core/rake_task"
8
6
 
9
7
  $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
10
8
  require "symbolize/version"
11
9
 
10
+ desc "Builds the gem"
12
11
  task :gem => :build
13
12
  task :build do
14
13
  system "gem build symbolize.gemspec"
@@ -30,59 +29,3 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
30
29
  end
31
30
 
32
31
  task :default => [:spec]
33
-
34
- # require 'rubygems'
35
- # require 'rake'
36
- # #require 'spec/rake/spectask'
37
-
38
- # begin
39
- # require 'jeweler'
40
- # Jeweler::Tasks.new do |gem|
41
- # gem.name = "symbolize"
42
- # gem.summary = "Object enums with i18n in AR or Mongoid"
43
- # gem.description = "ActiveRecord/Mongoid enums with i18n"
44
- # gem.email = "x@nofxx.com"
45
- # gem.homepage = "http://github.com/nofxx/symbolize"
46
- # gem.authors = ["Marcos Piccinini"]
47
- # gem.add_development_dependency "rspec"
48
- # gem.add_development_dependency "sqlite3"
49
- # # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
50
- # end
51
- # rescue LoadError
52
- # puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
53
- # end
54
-
55
- # Spec::Rake::SpecTask.new(:spec) do |spec|
56
- # spec.libs << 'lib' << 'spec'
57
- # spec.spec_files = FileList['spec/**/*_spec.rb']
58
- # end
59
-
60
- # Spec::Rake::SpecTask.new(:rcov) do |spec|
61
- # spec.libs << 'lib' << 'spec'
62
- # spec.pattern = 'spec/**/*_spec.rb'
63
- # spec.rcov = true
64
- # end
65
- # task :default => :spec
66
-
67
- # desc 'Generate documentation for the activerecord_symbolize plugin.'
68
- # Rake::RDocTask.new(:rdoc) do |rdoc|
69
- # rdoc.rdoc_dir = 'rdoc'
70
- # rdoc.title = 'ActiverecordSymbolize'
71
- # rdoc.options << '--line-numbers' << '--inline-source'
72
- # rdoc.rdoc_files.include('README')
73
- # rdoc.rdoc_files.include('lib/**/*.rb')
74
- # end
75
- # require 'rdoc/task'
76
- # Rake::RDocTask.new do |rdoc|
77
- # if File.exist?('VERSION.yml')
78
- # config = YAML.load(File.read('VERSION.yml'))
79
- # version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
80
- # else
81
- # version = ""
82
- # end
83
-
84
- # rdoc.rdoc_dir = 'rdoc'
85
- # rdoc.title = "symbolize #{version}"
86
- # rdoc.rdoc_files.include('README*')
87
- # rdoc.rdoc_files.include('lib/**/*.rb')
88
- # end
@@ -80,7 +80,7 @@ module Symbolize
80
80
  const_set const.upcase, values unless const_defined? const.upcase
81
81
  ev = if i18n
82
82
  # This one is a dropdown helper
83
- code = "#{const.upcase}.map { |k,v| [I18n.translate(\"activerecord.attributes.\#{ActiveSupport::Inflector.underscore(self)}.enums.#{attr_name}.\#{k}\"), k] }" #.to_sym rescue nila
83
+ code = "#{const.upcase}.map { |k,v| [I18n.translate(\"activerecord.attributes.\#{ActiveSupport::Inflector.underscore(self.model_name)}.enums.#{attr_name}.\#{k}\"), k] }" #.to_sym rescue nila
84
84
  "def self.get_#{const}; #{code}; end;"
85
85
  else
86
86
  "def self.get_#{const}; #{const.upcase}.map(&:reverse); end"
@@ -101,7 +101,7 @@ module Symbolize
101
101
  values.each do |value|
102
102
  name = value[0]
103
103
  if name.respond_to?(:to_sym)
104
- scope_comm.call name.to_sym, :conditions => { attr_name => name }
104
+ scope_comm.call name.to_sym, :conditions => { attr_name => name.to_s }
105
105
  # Figure out if this as another option, or default...
106
106
  # scope_comm.call "not_#{attr_name}".to_sym, :conditions => { attr_name != name }
107
107
  end
@@ -158,7 +158,7 @@ module Symbolize
158
158
  def read_i18n_attribute attr_name
159
159
  attr = read_attribute(attr_name)
160
160
  return nil if attr.nil?
161
- I18n.translate("activerecord.attributes.#{ActiveSupport::Inflector.underscore(self.class)}.enums.#{attr_name}.#{attr}") #.to_sym rescue nila
161
+ I18n.translate("activerecord.attributes.#{ActiveSupport::Inflector.underscore(self.class.model_name)}.enums.#{attr_name}.#{attr}") #.to_sym rescue nila
162
162
  end
163
163
 
164
164
  # Write a symbolized value. Watch out for booleans.
@@ -89,7 +89,7 @@ module Mongoid
89
89
  const_set const.upcase, values unless const_defined? const.upcase
90
90
  ev = if i18n
91
91
  # This one is a dropdown helper
92
- code = "#{const.upcase}.map { |k,v| [I18n.t(\"mongoid.attributes.\#{ActiveSupport::Inflector.underscore(self)}.enums.#{attr_name}.\#{k}\"), k] }" #.to_sym rescue nila
92
+ code = "#{const.upcase}.map { |k,v| [I18n.t(\"mongoid.attributes.\#{ActiveSupport::Inflector.underscore(self.model_name)}.enums.#{attr_name}.\#{k}\"), k] }" #.to_sym rescue nila
93
93
  "def self.get_#{const}; #{code}; end;"
94
94
  else
95
95
  "def self.get_#{const}; #{const.upcase}.map(&:reverse); end"
@@ -130,7 +130,7 @@ module Mongoid
130
130
  if i18n # memoize call to translate... good idea?
131
131
  define_method "#{attr_name}_text" do
132
132
  return nil unless attr = read_attribute(attr_name)
133
- I18n.t("mongoid.attributes.#{ActiveSupport::Inflector.underscore(self.class)}.enums.#{attr_name}.#{attr}")
133
+ I18n.t("mongoid.attributes.#{ActiveSupport::Inflector.underscore(self.class.model_name)}.enums.#{attr_name}.#{attr}")
134
134
  end
135
135
  elsif enum
136
136
  class_eval("def #{attr_name}_text; #{attr_name.to_s.upcase}_VALUES[#{attr_name}]; end")
@@ -1,3 +1,3 @@
1
1
  module Symbolize
2
- VERSION = '4.0.4'
2
+ VERSION = '4.1.0'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'rubygems'
2
+ # require 'pry'
2
3
  begin
3
4
  require 'spec'
4
5
  rescue LoadError
5
6
  require 'rspec'
6
7
  end
7
- require 'pry'
8
8
 
9
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
10
10
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
metadata CHANGED
@@ -1,148 +1,142 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: symbolize
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 4
7
- - 0
8
- - 4
9
- segments_generated: true
10
- version: 4.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.1.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Marcos Piccinini
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-28 00:00:00 -02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: i18n
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &15795620 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 6
31
- - 0
32
- segments_generated: true
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.6.0
34
22
  type: :development
35
23
  prerelease: false
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *15795620
25
+ - !ruby/object:Gem::Dependency
38
26
  name: rspec
39
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &15794700 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
29
+ requirements:
42
30
  - - ~>
43
- - !ruby/object:Gem::Version
44
- segments:
45
- - 2
46
- - 7
47
- - 0
48
- segments_generated: true
49
- version: 2.7.0
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
50
33
  type: :development
51
34
  prerelease: false
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *15794700
36
+ - !ruby/object:Gem::Dependency
54
37
  name: mongoid
55
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &15788120 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
40
+ requirements:
58
41
  - - ~>
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 2
62
- - 3
63
- - 0
64
- segments_generated: true
42
+ - !ruby/object:Gem::Version
65
43
  version: 2.3.0
66
44
  type: :development
67
45
  prerelease: false
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *15788120
47
+ - !ruby/object:Gem::Dependency
48
+ name: bson_ext
49
+ requirement: &15787540 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *15787540
58
+ - !ruby/object:Gem::Dependency
59
+ name: sqlite3
60
+ requirement: &15786880 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.3.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *15786880
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: &15786040 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.12.2
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *15786040
80
+ - !ruby/object:Gem::Dependency
70
81
  name: activerecord
71
- requirement: &id004 !ruby/object:Gem::Requirement
82
+ requirement: &15784660 !ruby/object:Gem::Requirement
72
83
  none: false
73
- requirements:
84
+ requirements:
74
85
  - - ~>
75
- - !ruby/object:Gem::Version
76
- segments:
77
- - 3
78
- - 1
79
- - 1
80
- segments_generated: true
81
- version: 3.1.1
86
+ - !ruby/object:Gem::Version
87
+ version: 3.1.0
82
88
  type: :development
83
89
  prerelease: false
84
- version_requirements: *id004
90
+ version_requirements: *15784660
85
91
  description: ActiveRecord/Mongoid enums with i18n
86
92
  email: x@nofxx.com
87
93
  executables: []
88
-
89
94
  extensions: []
90
-
91
95
  extra_rdoc_files: []
92
-
93
- files:
96
+ files:
94
97
  - lib/symbolize.rb
95
- - lib/symbolize/active_record.rb
96
98
  - lib/symbolize/mongoid.rb
97
99
  - lib/symbolize/version.rb
100
+ - lib/symbolize/active_record.rb
98
101
  - lib/symbolize/railtie.rb
102
+ - spec/support/ar_models.rb
103
+ - spec/support/mongoid_models.rb
104
+ - spec/spec_helper_ar.rb
105
+ - spec/locales/en.yml
106
+ - spec/locales/pt.yml
107
+ - spec/symbolize_spec.rb
99
108
  - spec/spec_helper_mongoid.rb
100
109
  - spec/spec_helper.rb
101
- - spec/symbolize_spec.rb
102
- - spec/spec_helper_ar.rb
103
- - spec/symbolize/active_record_spec.rb
104
110
  - spec/symbolize/mongoid_spec.rb
111
+ - spec/symbolize/active_record_spec.rb
105
112
  - spec/db/001_create_testing_structure.rb
106
- - spec/support/mongoid_models.rb
107
- - spec/support/ar_models.rb
108
- - spec/locales/pt.yml
109
- - spec/locales/en.yml
110
113
  - README.rdoc
111
114
  - Rakefile
112
- has_rdoc: true
113
115
  homepage: http://github.com/nofxx/symbolize
114
116
  licenses: []
115
-
116
117
  post_install_message:
117
118
  rdoc_options: []
118
-
119
- require_paths:
119
+ require_paths:
120
120
  - lib
121
- required_ruby_version: !ruby/object:Gem::Requirement
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
122
  none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 3271037607239981482
127
- segments:
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ segments:
128
128
  - 0
129
- segments_generated: true
130
- version: "0"
131
- required_rubygems_version: !ruby/object:Gem::Requirement
129
+ hash: 1782796710470930293
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
131
  none: false
133
- requirements:
134
- - - ">="
135
- - !ruby/object:Gem::Version
136
- segments:
137
- - 0
138
- segments_generated: true
139
- version: "0"
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
140
136
  requirements: []
141
-
142
137
  rubyforge_project:
143
- rubygems_version: 1.3.7
138
+ rubygems_version: 1.8.11
144
139
  signing_key:
145
140
  specification_version: 3
146
141
  summary: Object enums with i18n in AR or Mongoid
147
142
  test_files: []
148
-