-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class Revector | ||
module Exists | ||
def self.check!(item, iteratee) | ||
compare(Utility::TryFetchOrBlank[item, iteratee]) | ||
end | ||
|
||
def self.compare(value, other = false) | ||
case value | ||
in [*] | String | ||
value.size.positive?.to_s == other.to_s | ||
else | ||
!!value.to_s == other.to_s | ||
end | ||
end | ||
end | ||
|
||
module NotExists | ||
def self.check!(item, iteratee) | ||
!Exists.check!(item, iteratee) | ||
end | ||
|
||
def self.compare(value, other = nil) | ||
!Exists.compare(value, other) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class Revector | ||
VERSION = '0.1.0' | ||
VERSION = '0.1.1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
id: 1, | ||
name: 'Test #1', | ||
email: '[email protected]', | ||
contact_id: '1', | ||
schedule: { all_day: true, opened: true }, | ||
numbers: %w[1 2], | ||
phones: [ | ||
|
@@ -22,6 +23,7 @@ | |
id: 2, | ||
name: 'Test #2', | ||
email: '[email protected]', | ||
contact_id: '2', | ||
schedule: { all_day: false, opened: false }, | ||
numbers: %w[3 4], | ||
phones: [], | ||
|
@@ -32,6 +34,7 @@ | |
id: 3, | ||
name: 'Test #3', | ||
email: '[email protected]', | ||
contact_id: '', | ||
schedule: { all_day: false, opened: false }, | ||
numbers: %w[5 6], | ||
phones: [ | ||
|
@@ -44,6 +47,40 @@ | |
end | ||
|
||
context 'Deep values' do | ||
context 'ex' do | ||
it 'if the value is not empty' do | ||
filters = { 'phones.number': { ex: 'true' } } | ||
|
||
collection = described_class.swap(data, filters) | ||
|
||
expect(collection.size).to eq(2) | ||
end | ||
|
||
it 'if the value is not empty' do | ||
filters = { 'phones.number': { not_ex: 'true' } } | ||
|
||
collection = described_class.swap(data, filters) | ||
|
||
expect(collection.size).to eq(1) | ||
end | ||
|
||
it 'if the value is not empty' do | ||
filters = { contact_id: { ex: 'true' } } | ||
|
||
collection = described_class.swap(data, filters) | ||
|
||
expect(collection.size).to eq(2) | ||
end | ||
|
||
it 'if the value is empty' do | ||
filters = { contact_id: { not_ex: 'true' } } | ||
|
||
collection = described_class.swap(data, filters) | ||
|
||
expect(collection.size).to eq(1) | ||
end | ||
end | ||
|
||
context 'eq' do | ||
context 'array of hash' do | ||
it 'match array values in deep structure' do | ||
|