offline_lookup 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/offline_lookup.rb +6 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 214a550c54e40d9f718478920e4f9ec0a4a8be16
4
- data.tar.gz: 834b7a4a9b81da79a8fb10f23a0fe6a001c93579
3
+ metadata.gz: 2db35bb5e31d4cfde77e91c6f67988c5cdf6dfe9
4
+ data.tar.gz: 7743e8b15d2f1c93f121b99f5cb9cca0d302a2ce
5
5
  SHA512:
6
- metadata.gz: 7d2994fff30186971db79cbf00d7e9f8cb6dbca51ade19522e73e7a74f765b1e4e798a982a3a98f1a9ed189b0fc33b7d710cc143e847601e483c619f2131cffc
7
- data.tar.gz: 716e5f920f9492a1f3951eb5dc476625b4c2f031e875166602969c912577da1a65803462962cdd8ba69ccb7cc065b5a2f4c564afae7d98539e00d2d623833da7
6
+ metadata.gz: 0c1f72f28029f3d4e7d9bcad89996e3fc962147e886f9cdad6262b2e86b4fc3725aff4cfc6116e18a61312ed0d578f9cd0f29943da7c30f95a33b34a27161846
7
+ data.tar.gz: c426d15af5a5a675f28aada0d1acb760ec3e68f83bc521f3b8e565d6df4f73310ab643f8f0fc342dc7a83af23dd33fc8943333af1e66c4501d9b00290b784a3c
@@ -119,14 +119,17 @@ module OfflineLookup
119
119
  ### define value-named methods such as :two_hour_id and :two_hour?
120
120
 
121
121
  self.offline_lookup_values.each do |key, value|
122
+ # class method: get key value (e.g. FooType.bar_id)
122
123
  define_singleton_method(builder.key_method_name(value)) do
123
124
  key
124
125
  end
125
126
 
126
- define_singleton_method(builder.indentiy_method_name(value)) do
127
+ # instance method: true if instance is of named type (e.g. FooType.first.bar?)
128
+ define_method(builder.indentiy_method_name(value)) do
127
129
  self.attributes[self.offline_lookup_options[:key]] == key
128
130
  end
129
131
 
132
+ # class method: get instance by named method (e.g. FooType.bar)
130
133
  # not "Offline", but lookup by indexed key. Also, synactic sugar.
131
134
  if self.offline_lookup_options[:lookup_methods]
132
135
  define_singleton_method(builder.lookup_method_name(value)) do
@@ -138,24 +141,17 @@ module OfflineLookup
138
141
 
139
142
 
140
143
  ### define statically-named methods where you pass in the named value, e.g., id_for_name(:two_hour)
141
-
144
+ # e.g. FooType.name_for_id(1)
142
145
  define_singleton_method(builder.field_for_key_method_name) do |key_value|
143
146
  self.offline_lookup_values[key_value]
144
147
  end
145
148
 
149
+ # e.g. FooType.id_for_name("Bar")
146
150
  define_singleton_method(builder.key_for_field_method_name) do |field_value|
147
151
  self.offline_lookup_values.find{|k, v| v.to_s == field_value.to_s}.first
148
152
  end
149
153
 
150
154
  end
151
-
152
- module ClassMethods
153
- def quick_lookup(value)
154
- key = self.offline_lookup_values.find{|k, v| v.to_s == value.to_s}.first
155
- find(key)
156
- end
157
- end
158
-
159
155
  end
160
156
  end
161
157
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: offline_lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Schwartz