offline_lookup 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/offline_lookup.rb +9 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81bf5d7f3480aad4023793d4b1080942f3e61062
|
4
|
+
data.tar.gz: 120e4eb224c5533fa99d2d582e7aa24f42959fc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a309b3d4386cd90102fa0db083fca4a727b6f2fdf6deb7f78db82398f6c0a522ffdcf00d3135a63b0d8c7976d6aaa46a724c31dd5f7889fa7fb40aa559ee9c2
|
7
|
+
data.tar.gz: e57b182948563dff3bd076bbc59ea488aaccd59d9ec60ef4b542fc86deba26a0541ccd89b667a81c1cefe57fbee8064e3c6c85795776e4d430663ea12ad26e2d
|
data/README.md
CHANGED
data/lib/offline_lookup.rb
CHANGED
@@ -4,9 +4,14 @@
|
|
4
4
|
|
5
5
|
module OfflineLookup
|
6
6
|
module ActiveRecord
|
7
|
-
def use_offline_lookup(field = :name, key: :id,
|
7
|
+
def use_offline_lookup(field = :name, key: :id, identity_methods: true, lookup_methods: true)
|
8
8
|
class_attribute :offline_lookup_values, :offline_lookup_options
|
9
|
-
self.offline_lookup_options = {
|
9
|
+
self.offline_lookup_options = {
|
10
|
+
field: field.to_s,
|
11
|
+
key: key.to_s,
|
12
|
+
identity_methods: !!identity_methods,
|
13
|
+
lookup_methods: !!lookup_methods
|
14
|
+
}.freeze
|
10
15
|
self.offline_lookup_values = self.all.pluck(key, field).to_h.freeze
|
11
16
|
|
12
17
|
include OfflineLookup::Base
|
@@ -74,12 +79,12 @@ module OfflineLookup
|
|
74
79
|
end
|
75
80
|
|
76
81
|
# instance method: true if instance is of named type (e.g. FooType.first.bar?)
|
77
|
-
if self.offline_lookup_options[:
|
82
|
+
if self.offline_lookup_options[:identity_methods]
|
78
83
|
define_method(builder.indentiy_method_name(value)) do
|
79
84
|
self.attributes[self.offline_lookup_options[:key]] == key
|
80
85
|
end
|
81
86
|
end
|
82
|
-
|
87
|
+
|
83
88
|
# class method: get instance by named method (e.g. FooType.bar)
|
84
89
|
# not "Offline", but lookup by indexed key. Also, synactic sugar.
|
85
90
|
if self.offline_lookup_options[:lookup_methods]
|