lite-ruby 1.0.24 → 1.0.25

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ab807277ec08dcba4afc47272746223b154fbfc66dcb27d32594f808d26339e
4
- data.tar.gz: 9b06a59c0122c2b97285193d11476bade1fc50e69f9f414a06dcdf84fc65a637
3
+ metadata.gz: d4d01bb77cf20881775c7cecdee1ba3eeda550694a37dd5431e1efbca7b4a49b
4
+ data.tar.gz: e4f77ca66978020ab63fc01749946bfd027a5ddb04dabbd97dd1baaffed73d16
5
5
  SHA512:
6
- metadata.gz: a795dd8081eaa3172294a1c76f647c0008ebc81f39d70e7785aa9942cd19b542c10513ce04ddecc3b01b3ab3d65ac492307d8e96cd0574239fb4d29a91039284
7
- data.tar.gz: 1fff8bfcab78ccf1c0b0f63d3761a4f8c0b08fa61cd4c24964a664fb393f3ea7d50487e21567bc8a0b55bea71d02c1c97c02ce6f75e27cc6713d81500714b880
6
+ metadata.gz: 90d2b0f6662767b3650ed5b7230d45e17ccced7d63306998cc4b513ae632b1a9fb59b56c4543cfb16f64501e0a7da49bb7805cb57dc153619d32d511dde35796
7
+ data.tar.gz: a176f671ca037bb02bfc010f4e6284341f0586a30e038698c9f447a464bd850b2361f09c7a2948eeac426398d290f7451afa5cb54b979eacc429dd826e3b65dc
@@ -8,6 +8,8 @@ AllCops:
8
8
  Layout/EmptyLinesAroundBlockBody:
9
9
  Exclude:
10
10
  - 'spec/**/**/*'
11
+ Layout/EmptyLinesAroundAttributeAccessor:
12
+ Enabled: true
11
13
  Layout/EmptyLinesAroundClassBody:
12
14
  EnforcedStyle: empty_lines_except_namespace
13
15
  Layout/EmptyLinesAroundModuleBody:
@@ -49,3 +51,5 @@ Style/HashTransformValues:
49
51
  Enabled: false
50
52
  Style/PerlBackrefs:
51
53
  Enabled: false
54
+ Style/SlicingWithRange:
55
+ Enabled: false
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.25] - 2020-05-20
10
+ ### Added
11
+ - Added Hash => `to_open_struct`
12
+ - Added Hash => `to_struct`
13
+ - Added OpenStruct => `to_hash`
14
+ - Added OpenStruct => `to_json(table: true)`
15
+
9
16
  ## [1.0.24] - 2020-05-07
10
17
  ### Added
11
18
  - Added Object => `salvage_try`
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.24)
4
+ lite-ruby (1.0.25)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (6.0.3)
10
- actionview (= 6.0.3)
11
- activesupport (= 6.0.3)
9
+ actionpack (6.0.3.1)
10
+ actionview (= 6.0.3.1)
11
+ activesupport (= 6.0.3.1)
12
12
  rack (~> 2.0, >= 2.0.8)
13
13
  rack-test (>= 0.6.3)
14
14
  rails-dom-testing (~> 2.0)
15
15
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
- actionview (6.0.3)
17
- activesupport (= 6.0.3)
16
+ actionview (6.0.3.1)
17
+ activesupport (= 6.0.3.1)
18
18
  builder (~> 3.1)
19
19
  erubi (~> 1.4)
20
20
  rails-dom-testing (~> 2.0)
21
21
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
- activesupport (6.0.3)
22
+ activesupport (6.0.3.1)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 0.7, < 2)
25
25
  minitest (~> 5.1)
@@ -40,13 +40,12 @@ GEM
40
40
  railties (>= 3.0.0)
41
41
  i18n (1.8.2)
42
42
  concurrent-ruby (~> 1.0)
43
- jaro_winkler (1.5.4)
44
43
  loofah (2.5.0)
45
44
  crass (~> 1.0.2)
46
45
  nokogiri (>= 1.5.9)
47
46
  method_source (1.0.0)
48
47
  mini_portile2 (2.4.0)
49
- minitest (5.14.0)
48
+ minitest (5.14.1)
50
49
  nokogiri (1.10.9)
51
50
  mini_portile2 (~> 2.4.0)
52
51
  parallel (1.19.1)
@@ -60,9 +59,9 @@ GEM
60
59
  nokogiri (>= 1.6)
61
60
  rails-html-sanitizer (1.3.0)
62
61
  loofah (~> 2.3)
63
- railties (6.0.3)
64
- actionpack (= 6.0.3)
65
- activesupport (= 6.0.3)
62
+ railties (6.0.3.1)
63
+ actionpack (= 6.0.3.1)
64
+ activesupport (= 6.0.3.1)
66
65
  method_source
67
66
  rake (>= 0.8.7)
68
67
  thor (>= 0.20.3, < 2.0)
@@ -75,15 +74,14 @@ GEM
75
74
  rspec-mocks (~> 3.9.0)
