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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/offline_lookup.rb +9 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 887ba1b39a9ba252abb2a69d9ac652a8f9b3ded8
4
- data.tar.gz: 8b0d2fc3a6d65b605fd951255e4a796c02dd58f3
3
+ metadata.gz: 81bf5d7f3480aad4023793d4b1080942f3e61062
4
+ data.tar.gz: 120e4eb224c5533fa99d2d582e7aa24f42959fc3
5
5
  SHA512:
6
- metadata.gz: e1e931dc2e984e21823e18cbbfcb56c6ff8d441a04ad6c8ee90bd618333345de655afa40852c2474cd65e3a819f9b4a66bae68907d97318845645bcb2ac32368
7
- data.tar.gz: 9afcc20a56a0e6aec6c79cfa1a92ab36ea8c3f9928cb93fee8d07ecc502f65dcdf2920bf838a214265e9df398ea5a07e64cbecffad93b43b9d8c55b64e217d82
6
+ metadata.gz: 7a309b3d4386cd90102fa0db083fca4a727b6f2fdf6deb7f78db82398f6c0a522ffdcf00d3135a63b0d8c7976d6aaa46a724c31dd5f7889fa7fb40aa559ee9c2
7
+ data.tar.gz: e57b182948563dff3bd076bbc59ea488aaccd59d9ec60ef4b542fc86deba26a0541ccd89b667a81c1cefe57fbee8064e3c6c85795776e4d430663ea12ad26e2d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ##Offline Lookup
2
2
 
3
- Alhpa (0.0.2). Use at your own risk.
3
+ Alhpa (0.0.3). Use at your own risk.
4
4
 
5
5
  IMPORTANT: don't use this for models that have a lot of data!!
6
6
  This is basically a in-memory pseudo-index intended to speed up quick, repeated
@@ -4,9 +4,14 @@
4
4
 
5
5
  module OfflineLookup
6
6
  module ActiveRecord
7
- def use_offline_lookup(field = :name, key: :id, identiyy_methods: true, lookup_methods: true)
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 = {field: field.to_s, key: key.to_s, lookup_methods: lookup_methods}.freeze
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[:identiyy_methods]
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]
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Schwartz