acts_as_constant 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/acts_as_constant.rb +34 -26
  2. metadata +4 -4
@@ -17,6 +17,10 @@ module ActiveRecord #:nodoc:
17
17
  const = klass.upcase.gsub("::", "_")
18
18
  #puts "const = #{const}"
19
19
 
20
+ define_method("constantize") do
21
+ self.send(col).constantize
22
+ end
23
+
20
24
  class_eval %{
21
25
  def self.constant_class_name
22
26
  "#{const}"
@@ -47,43 +51,47 @@ module ActiveRecord #:nodoc:
47
51
 
48
52
  class_eval do
49
53
  def self.reload_constants!
50
- self.CONSTANTS.clear
51
-
52
- rows = eval "#{self.to_s}.find(:all)"
54
+ begin
55
+ self.CONSTANTS.clear
56
+
57
+ rows = eval "#{self.to_s}.find(:all)"
53
58
 
54
- rows.each do |rec|
55
- #puts rec.inspect
56
- name = rec.send(self.constant_column)
59
+ rows.each do |rec|
60
+ #puts rec.inspect
61
+ name = rec.send(self.constant_column)
57
62
 
58
- unless name.nil?
63
+ unless name.nil?
59
64
 
60
- # let's sanitize the name a bit.
61
- name = name.downcase
62
- name = name.gsub(' ', '_')
65
+ # let's sanitize the name a bit.
66
+ name = name.underscore.gsub("/", '_')
63
67
 
64
- self.instance_eval do
68
+ self.instance_eval do
65
69
 
66
- define_method("constant_name") do
67
- self.send(self.constant_column).downcase.gsub(' ', '_')
68
- end
70
+ define_method("constant_name") do
71
+ self.send(self.constant_column).downcase.gsub(' ', '_')
72
+ end
69
73
 
70
- end
74
+ end
71
75
 
72
- # let's create two methods an all downcase method for accessing the constant and an upper case one
73
- class_eval %{
74
- # by using .freeze we can prevent the object from being modified.
75
- #{self.constant_class_name}_CONSTANTS[#{rec.id}] = rec.freeze
76
+ # let's create two methods an all downcase method for accessing the constant and an upper case one
77
+ class_eval %{
78
+ # by using .freeze we can prevent the object from being modified.
79
+ #{self.constant_class_name}_CONSTANTS[#{rec.id}] = rec.freeze
76
80
 
77
- def self.#{name}
78
- #{self.constant_class_name}_CONSTANTS[#{rec.id}]
79
- end
81
+ def self.#{name}
82
+ #{self.constant_class_name}_CONSTANTS[#{rec.id}]
83
+ end
80
84
 
81
- def self.#{name.upcase}
82
- #{self.constant_class_name}_CONSTANTS[#{rec.id}]
83
- end
84
- }
85
+ def self.#{name.upcase}
86
+ #{self.constant_class_name}_CONSTANTS[#{rec.id}]
87
+ end
88
+ }
89
+ end
85
90
  end
91
+ rescue Exception => e
92
+
86
93
  end
94
+
87
95
  end
88
96
  end
89
97
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: acts_as_constant
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.4
7
- date: 2007-03-15 00:00:00 -04:00
6
+ version: 1.0.5
7
+ date: 2007-08-30 00:00:00 -04:00
8
8
  summary: Acts as Constant
9
9
  require_paths:
10
10
  - lib
@@ -51,7 +51,7 @@ dependencies:
51
51
  version_requirement:
52
52
  version_requirements: !ruby/object:Gem::Version::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - ">"
55
55
  - !ruby/object:Gem::Version
56
- version: 1.2.1
56
+ version: 0.0.0
57
57
  version: