rordash 0.1.1 → 0.1.3

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: 22a81aeca1fc92e70e311336496eb836394cc4d653cb1fccf729777ebc58bc5e
4
- data.tar.gz: 9d339ce6af83f826f8399e89dc865ae73a2186b9dbd4f910451bd5cf1765df3b
3
+ metadata.gz: 807275b91ea62a1bdf32c0864db14524994c0dd63f85dfcbbc87160237902082
4
+ data.tar.gz: 7fe354efaed0db6eda07ff702bf7184d6d1c4096903b2bc9086ac28dc5042606
5
5
  SHA512:
6
- metadata.gz: c7588b86ce3c215420b672fdc5da4e089e7697ff0a8bbe0083a4373bb78189096c6000dcb9aa98a3415eca79838fc21fa568592e2d67d9768fdbc700cd5b5a05
7
- data.tar.gz: 27d4bc53bca5436b6d6d0d893dffbf79038f73687d82380d2a57d7c6d9ffa8dccebca530b2b0644abbcdb9a48070d144eaf602d6c49f538ea7cb524f8d013eb2
6
+ metadata.gz: 2e23fbd54bcacfd95fa4509ef400741157a78926050e4b461663bcd095a1e6160dda2e600b2712489d93268b9ca7a99c382656cc88da5571eb69f4b3e7d601ed
7
+ data.tar.gz: 6acff57a7e8834b5714c13a410ed03e95122878e17b5a6ca96c04018d84d567be04b44c9d17d1ca5c7fbd801fdc1f8dc3905df2abea14e4d51a8f1ac18fc2b94
data/dev/setup.rb CHANGED
@@ -1,25 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Sets up environment for running specs and via irb e.g. `$ irb -r ./dev/setup`
4
- require 'delegate'
5
4
  require "pathname"
6
-
7
5
  require 'rspec/core'
8
- require 'colorize'
9
- require 'stackprof'
10
-
11
- require 'active_support/core_ext/hash/keys'
12
- require 'active_support/core_ext/module/delegation'
13
- require 'active_support/core_ext/object/blank'
14
- require 'active_support/core_ext/enumerable'
15
- require 'mime-types'
16
- require 'faker'
17
- require 'oj'
18
- require 'rudash'
19
- require 'dottie'
20
- require 'addressable'
21
- require 'rack/utils'
22
- require 'measured'
23
6
 
24
7
  %w[../../lib/rordash ../../spec/spec_helper].each do |rel_path|
25
8
  require File.expand_path(rel_path, Pathname.new(__FILE__).realpath)
@@ -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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rordash
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/rordash.rb CHANGED
@@ -1,5 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'delegate'
4
+ require 'colorize'
5
+ require 'stackprof'
6
+
7
+ require 'active_support/core_ext/hash/keys'
8
+ require 'active_support/core_ext/module/delegation'
9
+ require 'active_support/core_ext/object/blank'
10
+ require 'active_support/core_ext/enumerable'
11
+ require 'active_support/hash_with_indifferent_access'
12
+ require 'mime-types'
13
+ require 'faker'
14
+ require 'oj'
15
+ require 'rudash'
16
+ require 'dottie'
17
+ require 'addressable'
18
+ require 'rack/utils'
19
+ require 'measured'
20
+ require 'rordash'
21
+
3
22
  %w[
4
23
  version
5
24
  debug_util
@@ -10,9 +29,15 @@ file_util
10
29
  url_util
11
30
  object_util
12
31
  numeric_util
32
+ chain
13
33
  ].each do |filename|
14
34
  require File.expand_path("../rordash/#{filename}", Pathname.new(__FILE__).realpath)
15
35
  end
16
36
 
17
37
  module Rordash
18
- ; end
38
+ class << self
39
+ def chain(value)
40
+ Chain.new(value.dup)
41
+ end
42
+ end
43
+ 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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rordash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Desmond O'Leary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-27 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stackprof
@@ -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
@@ -305,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
307
  - !ruby/object:Gem::Version
306
308
  version: '0'
307
309
  requirements: []
308
- rubygems_version: 3.1.6
310
+ rubygems_version: 3.4.8
309
311
  signing_key:
310
312
  specification_version: 4
311
313
  summary: Lodash inspired utilities
@@ -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