zn 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 169966541807052462e0dcc386a5a2946ee19c27
4
- data.tar.gz: a9c201bb92ec31de84a59bcf20a552a839feb014
3
+ metadata.gz: 8cb0af882c77d258e9766ffc0d18ddaecb901a80
4
+ data.tar.gz: 629c1270a41ddaffe36d6cbf343efdba15fe0697
5
5
  SHA512:
6
- metadata.gz: 55f9ee7f95c5be03460fe30bd20ddac9677188200f6b41aec2b6f8ca17715119e3847c109f933eddb0b4bf5f4f3b1097408b75676ad7c68ab848096706e0cbbd
7
- data.tar.gz: 82dd515ec234cffc7a43f7a49577c9975c0fb53e699906a3e2da4005c68ad1ff9e495d7a3083789b7640fa6d3e220508ef96833d34932ae011a2c1467f01ef9d
6
+ metadata.gz: b79c006378b6330d2bac41890adaa25245acfe7909123b6ebd7a9a6776e1c9341cccf0e1569642027e921eb0d3ef65a5d2f71955a1b616b7c84c6c435984110c
7
+ data.tar.gz: 22c2fe6da7b01b900f420ad417874ce0f71d58337fdf81dee8c7ca79abf9c641369aab9ab3c0d39351b6e7bf3c981b2f1326c2c8163c7263d3c30bc347d63f5b
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Zn
2
2
 
