hash_map 0.5.2 → 0.6.0
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/.travis.yml +0 -1
- data/Gemfile +1 -0
- data/README.md +1 -26
- data/hash_map.gemspec +1 -1
- data/lib/hash_map.rb +1 -4
- data/lib/hash_map/base.rb +7 -1
- data/lib/hash_map/dsl.rb +3 -3
- data/lib/hash_map/mapper.rb +5 -5
- data/lib/hash_map/plugins.rb +2 -2
- data/lib/hash_map/version.rb +1 -1
- metadata +6 -8
- data/lib/hash_map/core_ext/hash.rb +0 -9
- data/lib/hash_map/core_ext/string.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef09a5a9361c24f1699f79e236d3d0b08da994c3
|
4
|
+
data.tar.gz: eae0a632e2c1ba49782a5f22925bf86461e4e491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808a0077718557db480351584190c2745f68dfb781f108bae18bf1e60c408f5722de02f63ed3fddd2b068391056d7b6a9baf2c330b48864ce3f01ce110801a12
|
7
|
+
data.tar.gz: f1dba0212065c7d2abd947c3ff78589dbe7255fdce9028abac8c62376bb84695092714887ad5e38cc35a43d23113284ee18db26f203bb4cbe7225b4cae8a0a78
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -93,7 +93,7 @@ ProfileMapper.map(original)
|
|
93
93
|
}
|
94
94
|
```
|
95
95
|
**IMPORTANT:**
|
96
|
-
- The **output** is a **HashWithIndifferentAccess** you can access the values with strings or symbols.
|
96
|
+
- The **output** is a **Fusu::HashWithIndifferentAccess** you can access the values with strings or symbols.
|
97
97
|
- The input is transformed as well, that's why you do not need to use strings.
|
98
98
|
|
99
99
|
Enjoy!
|
@@ -376,31 +376,6 @@ json = %Q[{"user":{"name":"John","surname":"Doe"}}]
|
|
376
376
|
UserMapper.map(json)
|
377
377
|
# => {"name"=>"John", "surname"=>"Doe"}
|
378
378
|
```
|
379
|
-
### Core Extensions
|
380
|
-
|
381
|
-
#### String
|
382
|
-
```ruby
|
383
|
-
class UserMapper < HashMap::Base
|
384
|
-
from_child :user do
|
385
|
-
properties :name, :surname
|
386
|
-
end
|
387
|
-
end
|
388
|
-
json = %Q[{"user":{"name":"John","surname":"Doe"}}]
|
389
|
-
json.hash_map_with(UserMapper)
|
390
|
-
# => {"name"=>"John", "surname"=>"Doe"}
|
391
|
-
```
|
392
|
-
#### Hash
|
393
|
-
|
394
|
-
```ruby
|
395
|
-
class UserMapper < HashMap::Base
|
396
|
-
from_child :user do
|
397
|
-
properties :name, :surname
|
398
|
-
end
|
399
|
-
end
|
400
|
-
hash = { user: { name: 'John', surname: 'Doe' } }
|
401
|
-
hash.hash_map_with(UserMapper)
|
402
|
-
# => {"name"=>"John", "surname"=>"Doe"}
|
403
|
-
```
|
404
379
|
|
405
380
|
### Testing
|
406
381
|
|
data/hash_map.gemspec
CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec"
|
25
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency "fusu", "~> 0.2"
|
26
26
|
end
|
data/lib/hash_map.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'hash_map/version'
|
2
|
-
require '
|
2
|
+
require 'fusu'
|
3
3
|
module HashMap
|
4
4
|
def self.root
|
5
5
|
File.expand_path '../..', __FILE__
|
@@ -10,6 +10,3 @@ require 'hash_map/mapper'
|
|
10
10
|
require 'hash_map/base'
|
11
11
|
require 'hash_map/json_adapter'
|
12
12
|
require 'hash_map/plugins'
|
13
|
-
|
14
|
-
require 'hash_map/core_ext/hash'
|
15
|
-
require 'hash_map/core_ext/string'
|
data/lib/hash_map/base.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module HashMap
|
2
2
|
class Base
|
3
|
-
delegate :[], to: :output
|
4
3
|
|
5
4
|
def self.map(*args)
|
6
5
|
new(*args).output
|
@@ -30,6 +29,13 @@ module HashMap
|
|
30
29
|
end
|
31
30
|
alias_method :to_h, :output
|
32
31
|
alias_method :to_hash, :output
|
32
|
+
alias_method :call, :output
|
33
|
+
alias_method :execute, :output
|
34
|
+
|
35
|
+
|
36
|
+
def [](key)
|
37
|
+
output[key]
|
38
|
+
end
|
33
39
|
|
34
40
|
private
|
35
41
|
|
data/lib/hash_map/dsl.rb
CHANGED
@@ -54,7 +54,7 @@ module HashMap
|
|
54
54
|
new_hash = {}.tap { |h| h[:key] = single_to_ary(key) }
|
55
55
|
new_hash[:proc] = block if block
|
56
56
|
new_hash[:from] = generate_from(new_hash, opts)
|
57
|
-
attributes << new_hash.merge!(
|
57
|
+
attributes << new_hash.merge!(Fusu::Hash.except(opts, :from))
|
58
58
|
new_hash
|
59
59
|
end
|
60
60
|
|
@@ -81,7 +81,7 @@ module HashMap
|
|
81
81
|
options = args.last.is_a?(::Hash) ? args.pop : {}
|
82
82
|
key = args
|
83
83
|
flat = _nested(key, options, &block)
|
84
|
-
keys = Array.wrap(key)
|
84
|
+
keys = Fusu::Array.wrap(key)
|
85
85
|
flat.each do |attr|
|
86
86
|
keys.reverse.each do |k|
|
87
87
|
attr[:from].unshift(k)
|
@@ -116,7 +116,7 @@ module HashMap
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def single_to_ary(elem)
|
119
|
-
Array.wrap(elem)
|
119
|
+
Fusu::Array.wrap(elem)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
data/lib/hash_map/mapper.rb
CHANGED
@@ -2,15 +2,15 @@ module HashMap
|
|
2
2
|
class Mapper
|
3
3
|
attr_reader :original, :hash_map
|
4
4
|
def initialize(original, hash_map)
|
5
|
-
@original = HashWithIndifferentAccess.new(original)
|
5
|
+
@original = Fusu::HashWithIndifferentAccess.new(original)
|
6
6
|
@hash_map = hash_map
|
7
7
|
end
|
8
8
|
|
9
9
|
def output
|
10
|
-
new_hash = HashWithIndifferentAccess.new
|
10
|
+
new_hash = Fusu::HashWithIndifferentAccess.new
|
11
11
|
hash_map.class.attributes.each do |struc|
|
12
12
|
value = get_value(struc)
|
13
|
-
|
13
|
+
Fusu::Hash.deep_merge!(new_hash, build_keys(struc[:key], value))
|
14
14
|
end
|
15
15
|
new_hash
|
16
16
|
end
|
@@ -42,7 +42,7 @@ module HashMap
|
|
42
42
|
|
43
43
|
def map_collection(struct)
|
44
44
|
value = get_value_from_key(struct)
|
45
|
-
value = Array.wrap(value)
|
45
|
+
value = Fusu::Array.wrap(value)
|
46
46
|
value.map { |elem| struct[:mapper].call(elem) }
|
47
47
|
end
|
48
48
|
|
@@ -67,7 +67,7 @@ module HashMap
|
|
67
67
|
|
68
68
|
def build_keys(ary, value)
|
69
69
|
ary.reverse.inject(value) do |a, n|
|
70
|
-
HashWithIndifferentAccess.new(n => a)
|
70
|
+
Fusu::HashWithIndifferentAccess.new(n => a)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
data/lib/hash_map/plugins.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module HashMap
|
2
2
|
BlankToNil = lambda do |v|
|
3
|
-
|
3
|
+
Fusu.blank?(v) ? nil : v
|
4
4
|
end
|
5
5
|
|
6
6
|
StringToBoolean = lambda do |v|
|
@@ -10,6 +10,6 @@ module HashMap
|
|
10
10
|
end
|
11
11
|
|
12
12
|
UnderscoreKeys = lambda do |output|
|
13
|
-
|
13
|
+
Fusu::Hash.deep_transform_keys(output){ |k| Fusu::String.underscore(k).to_sym }
|
14
14
|
end
|
15
15
|
end
|
data/lib/hash_map/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_map
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artur Pañach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: fusu
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.2'
|
69
69
|
description: Nice DSL to convert hash structure to different one.
|
70
70
|
email:
|
71
71
|
- arturictus@gmail.com
|
@@ -89,8 +89,6 @@ files:
|
|
89
89
|
- hash_map.gemspec
|
90
90
|
- lib/hash_map.rb
|
91
91
|
- lib/hash_map/base.rb
|
92
|
-
- lib/hash_map/core_ext/hash.rb
|
93
|
-
- lib/hash_map/core_ext/string.rb
|
94
92
|
- lib/hash_map/dsl.rb
|
95
93
|
- lib/hash_map/json_adapter.rb
|
96
94
|
- lib/hash_map/mapper.rb
|
@@ -117,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
115
|
version: '0'
|
118
116
|
requirements: []
|
119
117
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.2.3
|
121
119
|
signing_key:
|
122
120
|
specification_version: 4
|
123
121
|
summary: Library to map easily hashes.
|