hash_map 0.5.2 → 0.6.0

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
  SHA1:
3
- metadata.gz: c0a6a8bd9cc92001e37afa91b8f81bb7227cde14
4
- data.tar.gz: 807954453bc2c7364a174597dda3bcc5d00a409d
3
+ metadata.gz: ef09a5a9361c24f1699f79e236d3d0b08da994c3
4
+ data.tar.gz: eae0a632e2c1ba49782a5f22925bf86461e4e491
5
5
  SHA512:
6
- metadata.gz: 7ef4aaabb76f1ea29a981bdfe05ed7fc4c327b08eb578557b2b549f44c55889e711b5e0788f10d59ec628c2fd9f80c9e085a6b9cf31af09001cca72fed03c242
7
- data.tar.gz: f322f64a2fbd439e47d8cb076a81dc06c807e47a5d598482445881bf34eeb072814b9fc6e70dd8ff4fb99d2e7e1c256477570e04397034186759d86d496f2fe6
6
+ metadata.gz: 808a0077718557db480351584190c2745f68dfb781f108bae18bf1e60c408f5722de02f63ed3fddd2b068391056d7b6a9baf2c330b48864ce3f01ce110801a12
7
+ data.tar.gz: f1dba0212065c7d2abd947c3ff78589dbe7255fdce9028abac8c62376bb84695092714887ad5e38cc35a43d23113284ee18db26f203bb4cbe7225b4cae8a0a78
@@ -28,7 +28,6 @@ install:
28
28
  - bundle install --retry=3
29
29
  script:
30
30
  - bundle exec rspec
31
- - bundle exec rubocop
32
31
  addons:
33
32
  code_climate:
34
33
  repo_token: a11b66bfbb1acdf220d5cb317b2e945a986fd85adebe29a76d411ad6d74ec31f
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hash_map.gemspec
4
4
  gemspec
5
+
5
6
  group :development, :test do
6
7
  gem 'simplecov', require: false
7
8
  gem 'rubocop', '~> 0.37.2', require: false unless RUBY_VERSION =~ /^1.8/
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
 
@@ -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 'activesupport', '~> 4.2'
25
+ spec.add_dependency "fusu", "~> 0.2"
26
26
  end
@@ -1,5 +1,5 @@
1
1
  require 'hash_map/version'
2
- require 'active_support/all'
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'
@@ -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
 
@@ -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!(opts.except(:from))
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
@@ -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
- new_hash.deep_merge! build_keys(struc[:key], value)
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
 
@@ -1,6 +1,6 @@
1
1
  module HashMap
2
2
  BlankToNil = lambda do |v|
3
- v.blank? ? nil : v
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
- output.deep_transform_keys{ |k| k.underscore.to_sym }
13
+ Fusu::Hash.deep_transform_keys(output){ |k| Fusu::String.underscore(k).to_sym }
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module HashMap
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
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.5.2
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-08-01 00:00:00.000000000 Z
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: activesupport
56
+ name: fusu
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.2'
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: '4.2'
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.4.5
118
+ rubygems_version: 2.2.3
121
119
  signing_key:
122
120
  specification_version: 4
123
121
  summary: Library to map easily hashes.
@@ -1,9 +0,0 @@
1
- class Hash
2
- # Return the hash with the structure from the Mapper
3
- #
4
- # hash = { user: { name: 'John', surname: 'Doe' } }
5
- # hash.hash_map_with(UserMapper)
6
- def hash_map_with(mapper)
7
- mapper.call(self)
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class String
2
- # Return the string with the structure from the Mapper
3
- #
4
- # api_response = "{\"user\":{\"name\":\"John\",\"surname\":\"Doe\"}}"
5
- # api_response.hash_map_with(UserMapper)
6
- def hash_map_with(mapper)
7
- mapper.call(self)
8
- end
9
- end