flexi-json 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b10a91e8b4e687fdd0c69e73b8a53d6f1e66e96361fe08259c7244aec87e638b
4
- data.tar.gz: 2f7a7dd6d9acc9069c3c1884ff98736041113889c8cd35efa5c94bd7f6acd48e
3
+ metadata.gz: 4e8c41b6f187468d64f2d6d3321f7557a5ec17410a69508b8cc1391560ab81be
4
+ data.tar.gz: 5b7aeb733149ae14bce5481878566a99b4a971232900285153278f11d74decf8
5
5
  SHA512:
6
- metadata.gz: 1f793341d32d74087ce18d669f0df367e1503a081a4e227cb8dbda80e8e3a64fdc02b9bd7324b69738bde9b86aeb6f70c287ea75db0bd3accafff23ea08216b5
7
- data.tar.gz: dbd6b4bf1f222c4fb657ab346057ae975073397b7c5a4d84c32f0589b02e9c905be510ae6ea10c49b19515a312f19ef950bc64e0573268f80172ca185e8fa896
6
+ metadata.gz: 717ae733016f7913d3ef4d2d8d065fbded43304ff3f62b45ede49abf1aed3de63144202fd17bd8e12e4fa0bde1b9c22067027a6f66f873201ce5f30434f9843d
7
+ data.tar.gz: f08b3a2418807a5afce6e2b2c30db6e142829ff2c6fbe11968376f0612e8d6cc5a92315a8e98b377fb49c983d3229ca40ec0d3102982d488f0c4ff8e857d84ca
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- [![Gem Version](https://badge.fury.io/rb/flexi-json.svg)](https://badge.fury.io/rb/flexi-json) [![Github Actions](https://github.com/GD-Personal/flexi-json/actions/workflows/ci.yml/badge.svg)](https://github.com/GD-Personal/flexi-json/actions) [![Maintainability](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/maintainability)](https://codeclimate.com/github/GD-Personal/flexi-json/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/test_coverage)](https://codeclimate.com/github/GD-Personal/flexi-json/test_coverage)
1
+ [![Gem Version](https://img.shields.io/gem/v/flexi-json.svg)](https://rubygems.org/gems/flexi-json)
2
+ [![Github Actions](https://github.com/GD-Personal/flexi-json/actions/workflows/ci.yml/badge.svg)](https://github.com/GD-Personal/flexi-json/actions)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/maintainability)](https://codeclimate.com/github/GD-Personal/flexi-json/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/test_coverage)](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
- - Improve search filter by specifying fields to filter from
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
@@ -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: Searcher::DEFAULT_MATCH_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[:matched_all] ? :all? : :any?
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]
@@ -5,11 +5,6 @@ module Flexi
5
5
  class Searcher
6
6
  attr_reader :data, :result
7
7
 
8
- DEFAULT_MATCH_OPTIONS = {
9
- matched_all: false,
10
- exact_match: false
11
- }.freeze
12
-
13
8
  def initialize(data)
14
9
  @data = data
15
10
  @result = []
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Flexi
4
4
  module Json
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
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 Error < StandardError; end
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.3.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-21 00:00:00.000000000 Z
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.14
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: []