acts_as_lookup 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/TODO +2 -0
- data/acts_as_lookup.gemspec +2 -2
- data/lib/acts_as_lookup.rb +20 -3
- metadata +2 -2
data/TODO
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
Things to work on:
|
2
2
|
|
3
|
+
|
3
4
|
* find a better workaround for the cached instance problem (see https://rails.lighthouseapp.com/projects/8994/tickets/1339, for example) than explicit requiring of lookup classes (see acts_as_lookup.rb : ActsAsLookupHasLookupClassMethods#has_lookup)
|
4
5
|
* for now, it's required to include :id in the values hashes; enhance to allow leaving :id off (by specifying :uniqueness_column) and fetch them from db (option will only be available for :sync_with_db == true)
|
5
6
|
* allow gem to be used outside Rails by specifying alternative implementations for db-hitting methods....e.g. add configuration values that specify method names to call to load/write/remove from db. see +acts_as_lookup_fetch_values+ method comment.
|
@@ -18,6 +19,7 @@ Things to work on:
|
|
18
19
|
** indexed_columns: which columns can be used in lookup_by_column methods
|
19
20
|
*** allows for specifying other values in the model that don't need to be lookupable columns, e.g. if there are columns with non-unique values, foreign keys to other tables etc.
|
20
21
|
*** default will be to use all columns specified in the model
|
22
|
+
*** probably store the lookup caches in one giant hash, each entry is a hash :column => lookup_hash_for_that_column
|
21
23
|
** uniqueness_column: which column defines uniqueness of a record if :id is not set in model
|
22
24
|
*** allows to leave off the id when specifying the rows in model if it doesn't really matter, but still do the inserting/removing of rows automatically
|
23
25
|
*** default will be :name (if :name not specified in the data in the model, then if uniqueness_column isn't set, there will be errors)
|
data/acts_as_lookup.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{acts_as_lookup}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Percival"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-09}
|
13
13
|
s.description = %q{Provides an easy means for creating models that act like enumerations or lookup
|
14
14
|
tables. You can specify the lookup values in your Rails models and can lazily
|
15
15
|
push these to the associated db tables (or not). Also dynamically adds helpful
|
data/lib/acts_as_lookup.rb
CHANGED
@@ -111,10 +111,10 @@ module ActsAsLookupClassMethods
|
|
111
111
|
# updates the lookup cache hashes from @@acts_as_lookup_values
|
112
112
|
#-----------------------------------------------------------------------------
|
113
113
|
def acts_as_lookup_refresh_caches
|
114
|
+
# FUTURE: this will get cleaned up, and will dynamically select which
|
115
|
+
# columns to establish lookup caches for.
|
114
116
|
@@acts_as_lookup_values.each do |val|
|
115
117
|
@@acts_as_lookup_by_id.reverse_merge! val.id => val
|
116
|
-
end
|
117
|
-
@@acts_as_lookup_values.each do |val|
|
118
118
|
@@acts_as_lookup_by_name.reverse_merge! val.name => val
|
119
119
|
end
|
120
120
|
end
|
@@ -123,11 +123,28 @@ module ActsAsLookupClassMethods
|
|
123
123
|
# adds a class method to access a particular lookup value via a shortcut
|
124
124
|
# method
|
125
125
|
#
|
126
|
+
# does the following transformations:
|
127
|
+
# - converts spaces to underscores
|
128
|
+
# - downcases entire method name unless the constant is already all caps,
|
129
|
+
# in which case, leaves method name in all caps
|
130
|
+
# - checks for name conflicts and raises exception if the shortcut method
|
131
|
+
# name collides with existing method
|
132
|
+
#
|
126
133
|
# FUTURE: will allow for any column to be used here; for now, hardcoded
|
127
134
|
# to lookup by name
|
128
135
|
#-----------------------------------------------------------------------------
|
129
136
|
def acts_as_lookup_add_shortcut(name)
|
130
|
-
|
137
|
+
|
138
|
+
method_name = name.gsub(/ /, '_')
|
139
|
+
unless method_name.upcase == method_name
|
140
|
+
method_name.downcase!
|
141
|
+
end
|
142
|
+
if respond_to?(method_name.to_sym)
|
143
|
+
raise "Cannot create method '#{method_name}' to #{self.inspect} " +
|
144
|
+
"as it conflicts with existing method with same name"
|
145
|
+
end
|
146
|
+
|
147
|
+
instance_eval "def #{method_name}; self.lookup_by_name '#{name}'; end"
|
131
148
|
end
|
132
149
|
|
133
150
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Percival
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|