3
+ [![Build Status](https://travis-ci.org/lpadukana/zn.svg?branch=master)](https://travis-ci.org/lpadukana/zn)
4
+
5
+
3
6
  Zn is a tool to search and correlate data sources (JSON files for now).
4
7
 
5
8
  ## Installation
@@ -22,23 +25,46 @@ Note: For latest changes, please use `exe/zn` instead of depending on the instal
22
25
 
23
26
  ## Usage
24
27
 
25
- This tool depends on an index to understand the relationship between datasets. An example is available at `spec/fixtures/starwars/index.yml`. In this case, this file defines how `people.json`, `planets.json` and `robots.json` are related.
28
+ This tool depends on an index to understand the relationship between datasets. An example is available at [spec/fixtures/starwars/index.yml](spec/fixtures/starwars/index.yml). In this case, this file defines how `people.json`, `planets.json` and `robots.json` are related.
26
29
 
27
- ### Search Examples
30
+ ### Discovering Datasets
28
31
 
29
32
  ```sh
30
- $ zn search \
31
- --config-file=spec/fixtures/starwars/index.yml \
32
- --dataset robots \
33
- --key id \
34
- --value r2
35
- {"id":"r2","name":"R2-D2","owner_id":"obi"}
33
+ $ export ZN_CONFIG_FILE=spec/fixtures/starwars/index.yml
34
+
35
+ $ zn list-datasets
36
+ people
37
+ planets
38
+ robots
39
+ ```
36
40
 
37
- # config file can be set using environment variables
41
+ Note: config file can also be passed in as `--config-file spec/fixtures/starwars/index.yml`
42
+
43
+ ### Discovering Keys
44
+
45
+ ```sh
38
46
  $ export ZN_CONFIG_FILE=spec/fixtures/starwars/index.yml
39
47
 
48
+ $ zn list-keys --dataset robots
49
+ id
50
+ name
51
+ owner_id
52
+ ```
53
+
54
+ ### Search Examples
55
+
56
+ ```sh
57
+ $ export ZN_CONFIG_FILE=spec/fixtures/starwars/index.yml
58
+
59
+ $ zn search --dataset robots --key id --value r2
60
+ {"id":"r2","name":"R2-D2","owner_id":"obi"}
61
+
40
62
  $ zn search --dataset people --key name --value Kenobi
41
63
  {"id":"obi","name":"Obi Wan Kenobi","planet_id":"ste"}
64
+
65
+ # --exact can be used to search for exact values
66
+ $ zn search --exact --dataset people --key name --value 'Obi Wan Kenobi'
67
+ {"id":"obi","name":"Obi Wan Kenobi","planet_id":"ste"}
42
68
  ```
43
69
 
44
70
  ### Search and Associate Example
@@ -82,6 +108,22 @@ $ zn search --dataset people --key name --value Kenobi | zn associate --dataset
82
108
  }
83
109
  ```
84
110
 
111
+ ### Zendesk Examples to Try
112
+
113
+ ```sh
114
+ $ export ZN_CONFIG_FILE=spec/fixtures/zendesk/index.yml
115
+
116
+ $ zn list-datasets
117
+ $ zn list-keys --dataset users
118
+ $ zn list-keys --dataset tickets
119
+ $ zn list-keys --dataset organizations
120
+ $ zn search --dataset users --key _id --value 10 | zn associate --dataset users | zn prettify-json
121
+ $ zn search --dataset tickets --key subject --value Australia | zn associate --dataset tickets | zn prettify-json
122
+ $ zn search --dataset organizations --key name --value Qualitern | zn associate --dataset organizations | zn prettify-json
123
+ $ zn search --dataset users --key _id --value 1 | wc -l
124
+ $ zn search --exact --dataset users --key _id --value 1 | wc -l
125
+ ```
126
+
85
127
  ## Tests
86
128
 
87
129
  ### Rspec
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euxo pipefail
4
+
5
+ version=$(ruby -Ilib -r zn/version -e 'puts Zn::VERSION')
6
+ tag="latheeshp/zn:${version}"
7
+ tag_latest="latheeshp/zn:latest"
8
+
9
+ docker build -t "${tag}" .
10
+ docker tag "${tag}" "${tag_latest}"
11
+
12
+ docker push "${tag}"
13
+ docker push "${tag_latest}"
@@ -7,6 +7,8 @@ module Zn
7
7
  attr_reader :datasets, :dataset_name, :foreign_key, :primary_key, :dataset, :repo
8
8
 
9
9
  def initialize(datasets, params)
10
+ raise ArgumentError, 'Datasets is nil' if datasets.nil?
11
+
10
12
  @datasets = datasets
11
13
  @dataset_name = params.fetch('dataset')
12
14
  @foreign_key = params.fetch('foreign_key')
@@ -15,7 +17,7 @@ module Zn
15
17
 
16
18
  def associate(object)
17
19
  @dataset ||= datasets.fetch(dataset_name)
18
- dataset.search(key: primary_key, value: object[foreign_key], exact: true).to_a.first
20
+ dataset.search(key: primary_key, value: object.fetch(foreign_key), exact: true).to_a.first
19
21
  end
20
22
  end
21
23
  end
@@ -7,6 +7,8 @@ module Zn
7
7
  attr_reader :datasets, :dataset_name, :foreign_key, :primary_key, :dataset, :repo
8
8
 
9
9
  def initialize(datasets, params)
10
+ raise ArgumentError, 'Datasets is nil' if datasets.nil?
11
+
10
12
  @datasets = datasets
11
13
  @dataset_name = params.fetch('dataset')
12
14
  @foreign_key = params.fetch('foreign_key')
@@ -28,7 +28,7 @@ module Zn
28
28
  value = params.fetch(:value)
29
29
  exact = params.fetch(:exact)
30
30
 
31
- if exact
31
+ if exact || value.empty?
32
32
  search_exact(key, value) { |result| yield result }
33
33
  else
34
34
  search_for_inclusion(key, value) { |result| yield result }
@@ -41,17 +41,15 @@ module Zn
41
41
  return enum_for(:search_exact, key, value) unless block_given?
42
42
 
43
43
  all.each do |element|
44
- yield element if element[key].to_s == value.to_s
44
+ yield element if element.fetch(key, '').to_s == value.to_s
45
45
  end
46
46
  end
47
47
 
48
48
  def search_for_inclusion(key, value)
49
49
  return enum_for(:search_for_inclusion, key, value) unless block_given?
50
50
 
51
- return [].each if value.empty?
52
-
53
51
  all.each do |element|
54
- yield element if element[key].to_s.include?(value.to_s)
52
+ yield element if element.fetch(key, '').to_s.include?(value.to_s)
55
53
  end
56
54
  end
57
55
  end
@@ -8,12 +8,17 @@ module Zn
8
8
  attr_reader :config_root, :assembly
9
9
 
10
10
  def initialize(assembly)
11
+ raise ArgumentError, 'Assembly is nil' if assembly.nil?
12
+
11
13
  @assembly = assembly
12
14
  @repos = {}
13
15
  @associators = {}
14
16
  end
15
17
 
16
18
  def register_repo_class(name, repo_class)
19
+ raise ArgumentError, 'Name is empty' if name.to_s.empty?
20
+ raise ArgumentError, 'Repo class is nil' if repo_class.nil?
21
+
17
22
  @repos[name] = repo_class
18
23
  end
19
24
 
@@ -24,6 +29,9 @@ module Zn
24
29
  end
25
30
 
26
31
  def register_associator_class(name, associator_class)
32
+ raise ArgumentError, 'Name is empty' if name.to_s.empty?
33
+ raise ArgumentError, 'Associator class is nil' if associator_class.nil?
34
+
27
35
  @associators[name] = associator_class
28
36
  end
29
37
 
@@ -47,6 +55,8 @@ module Zn
47
55
  end
48
56
 
49
57
  def assemble(config_yml)
58
+ raise ArgumentError, 'Config yml is empty' if config_yml.to_s.empty?
59
+
50
60
  config = YAML.load_file(config_yml)
51
61
  @config_root = File.dirname(config_yml)
52
62
  dataset_definitions = config.fetch('datasets')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zn
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Latheesh Padukana
@@ -170,6 +170,7 @@ files:
170
170
  - Rakefile
171
171
  - bin/console
172
172
  - bin/install
173
+ - bin/publish-docker-image
173
174
  - bin/release
174
175
  - bin/rspec-test
175
176
  - bin/setup