hash_map 0.3.6 → 0.3.7

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: 1b34bf9da8846a7016da845a50f12f5b56906135
4
- data.tar.gz: 90939f2f29f4fe79f824545b14d04a0c1934d9b7
3
+ metadata.gz: e04f1953cd197e037e9a3a3b0c2381d0ea878062
4
+ data.tar.gz: 6b769f5fce5ca758b17eac83a7e5da12d2e81c77
5
5
  SHA512:
6
- metadata.gz: 1dedeaef38d7745b11437abee4bc3ef0a266f924f453449ae367142a084a07feb607e14e7bf75b0c036a036793de3ed0f93f0bd7bc5c8f62f68ab0cd62d8645b
7
- data.tar.gz: 94c97df1807f5e9ce07993be731bd8256b095a02c9ea9c41fe76e0527499d7ac230decc978fb2ef6d6326c9afce68ac255b5411443c21d9f9bb0585c21cfdf2c
6
+ metadata.gz: 5fa67a56292f6e9368780f024b8dda1c3c93d58f357f6acf8e1c2e5824ec15486e38189ad511ae96596fa57f04e06577ea129065bd0b20301cae5e07baf5925a
7
+ data.tar.gz: 6dc6282c26cd48a0a9940a85eefc330aa2ac38766a255ba70c69d0140fdd143df95cdf8b0bf45ccff552b234893a2b05eb029a3fc84afe4e804414f26e726852
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: oKDl7BmU0ePa4AS6Yo8dJuBdjXdIFW5nv
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ inherit_from: ./.rubocop_todo.yml
2
+
3
+ AllCops:
4
+ Include:
5
+ - '**/Rakefile'
6
+ - '**/config.ru'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'db/**/*'
10
+ - 'config/**/*'
11
+ - 'script/**/*'
12
+ - 'puppet/**/*'
13
+ - 'tmp/**/*'
14
+ - 'log/**/*'
15
+ - 'vendor/bundle/**/*'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,177 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-04-26 22:01:05 +0200 using RuboCop version 0.37.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: IgnoreEmptyBlocks.
12
+ Lint/UnusedBlockArgument:
13
+ Exclude:
14
+ - 'spec/examples/blocks_spec.rb'
15
+ - 'spec/hash_map/dsl_spec.rb'
16
+ - 'spec/hash_map/mapper_spec.rb'
17
+
18
+ # Offense count: 28
19
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
20
+ # URISchemes: http, https
21
+ Metrics/LineLength:
22
+ Max: 238
23
+
24
+ # Offense count: 1
25
+ # Configuration parameters: CountComments.
26
+ Metrics/ModuleLength:
27
+ Max: 123
28
+
29
+ # Offense count: 1
30
+ # Cop supports --auto-correct.
31
+ # Configuration parameters: MaxKeyValuePairs.
32
+ Performance/RedundantMerge:
33
+ Exclude:
34
+ - 'lib/hash_map/dsl.rb'
35
+
36
+ # Offense count: 2
37
+ # Cop supports --auto-correct.
38
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
39
+ # SupportedStyles: prefer_alias, prefer_alias_method
40
+ Style/Alias:
41
+ Exclude:
42
+ - 'lib/hash_map/base.rb'
43
+
44
+ # Offense count: 8
45
+ Style/Documentation:
46
+ Exclude:
47
+ - 'spec/**/*'
48
+ - 'test/**/*'
49
+ - 'lib/hash_map.rb'
50
+ - 'lib/hash_map/base.rb'
51
+ - 'lib/hash_map/core_ext/hash.rb'
52
+ - 'lib/hash_map/core_ext/string.rb'
53
+ - 'lib/hash_map/dsl.rb'
54
+ - 'lib/hash_map/json_adapter.rb'
55
+ - 'lib/hash_map/mapper.rb'
56
+
57
+ # Offense count: 1
58
+ # Cop supports --auto-correct.
59
+ Style/EmptyLines:
60
+ Exclude:
61
+ - 'spec/examples/collections_spec.rb'
62
+
63
+ # Offense count: 1
64
+ # Cop supports --auto-correct.
65
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
66
+ # SupportedStyles: empty_lines, no_empty_lines
67
+ Style/EmptyLinesAroundClassBody:
68
+ Exclude:
69
+ - 'spec/examples/blocks_spec.rb'
70
+
71
+ # Offense count: 4
72
+ # Cop supports --auto-correct.
73
+ # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
74
+ Style/ExtraSpacing:
75
+ Exclude:
76
+ - 'spec/hash_map/base_spec.rb'
77
+ - 'spec/hash_map/mapper_spec.rb'
78
+
79
+ # Offense count: 1
80
+ # Cop supports --auto-correct.
81
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
82
+ # SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
83
+ Style/HashSyntax:
84
+ Enabled: false
85
+
86
+ # Offense count: 1
87
+ # Cop supports --auto-correct.
88
+ Style/MutableConstant:
89
+ Exclude:
90
+ - 'lib/hash_map/version.rb'
91
+
92
+ # Offense count: 2
93
+ # Cop supports --auto-correct.
94
+ Style/NumericLiterals:
95
+ MinDigits: 6
96
+
97
+ # Offense count: 2
98
+ # Cop supports --auto-correct.
99
+ # Configuration parameters: PreferredDelimiters.
100
+ Style/PercentLiteralDelimiters:
101
+ Exclude:
102
+ - 'hash_map.gemspec'
103
+
104
+ # Offense count: 3
105
+ # Cop supports --auto-correct.
106
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
107
+ # SupportedStyles: only_raise, only_fail, semantic
108
+ Style/SignalException:
109
+ Exclude:
110
+ - 'lib/hash_map/dsl.rb'
111
+ - 'lib/hash_map/json_adapter.rb'
112
+
113
+ # Offense count: 4
114
+ # Cop supports --auto-correct.
115
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
116
+ # SupportedStyles: space, no_space
117
+ Style/SpaceBeforeBlockBraces:
118
+ Enabled: false
119
+
120
+ # Offense count: 4
121
+ # Cop supports --auto-correct.
122
+ # Configuration parameters: AllowForAlignment.
123
+ Style/SpaceBeforeFirstArg:
124
+ Exclude:
125
+ - 'spec/hash_map/base_spec.rb'
126
+ - 'spec/hash_map/mapper_spec.rb'
127
+
128
+ # Offense count: 11
129
+ # Cop supports --auto-correct.
130
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
131
+ # SupportedStyles: space, no_space
132
+ Style/SpaceInsideBlockBraces:
133
+ Enabled: false
134
+
135
+ # Offense count: 2
136
+ # Cop supports --auto-correct.
137
+ Style/SpaceInsideBrackets:
138
+ Exclude:
139
+ - 'spec/examples/collections_spec.rb'
140
+
141
+ # Offense count: 3
142
+ # Cop supports --auto-correct.
143
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
144
+ # SupportedStyles: space, no_space
145
+ Style/SpaceInsideHashLiteralBraces:
146
+ Enabled: false
147
+
148
+ # Offense count: 21
149
+ # Cop supports --auto-correct.
150
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
151
+ # SupportedStyles: single_quotes, double_quotes
152
+ Style/StringLiterals:
153
+ Enabled: false
154
+
155
+ # Offense count: 1
156
+ # Cop supports --auto-correct.
157
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
158
+ # SupportedStyles: final_newline, final_blank_line
159
+ Style/TrailingBlankLines:
160
+ Exclude:
161
+ - 'lib/hash_map.rb'
162
+
163
+ # Offense count: 3
164
+ # Cop supports --auto-correct.
165
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
166
+ # SupportedStyles: comma, consistent_comma, no_comma
167
+ Style/TrailingCommaInLiteral:
168
+ Exclude:
169
+ - 'spec/examples/defaults_spec.rb'
170
+ - 'spec/hash_map/dsl_spec.rb'
171
+ - 'spec/hash_map/mapper_spec.rb'
172
+
173
+ # Offense count: 2
174
+ # Cop supports --auto-correct.
175
+ Style/UnneededPercentQ:
176
+ Exclude:
177
+ - 'hash_map.gemspec'
data/.travis.yml CHANGED
@@ -1,4 +1,34 @@
1
+ sudo: false
2
+ cache: bundler
1
3
  language: ruby
