classy_enum 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # ClassyEnum Changelog
2
2
 
3
+ ## 2.2.0
4
+
5
+ * Deprecating class names like ParentChild in favor of namespaced names
6
+ like Parent::Child
7
+
3
8
  ## 2.1.0
4
9
 
5
10
  * Deprecating ClassyEnum::Base.enum_classes() (this is no longer needed)
@@ -40,7 +40,13 @@ module ClassyEnum
40
40
  define_method "visit_#{klass.name}", lambda {|value| quote(value.to_s) }
41
41
  end
42
42
 
43
- enum = klass.name.gsub(klass.base_class.name, '').underscore.to_sym
43
+ if klass.name.start_with? "#{base_class.name}::"
44
+ enum = klass.name.split('::').last.underscore.to_sym
45
+ else
46
+ ActiveSupport::Deprecation.warn("The enum class name #{klass} is deprecated. ClassyEnum 3.0 will require subclasses to use the parent class as a namespace. Change it to #{base_class}::#{klass.name.gsub(base_class.name, '')}", caller)
47
+ enum = klass.name.gsub(klass.base_class.name, '').underscore.to_sym
48
+ end
49
+
44
50
  index = self.enum_options.index(enum) + 1
45
51
 
46
52
  klass.class_eval do
@@ -64,7 +70,14 @@ module ClassyEnum
64
70
  return value if value.blank?
65
71
  return TypeError.new("Valid #{self} options are #{self.valid_options}") unless self.enum_options.include? value.to_sym
66
72
 
67
- object = ("#{self}#{value.to_s.camelize}").constantize.new
73
+ # Temp hack until 3.0 to allow both namespaced and non-namespaced classes
74
+ begin
75
+ klass = "#{self}::#{value.to_s.camelize}".constantize
76
+ rescue NameError
77
+ klass = "#{self}#{value.to_s.camelize}".constantize
78
+ end
79
+
80
+ object = klass.new
68
81
  object.owner = options[:owner]
69
82
  object.serialize_as_json = options[:serialize_as_json]
70
83
  object
@@ -1,3 +1,3 @@
1
1
  module ClassyEnum
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -2,6 +2,6 @@ class <%= class_name %> < ClassyEnum::Base
2
2
  enum_classes <%= values.map {|a| ":#{a}"}.join(", ") %>
3
3
  end
4
4
  <% values.each do |arg| %>
5
- class <%= class_name + arg.camelize %> < <%= class_name %>
5
+ class <%= "#{class_name}::#{arg.camelize}" %> < <%= class_name %>
6
6
  end
7
- <% end %>
7
+ <%- end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  segments:
123
123
  - 0
124
- hash: -4601389622693505403
124
+ hash: -1067969167030479994
125
125
  required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  none: false
127
127
  requirements:
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: -4601389622693505403
133
+ hash: -1067969167030479994
134
134
  requirements: []
135
135
  rubyforge_project:
136
136
  rubygems_version: 1.8.24