looksist 0.1.7 → 0.1.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05e00fd33e27ccbadbb9a2cda52ec0836c00df83
4
- data.tar.gz: 36e9090fcacd6cddbe4dfb61f1e0065bb90ddcb7
3
+ metadata.gz: 59e638529e17d4968241ad31416d21e1a080b919
4
+ data.tar.gz: ca701b1a666bb76129bc47b64ff88d5749827a77
5
5
  SHA512:
6
- metadata.gz: ffb2876b6acc1b1d140532b7448c63a2cd0f1f26993e5cefa6d64891bc9ef9a13b2ad76d1345f142a060757aa4500209aa5f7606b400ffd3b845cca0ab44cdae
7
- data.tar.gz: bdfee543c270c43b238b3c982492ba91dedf388848e116980a720e1661154665a70686074ef0498f91c103869790085975c70895d867e12e12e5b3b52ea4ee84
6
+ metadata.gz: 6ce8904095dce8cfe8c69d8fd13bd52969c3f9e055d4fa280f7f30a257c9ee31cffb6228c56c7c03ab98c3ca506e5f1ed0d66afeb7d53ec2ca62de42a3037960
7
+ data.tar.gz: c0d847600a601f99569dac66439247882ded32f2df00a733e95e60147c6ae25f157bbbef386e0e41fc489e3951c3075fbabcee5217699f32be52cd8d1f051d62
@@ -8,11 +8,11 @@ Feature: I should be able to look up all keys in a bucket by pattern so that I c
8
8
  | ids/2 | ID 2 |
9
9
  | ids/3 | ID 3 |
10
10
  | ids/4 | ID 4 |
11
- | non_matching_ids/4 | ID 4 |
11
+ | non_matching_ids/4 | ID 5 |
12
12
  When I ask looksist to lookup by pattern "id"
13
13
  Then I see the response to be the following
14
- | key | value |
15
- | ids/1 | ID 1 |
16
- | ids/2 | ID 2 |
17
- | ids/3 | ID 3 |
18
- | ids/4 | ID 4 |
14
+ | key | value |
15
+ | 1 | ID 1 |
16
+ | 2 | ID 2 |
17
+ | 3 | ID 3 |
18
+ | 4 | ID 4 |
@@ -0,0 +1,30 @@
1
+ @hashes
2
+ Feature: Enrich hashes
3
+
4
+ @columnar
5
+ Scenario: I should be able to enrich columnar hashes
6
+ Given I have the following keys setup in Redis
7
+ | key | value |
8
+ | employees/10 | Employee 1 |
9
+ | employees/20 | Employee 2 |
10
+ | employees/3 | Employee 3 |
11
+ | employees/4 | Employee 4 |
12
+ | employers/4 | Employee 5 |
13
+ When I ask DeepHash for metrics
14
+ Then I should see the following "employee names" be injected into the hash at "$.table.inner_table"
15
+ | value |
16
+ | Employee 1 |
17
+ | Employee 2 |
18
+
19
+ @object
20
+ Scenario: I should be able to enrich object like hashes
21
+ Given I have the following keys setup in Redis
22
+ | key | value |
23
+ | items/1 | Idly |
24
+ | items/2 | Pongal |
25
+ | items/3 | Off Menu |
26
+ When I ask Menu for menu
27
+ Then I should see the following "item name" enriched for each sub hash at "$.table.menu"
28
+ | value |
29
+ | Idly |
30
+ | Pongal |
@@ -0,0 +1,15 @@
1
+ class DeepHash
2
+ include Looksist
3
+
4
+ def metrics
5
+ {
6
+ table: {
7
+ inner_table: {
8
+ employee_id: [10, 20]
9
+ }
10
+ }
11
+ }
12
+ end
13
+
14
+ inject after: :metrics, at: '$.table.inner_table', using: :employee_id, populate: :employee_name
15
+ end
@@ -0,0 +1,20 @@
1
+ class Menu
2
+ include Looksist
3
+
4
+ def menu
5
+ {
6
+ table: {
7
+ menu: [
8
+ {
9
+ item_id: 1
10
+ },
11
+ {
12
+ item_id: 2
13
+ }
14
+ ]
15
+ }
16
+ }
17
+ end
18
+
19
+ inject after: :menu, at: '$.table.menu', using: :item_id, populate: :item_name
20
+ end
@@ -0,0 +1,13 @@
1
+ @models
2
+ Feature: Lookup model properties
3
+
4
+ Scenario: I should be able to inject model properties
5
+ Given I have the following keys setup in Redis
6
+ | key | value |
7
+ | employees/1 | Employee 1 |
8
+ | employees/2 | Employee 2 |
9
+ | employees/3 | Employee 3 |
10
+ | employees/4 | Employee 4 |
11
+ | employers/4 | Employee 5 |
12
+ When I create an instance of the "employee" class with id "1"
13
+ Then I model created should have "name" "Employee 1"
@@ -0,0 +1,9 @@
1
+ class Employee
2
+ include Looksist
3
+ attr_accessor :employee_id
4
+ lookup :name, using = :employee_id
5
+
6
+ def initialize(id)
7
+ @employee_id = id
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ When(/^I ask (DeepHash|Menu) for (metrics|menu)$/) do |lookup_service, method|
2
+ @enriched_hash = Object.const_get(lookup_service.classify).new.send(method)
3
+ end
4
+
5
+ Then(/^I should see the following "([^"]*)" be injected into the hash at "([^"]*)"$/) do |target, json_path, table|
6
+ expected_names = table.hashes.collect { |row| row[:value] }
7
+ actual_names = JsonPath.new("#{json_path}.#{target.parameterize.underscore.singularize}").on(@enriched_hash.with_indifferent_access)
8
+ expect(actual_names.size).to eq(1)
9
+ expect(actual_names.first).to eq(expected_names)
10
+ end
11
+
12
+ Then(/^I should see the following "([^"]*)" enriched for each sub hash at "([^"]*)"$/) do |name, jsonpath, table|
13
+ expect(JsonPath.new(jsonpath).on(@enriched_hash.with_indifferent_access).first.collect { |i| i[name.parameterize.underscore.to_sym] }).to eq(table.hashes.collect { |i| i[:value] })
14
+ end
@@ -0,0 +1,7 @@
1
+ When(/^I create an instance of the "([^"]*)" class with id "([^"]*)"$/) do |klass, id|
2
+ @model_instance = (Object.const_get klass.classify).new(id)
3
+ end
4
+
5
+ Then(/^I model created should have "([^"]*)" "([^"]*)"$/) do |method, value|
6
+ expect(@model_instance.send(method.to_sym)).to eq(value)
7
+ end
@@ -9,6 +9,9 @@ require 'looksist/safe_lru_cache'
9
9
  require 'pry'
10
10
  require 'redis'
11
11
  require 'hiredis'
12
+ require 'jsonpath'
13
+
14
+ I18n.enforce_available_locales = false
12
15
 
13
16
  Looksist.configure do |looksist|
14
17
  looksist.lookup_store = Redis.new(url: 'redis://localhost:6379', driver: :hiredis)
data/lib/looksist.rb CHANGED
@@ -28,7 +28,7 @@ module Looksist
28
28
  def bucket_dump(entity)
29
29
  keys = Looksist.lookup_store.keys("#{entity.pluralize}*")
30
30
  values = Looksist.redis_service.send("#{entity}_for", keys.collect{|i| i.split('/').last})
31
- keys.zip(values).to_h
31
+ (keys.collect {|i| i.split('/').last}).zip(values).to_h
32
32
  end
33
33
  end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Lookist
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: looksist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - RC
@@ -211,8 +211,15 @@ files:
211
211
  - README.md
212
212
  - Rakefile
213
213
  - features/bucket_lookup.feature
214
- - features/env.rb
214
+ - features/hash_lookup.feature
215
+ - features/hash_services/deep_hash.rb
216
+ - features/hash_services/menu.rb
217
+ - features/model_lookup.feature
218
+ - features/models/employee.rb
215
219
  - features/step_definitions/bucket_lookup_steps.rb
220
+ - features/step_definitions/hash_lookup_steps.rb
221
+ - features/step_definitions/model_lookup_steps.rb
222
+ - features/support/env.rb
216
223
  - lib/looksist.rb
217
224
  - lib/looksist/common.rb
218
225
  - lib/looksist/core.rb
@@ -252,8 +259,15 @@ specification_version: 4
252
259
  summary: Redis backed lookup for your models
253
260
  test_files:
254
261
  - features/bucket_lookup.feature
255
- - features/env.rb
262
+ - features/hash_lookup.feature
263
+ - features/hash_services/deep_hash.rb
264
+ - features/hash_services/menu.rb
265
+ - features/model_lookup.feature
266
+ - features/models/employee.rb
256
267
  - features/step_definitions/bucket_lookup_steps.rb
268
+ - features/step_definitions/hash_lookup_steps.rb
269
+ - features/step_definitions/model_lookup_steps.rb
270
+ - features/support/env.rb
257
271
  - spec/looksist/hashed_spec.rb
258
272
  - spec/looksist/looksist_spec.rb
259
273
  - spec/looksist/redis_service_spec.rb