2
4
  rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1
3
8
  - 2.1.6
4
- before_install: gem install bundler -v 1.10.4
9
+ - 2.2
10
+ - 2.3.0
11
+ - ruby-head
12
+ - jruby-19mode
13
+ - jruby-9.0.1.0
14
+ - rbx-3
15
+ env:
16
+ # this doesn't do anything for MRI or RBX, but it doesn't hurt them either
17
+ # for JRuby, it enables us to get more accurate coverage data
18
+ - JRUBY_OPTS="--debug"
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+ - rvm: rbx-3
23
+ - rvm: jruby-19mode
24
+ - rvm: jruby-9.0.1.0
25
+ fast_finish: true
26
+ before_install: gem update --remote bundler
27
+ install:
28
+ - bundle install --retry=3
29
+ script:
30
+ - bundle exec rspec
31
+ - bundle exec rubocop
32
+ addons:
33
+ code_climate:
34
+ repo_token: a11b66bfbb1acdf220d5cb317b2e945a986fd85adebe29a76d411ad6d74ec31f
data/Gemfile CHANGED
@@ -2,4 +2,13 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in hash_map.gemspec
4
4
  gemspec
5
- gem 'pry'
5
+ group :development, :test do
6
+ gem 'simplecov', require: false
7
+ gem 'rubocop', '~> 0.37.2', require: false unless RUBY_VERSION =~ /^1.8/
8
+ gem 'coveralls', require: false
9
+
10
+ platforms :mri, :mingw do
11
+ gem 'pry', require: false
12
+ gem 'pry-coolline', require: false
13
+ end
14
+ end
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # HashMap
2
- [ ![Codeship Status for arturictus/hash_map](https://codeship.com/projects/5900adb0-7452-0133-84a1-52f3970f70f1/status?branch=master)](https://codeship.com/projects/117597)
2
+ [![Build Status](https://travis-ci.org/arturictus/hash_map.svg?branch=master)](https://travis-ci.org/arturictus/hash_map)
3
+ [![Gem Version](https://badge.fury.io/rb/hash_map.svg)](https://badge.fury.io/rb/hash_map)
4
+ [![](https://img.shields.io/gem/dt/contextuable.svg?style=flat)](https://rubygems.org/gems/hash_map)
5
+ [![Code Climate](https://codeclimate.com/github/arturictus/hash_map/badges/gpa.svg)](https://codeclimate.com/github/arturictus/hash_map)
6
+ [![Coverage Status](https://coveralls.io/repos/github/arturictus/hash_map/badge.svg?branch=master)](https://coveralls.io/github/arturictus/hash_map?branch=master)
7
+ [![Issue Count](https://codeclimate.com/github/arturictus/hash_map/badges/issue_count.svg)](https://codeclimate.com/github/arturictus/hash_map)
3
8
 
4
9
  HashMap is a small library that allow you to map hashes with style :).
5
10
  It will remove from your code many of the ugly navigation inside hashes to
@@ -140,6 +145,33 @@ Collections.map({ numbers: '1'})
140
145
  }
141
146
  ```
142
147
 
148
+ **Inheritance**
149
+ When inheriting from a Mapper child will inherit the properties
150
+
151
+ ```ruby
152
+ class UserMapper < HashMap::Base
153
+ properties :name, :lastname
154
+ end
155
+
156
+ class AdminMapper < UserMapper
157
+ properties :role, :company
158
+ end
159
+
160
+ original = {
161
+ name: 'John',
162
+ lastname: 'Doe',
163
+ role: 'Admin',
164
+ company: 'ACME'
165
+ }
166
+
167
+ UserMapper.map(original)
168
+ #=> { name: 'John', lastname: 'Doe' }
169
+
170
+ AdminMapper.map(original)
171
+ #=> { name: 'John', lastname: 'Doe', role: 'Admin', company: 'ACME' }
172
+
173
+ ```
174
+
143
175
  **Methods:**
144
176
 
145
177
  You can create your helpers in the mapper and call them inside the block
data/lib/hash_map/base.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module HashMap
2
2
  class Base
3
- include ToDSL
4
3
  delegate :[], to: :output
5
4
 
6
5
  def self.map(input)
@@ -8,6 +7,14 @@ module HashMap
8
7
  end
9
8
  singleton_class.send(:alias_method, :call, :map)
10
9
 
10
+ def self.inherited(subclass)
11
+ subclass.extend ToDSL
12
+ return unless self < HashMap::Base
13
+ unless dsl.attributes.empty?
14
+ subclass._set_attributes_from_inheritance(attributes)
15
+ end
16
+ end
17
+
11
18
  attr_reader :original
12
19
  def initialize(original)
13
20
  @original = prepare_input(original)
data/lib/hash_map/dsl.rb CHANGED
@@ -1,22 +1,23 @@
1
1
  module HashMap
2
2
  module ToDSL
3
- extend ActiveSupport::Concern
4
- class_methods do
5
- def method_missing(method, *args, &block)
6
- if dsl.respond_to?(method)
7
- dsl.send(method, *args, &block)
8
- else
9
- super
10
- end
3
+ def method_missing(method, *args, &block)
4
+ if dsl.respond_to?(method)
5
+ dsl.send(method, *args, &block)
6
+ else
7
+ super
11
8
  end
9
+ end
12
10
 
13
- def dsl
14
- @dsl ||= DSL.new
15
- end
11
+ def dsl
12
+ @dsl ||= DSL.new
13
+ end
16
14
 
17
- def attributes
18
- dsl.attributes
19
- end
15
+ def attributes
16
+ dsl.attributes
17
+ end
18
+
19
+ def _set_attributes_from_inheritance(attrs)
20
+ dsl._set_attributes(attrs.dup)
20
21
  end
21
22
  end
22
23
 
@@ -29,6 +30,10 @@ module HashMap
29
30
  @attributes = []
30
31
  end
31
32
 
33
+ def _set_attributes(attrs)
34
+ @attributes = attrs
35
+ end
36
+
32
37
  def property(key, opts = {}, &block)
33
38
  fail InvalidOptionsForProperty, "[HashMap Error] using: `#{__callee__}` with wrong options, second argument must be a `Hash" unless opts.is_a? Hash
34
39
  new_hash = {}.tap { |h| h[:key] = single_to_ary(key) }
@@ -1,3 +1,3 @@
1
1
  module HashMap
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
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.3.6
4
+ version: 0.3.7
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: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,8 +73,11 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".coveralls.yml"
76
77
  - ".gitignore"
77
78
  - ".rspec"
79
+ - ".rubocop.yml"
80
+ - ".rubocop_todo.yml"
78
81
  - ".travis.yml"
79
82
  - CODE_OF_CONDUCT.md
80
83
  - Gemfile
@@ -112,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  version: '0'
113
116
  requirements: []
114
117
  rubyforge_project:
115
- rubygems_version: 2.4.6
118
+ rubygems_version: 2.2.3
116
119
  signing_key:
117
120
  specification_version: 4
118
121
  summary: Library to map easily hashes.