rordash 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 +4 -4
- data/dev/setup.rb +1 -0
- data/lib/rordash/chain.rb +42 -0
- data/lib/rordash/hash_util.rb +1 -1
- data/lib/rordash/version.rb +1 -1
- data/lib/rordash.rb +7 -1
- data/spec/rordash/chain_spec.rb +25 -0
- data/spec/rordash_spec.rb +10 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a463d5fefac0a24c9690767a00ddc2d85bea2eacd0e4ac97f7e917b7b091e2ed
|
4
|
+
data.tar.gz: e4e1764191e3a48b77f5ff113520a832122c7127e05f020ea17d07217abc781b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d888c1aa5df614564a0eb7dc31d3125e1fd01dd09125bfa5b003d7279f23a4f973a0c61bb872476a5a7203cceabc53437dacf62c13d461633cf0de38d2da9a58
|
7
|
+
data.tar.gz: 5c27cf932778fe055f4c1162f2efb8777c4aa08e705b47ca05151576325807e4fbfee2ea614781698496628560a143066e384a3612baf18c8af4ebf3d5395f78
|
data/dev/setup.rb
CHANGED
@@ -12,6 +12,7 @@ require 'active_support/core_ext/hash/keys'
|
|
12
12
|
require 'active_support/core_ext/module/delegation'
|
13
13
|
require 'active_support/core_ext/object/blank'
|
14
14
|
require 'active_support/core_ext/enumerable'
|
15
|
+
require 'active_support/hash_with_indifferent_access'
|
15
16
|
require 'mime-types'
|
16
17
|
require 'faker'
|
17
18
|
require 'oj'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Rordash
|
2
|
+
class Chain
|
3
|
+
attr_reader :value
|
4
|
+
|
5
|
+
def initialize(value)
|
6
|
+
@value = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_h
|
10
|
+
@value = HashUtil.from_string(@value)
|
11
|
+
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_str
|
16
|
+
@value = HashUtil.to_str(@value)
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def deep_compact
|
22
|
+
@value = HashUtil.deep_compact(@value)
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def pick(paths)
|
28
|
+
@value = HashUtil.pick(@value, paths)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def merge(other)
|
33
|
+
@value = @value.merge(other)
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def set(path, value)
|
38
|
+
HashUtil.set(@value, path, value)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/rordash/hash_util.rb
CHANGED
@@ -127,7 +127,7 @@ module Rordash
|
|
127
127
|
result = {}
|
128
128
|
|
129
129
|
dot(attrs, keep_arrays: true) do |k, v|
|
130
|
-
value = each_value_proc.respond_to?(:call) ? each_value_proc&.call(k, v) : v.compact
|
130
|
+
value = each_value_proc.respond_to?(:call) ? each_value_proc&.call(k, v) : v.try(:compact)
|
131
131
|
next if value.nil?
|
132
132
|
|
133
133
|
set(result, k, value)
|
data/lib/rordash/version.rb
CHANGED
data/lib/rordash.rb
CHANGED
@@ -10,9 +10,15 @@ file_util
|
|
10
10
|
url_util
|
11
11
|
object_util
|
12
12
|
numeric_util
|
13
|
+
chain
|
13
14
|
].each do |filename|
|
14
15
|
require File.expand_path("../rordash/#{filename}", Pathname.new(__FILE__).realpath)
|
15
16
|
end
|
16
17
|
|
17
18
|
module Rordash
|
18
|
-
|
19
|
+
class << self
|
20
|
+
def chain(value)
|
21
|
+
Chain.new(value.dup)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rordash
|
4
|
+
RSpec.describe Chain do
|
5
|
+
let(:instance) { described_class.new(value) }
|
6
|
+
|
7
|
+
describe "#to_h" do
|
8
|
+
let(:value) { JSON.dump(a: 1) }
|
9
|
+
|
10
|
+
it "chains underlying hash util method" do
|
11
|
+
expect(instance.to_h.value).to eql(a: 1)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#deep_compact" do
|
16
|
+
let(:value) { { a: { b: { c: nil } }, d: 1, e: [], f: [1, 2, nil, 3, nil] } }
|
17
|
+
|
18
|
+
it "chains underlying hash util method" do
|
19
|
+
expect(
|
20
|
+
instance.deep_compact.value
|
21
|
+
).to eql(e: [], f: [1, 2, 3])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/rordash_spec.rb
CHANGED
@@ -4,4 +4,14 @@ RSpec.describe Rordash do
|
|
4
4
|
it "has a version number" do
|
5
5
|
expect(Rordash::VERSION).not_to be_nil
|
6
6
|
end
|
7
|
+
|
8
|
+
describe '.chain' do
|
9
|
+
describe "#to_h" do
|
10
|
+
let(:value) { JSON.dump(a: 1) }
|
11
|
+
|
12
|
+
it "chains underlying hash util method" do
|
13
|
+
expect(described_class.chain(JSON.dump(a: 1)).to_h.value).to eql(a: 1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rordash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Desmond O'Leary
|
@@ -257,6 +257,7 @@ files:
|
|
257
257
|
- bin/setup
|
258
258
|
- dev/setup.rb
|
259
259
|
- lib/rordash.rb
|
260
|
+
- lib/rordash/chain.rb
|
260
261
|
- lib/rordash/debug_util.rb
|
261
262
|
- lib/rordash/file_util.rb
|
262
263
|
- lib/rordash/hash_util.rb
|
@@ -273,6 +274,7 @@ files:
|
|
273
274
|
- spec/fixtures/files/sample.json
|
274
275
|
- spec/fixtures/sample.csv
|
275
276
|
- spec/fixtures/sample.json
|
277
|
+
- spec/rordash/chain_spec.rb
|
276
278
|
- spec/rordash/debug_util_spec.rb
|
277
279
|
- spec/rordash/file_util_spec.rb
|
278
280
|
- spec/rordash/hash_util_spec.rb
|
@@ -315,6 +317,7 @@ test_files:
|
|
315
317
|
- spec/fixtures/files/sample.json
|
316
318
|
- spec/fixtures/sample.csv
|
317
319
|
- spec/fixtures/sample.json
|
320
|
+
- spec/rordash/chain_spec.rb
|
318
321
|
- spec/rordash/debug_util_spec.rb
|
319
322
|
- spec/rordash/file_util_spec.rb
|
320
323
|
- spec/rordash/hash_util_spec.rb
|