76
75
  rspec-core (3.9.2)
77
76
  rspec-support (~> 3.9.3)
78
- rspec-expectations (3.9.1)
77
+ rspec-expectations (3.9.2)
79
78
  diff-lcs (>= 1.2.0, < 2.0)
80
79
  rspec-support (~> 3.9.0)
81
80
  rspec-mocks (3.9.1)
82
81
  diff-lcs (>= 1.2.0, < 2.0)
83
82
  rspec-support (~> 3.9.0)
84
83
  rspec-support (3.9.3)
85
- rubocop (0.82.0)
86
- jaro_winkler (~> 1.5.1)
84
+ rubocop (0.83.0)
87
85
  parallel (~> 1.10)
88
86
  parser (>= 2.7.0.1)
89
87
  rainbow (>= 2.2.2, < 4.0)
@@ -425,12 +425,20 @@ Symbolize and underscore hash keys.
425
425
  { 'firstName' => 'foo', 'last Name' => 'test' }.symbolize_and_underscore_keys #=> { first_name: 'foo', last_name: 'test' }
426
426
  ```
427
427
 
428
- `to_object` aka `to_o`
428
+ `to_open_struct` aka `to_object` aka `to_o`
429
429
  ------
430
- Converts an object to have an object like API.
430
+ Converts a hash to an open struct to have an object like API.
431
431
 
432
432
  ```ruby
433
- { foo: { bar: true } }.to_object.foo.bar #=> true
433
+ { foo: { bar: true } }.to_open_struct.foo.bar #=> true
434
+ ```
435
+
436
+ `to_struct`
437
+ ------
438
+ Converts a hash to a struct to have an object like API.
439
+
440
+ ```ruby
441
+ { foo: { bar: true } }.to_struct.foo #=> { bar: true }
434
442
  ```
435
443
 
436
444
  `update_each`
@@ -31,7 +31,7 @@ person['name'] = 'tim'
31
31
 
32
32
  `attributes`
33
33
  ------
34
- Returns the key values of the assigned struct.
34
+ Returns the key values as a hash of the assigned struct.
35
35
 
36
36
  ```ruby
37
37
  person = OpenStruct.new(name: 'bob', age: 60)
@@ -49,3 +49,25 @@ person = OpenStruct.new(name: 'bob', age: 60)
49
49
  person.replace(name: 'tom', age: 28)
50
50
  preson.name #=> 'tom'
51
51
  ```
52
+
53
+ `to_hash` aka `to_h`
54
+ ------
55
+ Returns the key values as a hash of the assigned struct.
56
+
57
+ ```ruby
58
+ person = OpenStruct.new(name: 'bob', age: 60)
59
+
60
+ person.to_hash #=> { table: { name: 'bob', age: 60 } }
61
+ person.to_hash(table: false) #=> { name: 'bob', age: 60 }
62
+ ```
63
+
64
+ `to_json` aka `as_json`
65
+ ------
66
+ Returns the key values as Json of the assigned struct.
67
+
68
+ ```ruby
69
+ person = OpenStruct.new(name: 'bob', age: 60)
70
+
71
+ person.to_json #=> { table: { name: 'bob', age: 60 } }
72
+ person.to_json(table: false) #=> { name: 'bob', age: 60 }
73
+ ```
@@ -440,11 +440,17 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
440
440
  replace(symbolize_and_underscore_keys)
441
441
  end
442
442
 
443
- def to_object
443
+ def to_open_struct
444
444
  JSON.parse(to_json, object_class: OpenStruct)
445
445
  end
446
446
 
447
- alias to_o to_object
447
+ alias to_object to_open_struct
448
+ alias to_o to_open_struct
449
+
450
+ def to_struct
451
+ struct = Struct.new(*keys)
452
+ struct.new(*values)
453
+ end
448
454
 
449
455
  def update_each
450
456
  replace(each_with_object({}) { |(key, val), hash| hash.update(yield(key, val)) })
@@ -33,12 +33,26 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
33
33
  end
34
34
 
35
35
  def attributes
36
- each_pair.with_object({}) { |(key, val), hash| hash[key] = val }
36
+ @table
37
37
  end
38
38
 
39
39
  def replace(args)
40
40
  args.each_pair { |key, val| send("#{key}=", val) }
41
41
  end
42
42
 
43
+ def to_hash(table: true)
44
+ return attributes unless table
45
+
46
+ { table: attributes }
47
+ end
48
+
49
+ alias to_h to_hash
50
+
51
+ def to_json(table: true)
52
+ to_hash(table: table).to_json
53
+ end
54
+
55
+ alias as_json to_json
56
+
43
57
  end
44
58
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.24'
6
+ VERSION ||= '1.0.25'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.24
4
+ version: 1.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  - !ruby/object:Gem::Version
203
203
  version: '0'
204
204
  requirements: []
205
- rubygems_version: 3.1.2
205
+ rubygems_version: 3.1.3
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: Collection of useful Ruby methods for its primitive classes