acts_as_constant 1.0.1 → 1.0.2

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 +13 -9
  2. metadata +2 -2
@@ -12,28 +12,30 @@ module ActiveRecord #:nodoc:
12
12
  #puts self.to_s
13
13
 
14
14
  # let's set up a variable to represent the name of the klass
15
- const = self.to_s
15
+ klass = self.to_s
16
+ #puts "klass = #{klass}"
17
+ const = klass.upcase.gsub("::", "_")
16
18
  #puts "const = #{const}"
17
19
 
18
20
  # create a constant array to hold the values
19
21
  # create a nice get method to pull from the constant array
20
22
  class_eval %{
21
23
  private
22
- #{const.upcase}_CONSTANTS = []
24
+ #{const}_CONSTANTS = []
23
25
 
24
26
  public
25
27
  def self.get(id)
26
28
  return nil if id.blank?
27
- #{const.upcase}_CONSTANTS[id]
29
+ #{const}_CONSTANTS[id]
28
30
  end
29
31
 
30
32
  def self.CONSTANTS
31
- #{const.upcase}_CONSTANTS
33
+ #{const}_CONSTANTS
32
34
  end
33
35
  }
34
36
 
35
37
  # let's build methods for everything in the database.
36
- rows = eval "#{const}.find(:all)"
38
+ rows = eval "#{klass}.find(:all)"
37
39
 
38
40
  rows.each do |rec|
39
41
  #puts rec.inspect
@@ -48,23 +50,25 @@ module ActiveRecord #:nodoc:
48
50
  # let's create two methods an all downcase method for accessing the constant and an upper case one
49
51
  class_eval %{
50
52
  # by using .freeze we can prevent the object from being modified.
51
- #{const.upcase}_CONSTANTS[#{rec.id}] = rec.freeze
53
+ #{const}_CONSTANTS[#{rec.id}] = rec.freeze
52
54
 
53
55
  def self.#{name}
54
- #{const.upcase}_CONSTANTS[#{rec.id}]
56
+ #{const}_CONSTANTS[#{rec.id}]
55
57
  end
56
58
 
57
59
  def self.#{name.upcase}
58
- #{const.upcase}_CONSTANTS[#{rec.id}]
60
+ #{const}_CONSTANTS[#{rec.id}]
59
61
  end
60
62
  }
61
63
  end
62
64
  end
63
65
  class_eval %{
64
66
  # by using .freeze we can prevent the constants array from being modified.
65
- #{const.upcase}_CONSTANTS.freeze
67
+ #{const}_CONSTANTS.freeze
66
68
  }
67
69
  rescue => ex
70
+ puts "Error in acts_as_constant: #{ex.message}"
71
+ puts ex.backtrace
68
72
  end
69
73
 
70
74
  end
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.1
7
- date: 2007-02-27 00:00:00 -05:00
6
+ version: 1.0.2
7
+ date: 2007-02-28 00:00:00 -05:00
8
8
  summary: Acts as Constant
9
9
  require_paths:
10
10
  - lib