flexi-json 0.3.0 → 0.4.0
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 +4 -4
- data/README.md +13 -2
- data/lib/flexi/json/configuration.rb +26 -0
- data/lib/flexi/json/dataset.rb +2 -3
- data/lib/flexi/json/searcher.rb +0 -5
- data/lib/flexi/json/version.rb +1 -1
- data/lib/flexi/json.rb +14 -5
- metadata +7 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e8c41b6f187468d64f2d6d3321f7557a5ec17410a69508b8cc1391560ab81be
|
|
4
|
+
data.tar.gz: 5b7aeb733149ae14bce5481878566a99b4a971232900285153278f11d74decf8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 717ae733016f7913d3ef4d2d8d065fbded43304ff3f62b45ede49abf1aed3de63144202fd17bd8e12e4fa0bde1b9c22067027a6f66f873201ce5f30434f9843d
|
|
7
|
+
data.tar.gz: f08b3a2418807a5afce6e2b2c30db6e142829ff2c6fbe11968376f0612e8d6cc5a92315a8e98b377fb49c983d3229ca40ec0d3102982d488f0c4ff8e857d84ca
|
data/README.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
[](https://rubygems.org/gems/flexi-json)
|
|
2
|
+
[](https://github.com/GD-Personal/flexi-json/actions)
|
|
3
|
+
[](https://codeclimate.com/github/GD-Personal/flexi-json/maintainability)
|
|
4
|
+
[](https://codeclimate.com/github/GD-Personal/flexi-json/test_coverage)
|
|
2
5
|
|
|
3
6
|
# flexi-json
|
|
4
7
|
|
|
@@ -54,8 +57,16 @@ flexi_json.search({first_name: "john", address: "sydney"}, options)
|
|
|
54
57
|
# => [#<Flexi::Json::Dataset:0x0000ffffa0f5f668 @address="Sydney Australia", @attributes={:name=>"John", :address=>"Sydney Australia"}, @name="John", @searchable_fields=["name", "address"]>]
|
|
55
58
|
```
|
|
56
59
|
|
|
60
|
+
## Configuration
|
|
61
|
+
```ruby
|
|
62
|
+
Flexi::Json.configure do |config|
|
|
63
|
+
config.exact_match_search = true
|
|
64
|
+
config.match_all_fields = true
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
57
68
|
## TODOS
|
|
58
|
-
-
|
|
69
|
+
- Generate results in json, csv, txt, or output in the console
|
|
59
70
|
- Add CRUD support to the dataset
|
|
60
71
|
- Optimise the search function by implementing indeces
|
|
61
72
|
- Optimise the loader by chunking the data
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "singleton"
|
|
2
|
+
module Flexi
|
|
3
|
+
module Json
|
|
4
|
+
class ConfigError < StandardError; end
|
|
5
|
+
|
|
6
|
+
class Configuration
|
|
7
|
+
include Singleton
|
|
8
|
+
|
|
9
|
+
attr_accessor :exact_match_search, :match_all_fields
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def default_match_options
|
|
13
|
+
{
|
|
14
|
+
match_all: @match_all_fields || false,
|
|
15
|
+
exact_match: @exact_match_search || false
|
|
16
|
+
}.freeze
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
@exact_match_search = false
|
|
22
|
+
@match_all_fields = false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/flexi/json/dataset.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require "debug"
|
|
2
1
|
module Flexi
|
|
3
2
|
module Json
|
|
4
3
|
class Dataset
|
|
@@ -13,13 +12,13 @@ module Flexi
|
|
|
13
12
|
end
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
def matches?(query, fields = searchable_fields, options:
|
|
15
|
+
def matches?(query, fields = searchable_fields, options: Flexi::Json::Configuration.default_match_options)
|
|
17
16
|
validateable_fields = query.is_a?(Hash) ? query.keys.map(&:to_s) : fields
|
|
18
17
|
valid_fields = validateable_fields&.select { |field| searchable_fields.include?(field) } || searchable_fields
|
|
19
18
|
|
|
20
19
|
return false if valid_fields.empty?
|
|
21
20
|
|
|
22
|
-
matching_method = options[:
|
|
21
|
+
matching_method = options[:match_all] ? :all? : :any?
|
|
23
22
|
valid_fields.public_send(matching_method) do |field|
|
|
24
23
|
search_query = query.is_a?(Hash) ? query[field.to_sym] : query
|
|
25
24
|
if options[:exact_match]
|
data/lib/flexi/json/searcher.rb
CHANGED
data/lib/flexi/json/version.rb
CHANGED
data/lib/flexi/json.rb
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "json/configuration"
|
|
3
4
|
require_relative "json/dataset"
|
|
4
5
|
require_relative "json/loader"
|
|
5
6
|
require_relative "json/searcher"
|
|
6
7
|
require_relative "json/version"
|
|
7
8
|
|
|
8
9
|
module Flexi::Json
|
|
9
|
-
class
|
|
10
|
+
class << self
|
|
11
|
+
attr_writer :configuration
|
|
12
|
+
|
|
13
|
+
# Access or initialize the configuration object
|
|
14
|
+
def configuration
|
|
15
|
+
@configuration ||= Flexi::Json::Configuration.instance
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Configure block for setting custom configurations
|
|
19
|
+
def configure
|
|
20
|
+
yield(configuration)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
10
23
|
|
|
11
24
|
class Run
|
|
12
25
|
# Your code goes here...
|
|
@@ -22,9 +35,5 @@ module Flexi::Json
|
|
|
22
35
|
def find_duplicates(keys)
|
|
23
36
|
@searcher.find_duplicates(keys)
|
|
24
37
|
end
|
|
25
|
-
|
|
26
|
-
def display_results
|
|
27
|
-
@searcher.display_results
|
|
28
|
-
end
|
|
29
38
|
end
|
|
30
39
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: flexi-json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gerda Decio
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-09-
|
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -125,6 +125,7 @@ files:
|
|
|
125
125
|
- Rakefile
|
|
126
126
|
- changelog_config.yml
|
|
127
127
|
- lib/flexi/json.rb
|
|
128
|
+
- lib/flexi/json/configuration.rb
|
|
128
129
|
- lib/flexi/json/dataset.rb
|
|
129
130
|
- lib/flexi/json/loader.rb
|
|
130
131
|
- lib/flexi/json/searcher.rb
|
|
@@ -139,7 +140,7 @@ metadata:
|
|
|
139
140
|
homepage_uri: https://github.com/GD-Personal/flexi-json
|
|
140
141
|
source_code_uri: https://github.com/GD-Personal/flexi-json
|
|
141
142
|
changelog_uri: https://github.com/GD-Personal/flexi-json/blob/main/CHANGELOG.md
|
|
142
|
-
post_install_message:
|
|
143
|
+
post_install_message:
|
|
143
144
|
rdoc_options: []
|
|
144
145
|
require_paths:
|
|
145
146
|
- lib
|
|
@@ -154,8 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
154
155
|
- !ruby/object:Gem::Version
|
|
155
156
|
version: '0'
|
|
156
157
|
requirements: []
|
|
157
|
-
rubygems_version: 3.5.
|
|
158
|
-
signing_key:
|
|
158
|
+
rubygems_version: 3.5.16
|
|
159
|
+
signing_key:
|
|
159
160
|
specification_version: 4
|
|
160
161
|
summary: A ruby gem designed for manipulating JSON data.
|
|
161
162
|
test_files: []
|