simple_enum 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +5 -1
  2. data/init.rb +1 -1
  3. data/lib/simple_enum.rb +11 -8
  4. metadata +9 -4
data/Rakefile CHANGED
@@ -2,6 +2,9 @@ require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
4
 
5
+ # kinda ensure simple_enum is on load path
6
+ $: << File.join(File.dirname(__FILE__), 'lib')
7
+
5
8
  desc 'Default: run unit tests.'
6
9
  task :default => :test
7
10
 
@@ -26,7 +29,8 @@ end
26
29
  begin
27
30
  require 'jeweler'
28
31
  Jeweler::Tasks.new do |gemspec|
29
- require File.join(File.dirname(__FILE__), 'lib', 'simple_enum')
32
+ require 'rubygems'
33
+ require 'simple_enum'
30
34
 
31
35
  gemspec.name = "simple_enum"
32
36
  gemspec.version = SimpleEnum::VERSION
data/init.rb CHANGED
@@ -1 +1 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'simple_enum')
1
+ require 'simple_enum'
data/lib/simple_enum.rb CHANGED
@@ -8,6 +8,10 @@
8
8
  #
9
9
  # See the +as_enum+ documentation for more details.
10
10
 
11
+ # because we depend on AR and i18n
12
+ require 'active_record'
13
+ require 'i18n'
14
+
11
15
  require 'simple_enum/enum_hash'
12
16
  require 'simple_enum/object_support'
13
17
  require 'simple_enum/validation'
@@ -17,7 +21,7 @@ require 'simple_enum/validation'
17
21
  module SimpleEnum
18
22
 
19
23
  # +SimpleEnum+ version string.
20
- VERSION = "1.1.0".freeze
24
+ VERSION = "1.2.0".freeze
21
25
 
22
26
  class << self
23
27
 
@@ -223,7 +227,8 @@ module SimpleEnum
223
227
  include Validation
224
228
 
225
229
  def human_enum_name(enum, key, options = {})
226
- defaults = ([self] + subclasses).map { |klass| :"#{klass.name.underscore}.#{enum}.#{key}" }
230
+ klasses = self.respond_to?(:descendants) ? descendants : ancestors
231
+ defaults = ([self] + klasses).map { |klass| :"#{klass.name.underscore}.#{enum}.#{key}" }
227
232
  defaults << :"#{enum}.#{key}"
228
233
  defaults << options.delete(:default) if options[:default]
229
234
  defaults << "#{key}".humanize
@@ -241,9 +246,7 @@ module SimpleEnum
241
246
  end
242
247
 
243
248
  # Tie stuff together and load translations if ActiveRecord is defined
244
- if Object.const_defined?('ActiveRecord')
245
- Object.send(:include, SimpleEnum::ObjectSupport)
246
-
247
- ActiveRecord::Base.send(:include, SimpleEnum)
248
- I18n.load_path << File.join(File.dirname(__FILE__), '..', 'locales', 'en.yml')
249
- end
249
+ Object.send(:include, SimpleEnum::ObjectSupport)
250
+
251
+ ActiveRecord::Base.send(:include, SimpleEnum)
252
+ I18n.load_path << File.join(File.dirname(__FILE__), '..', 'locales', 'en.yml')
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_enum
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 31
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 1.1.0
10
+ version: 1.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Lukas Westermann
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-10 00:00:00 +02:00
18
+ date: 2010-08-30 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -58,23 +59,27 @@ rdoc_options:
58
59
  require_paths:
59
60
  - lib
60
61
  required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
61
63
  requirements:
62
64
  - - ">="
63
65
  - !ruby/object:Gem::Version
66
+ hash: 3
64
67
  segments:
65
68
  - 0
66
69
  version: "0"
67
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
68
72
  requirements:
69
73
  - - ">="
70
74
  - !ruby/object:Gem::Version
75
+ hash: 3
71
76
  segments:
72
77
  - 0
73
78
  version: "0"
74
79
  requirements: []
75
80
 
76
81
  rubyforge_project:
77
- rubygems_version: 1.3.6
82
+ rubygems_version: 1.3.7
78
83
  signing_key:
79
84
  specification_version: 3
80
85
  summary: Simple enum-like field support for ActiveRecord (including validations and i18n)