light_mapper 0.0.1
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 +7 -0
- data/.gitignore +24 -0
- data/.rspec +4 -0
- data/.rubocop.yml +48 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/light_mapper/version.rb +3 -0
- data/lib/light_mapper.rb +16 -0
- data/light_mapper.gemspec +29 -0
- data/spec/lib/light_mapper_spec.rb +46 -0
- data/spec/spec_helper.rb +31 -0
- metadata +172 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ec180a4b4062fa63e032fef32a556894a365dcb4
|
|
4
|
+
data.tar.gz: 40f8416865d57b19af6c16bf0b82fe4306261dc1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 35af7945db5ac71c6353fa873f46a86677a9bcea56e9d4645c57acfbb2a850dc48ff4ee1e847d46fad8ca4bfb7a856ce69cc330cc57a1bf204ebcf2aa7ba719a
|
|
7
|
+
data.tar.gz: 9e2693e1fbcc48e7a6a95c10d609aa3536303dcbad048bd52221516bbd96f3f1691775b6d1cceb75f7987c23f42fa4461e3c0dcc2b6f27aa003fba18f8efd8d9
|
data/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
.bundle
|
|
4
|
+
.config
|
|
5
|
+
.yardoc
|
|
6
|
+
Gemfile.lock
|
|
7
|
+
InstalledFiles
|
|
8
|
+
_yardoc
|
|
9
|
+
coverage
|
|
10
|
+
doc/
|
|
11
|
+
lib/bundler/man
|
|
12
|
+
pkg
|
|
13
|
+
rdoc
|
|
14
|
+
spec/reports
|
|
15
|
+
test/tmp
|
|
16
|
+
test/version_tmp
|
|
17
|
+
tmp
|
|
18
|
+
*.bundle
|
|
19
|
+
*.so
|
|
20
|
+
*.o
|
|
21
|
+
*.a
|
|
22
|
+
mkmf.log
|
|
23
|
+
.rubocop_todo.yml
|
|
24
|
+
.ruby-version
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
|
2
|
+
# on 2015-02-23 06:17:38 +0100 using RuboCop version 0.27.1.
|
|
3
|
+
# The point is for the user to remove these configuration records
|
|
4
|
+
# one by one as the offenses are removed from the code base.
|
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
7
|
+
|
|
8
|
+
# Offense count: 3
|
|
9
|
+
Style/Documentation:
|
|
10
|
+
Enabled: false
|
|
11
|
+
|
|
12
|
+
# Offense count: 2
|
|
13
|
+
# Cop supports --auto-correct.
|
|
14
|
+
# Configuration parameters: PreferredDelimiters.
|
|
15
|
+
Style/PercentLiteralDelimiters:
|
|
16
|
+
Enabled: false
|
|
17
|
+
|
|
18
|
+
# Offense count: 2
|
|
19
|
+
Style/RegexpLiteral:
|
|
20
|
+
MaxSlashes: 0
|
|
21
|
+
|
|
22
|
+
# Offense count: 1
|
|
23
|
+
# Cop supports --auto-correct.
|
|
24
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
25
|
+
Style/TrailingBlankLines:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
# Offense count: 1
|
|
29
|
+
# Cop supports --auto-correct.
|
|
30
|
+
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
|
|
31
|
+
Style/TrivialAccessors:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
# Offense count: 2
|
|
35
|
+
# Cop supports --auto-correct.
|
|
36
|
+
Style/UnneededPercentQ:
|
|
37
|
+
Enabled: false
|
|
38
|
+
|
|
39
|
+
Documentation:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
Metrics/LineLength:
|
|
43
|
+
Max: 120
|
|
44
|
+
|
|
45
|
+
AllCops:
|
|
46
|
+
Exclude:
|
|
47
|
+
- '**/Guardfile'
|
|
48
|
+
- '**/light_parmas.gemspec'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
guard :rspec, cmd: 'rspec' do
|
|
2
|
+
watch(%r{^lib/(.+).rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
|
3
|
+
watch(%r{^spec/(.+).rb$}) { |m| "spec/#{m[1]}.rb" }
|
|
4
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
|
5
|
+
watch('Gemfile')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
guard :rubocop, all_on_start: false, cli: ['--format', 'clang'] do
|
|
9
|
+
watch(%r{.+\.rb$})
|
|
10
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
|
11
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Pawel Niemczyk
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# LightMapper
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'light_mapper'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install light_mapper
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
TODO: Write usage instructions here
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/light_mapper/fork )
|
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/light_mapper.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'light_mapper/version'
|
|
2
|
+
|
|
3
|
+
module LightMapper
|
|
4
|
+
def mapping(mappings, opts = {})
|
|
5
|
+
LightMapper.mapping(clone, mappings, opts)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.mapping(hash, mappings, opts = {})
|
|
9
|
+
require_keys = opts[:require_keys] == true
|
|
10
|
+
|
|
11
|
+
fetch_method = require_keys ? :fetch : :[]
|
|
12
|
+
{}.tap do |h|
|
|
13
|
+
mappings.each { |k, v| h[v] = hash.public_send(fetch_method, k) }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'light_mapper/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'light_mapper'
|
|
8
|
+
spec.version = LightMapper::VERSION
|
|
9
|
+
spec.authors = ['Pawel Niemczyk']
|
|
10
|
+
spec.email = ['pniemczyk.info@gmail.com']
|
|
11
|
+
spec.summary = %q{Very light hash mapper}
|
|
12
|
+
spec.description = %q{Hash mapper}
|
|
13
|
+
spec.homepage = 'https://github.com/pniemczyk/light_mapper'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = %w(lib)
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
24
|
+
spec.add_development_dependency 'guard', '~> 2.12'
|
|
25
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.5'
|
|
26
|
+
spec.add_development_dependency 'guard-rubocop', '~> 1.2'
|
|
27
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
|
28
|
+
spec.add_development_dependency 'awesome_print', '~> 1.6'
|
|
29
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe LightMapper do
|
|
4
|
+
|
|
5
|
+
subject { original_hash.extend(LightMapper) }
|
|
6
|
+
|
|
7
|
+
describe 'basic data mapping' do
|
|
8
|
+
let(:original_hash) do
|
|
9
|
+
{
|
|
10
|
+
'A' => 'test',
|
|
11
|
+
'b' => 1
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:maper) do
|
|
16
|
+
{
|
|
17
|
+
'A' => :a,
|
|
18
|
+
'b' => 'z'
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'return correct hash' do
|
|
23
|
+
expect(subject.mapping(maper)).to eq(a: original_hash['A'], 'z' => original_hash['b'])
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe 'basic data mapping when keys are required' do
|
|
28
|
+
let(:original_hash) do
|
|
29
|
+
{
|
|
30
|
+
'A' => 'test',
|
|
31
|
+
'b' => 1
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
let(:maper) do
|
|
36
|
+
{
|
|
37
|
+
'A' => :a,
|
|
38
|
+
'c' => 'z'
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'raise KeyError when required key missing' do
|
|
43
|
+
expect { subject.mapping(maper, require_keys: true) }.to raise_error(KeyError)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
require 'awesome_print'
|
|
3
|
+
Bundler.setup
|
|
4
|
+
|
|
5
|
+
require 'coveralls'
|
|
6
|
+
Coveralls.wear!
|
|
7
|
+
|
|
8
|
+
require 'light_mapper'
|
|
9
|
+
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
|
|
10
|
+
|
|
11
|
+
RSpec.configure do |config|
|
|
12
|
+
config.filter_run :focus
|
|
13
|
+
config.run_all_when_everything_filtered = true
|
|
14
|
+
|
|
15
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
|
16
|
+
|
|
17
|
+
config.profile_examples = 10
|
|
18
|
+
config.order = :random
|
|
19
|
+
|
|
20
|
+
Kernel.srand config.seed
|
|
21
|
+
|
|
22
|
+
config.expect_with :rspec do |expectations|
|
|
23
|
+
expectations.syntax = :expect
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
config.mock_with :rspec do |mocks|
|
|
27
|
+
mocks.syntax = :expect
|
|
28
|
+
mocks.verify_partial_doubles = true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
require 'guard/rubocop'
|
metadata
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: light_mapper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pawel Niemczyk
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.7'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.7'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.4'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.4'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: guard
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '2.12'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '2.12'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: guard-rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '4.5'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '4.5'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: guard-rubocop
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '1.2'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '1.2'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: coveralls
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0.7'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0.7'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: awesome_print
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '1.6'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '1.6'
|
|
125
|
+
description: Hash mapper
|
|
126
|
+
email:
|
|
127
|
+
- pniemczyk.info@gmail.com
|
|
128
|
+
executables: []
|
|
129
|
+
extensions: []
|
|
130
|
+
extra_rdoc_files: []
|
|
131
|
+
files:
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- ".rubocop.yml"
|
|
135
|
+
- ".travis.yml"
|
|
136
|
+
- Gemfile
|
|
137
|
+
- Guardfile
|
|
138
|
+
- LICENSE.txt
|
|
139
|
+
- README.md
|
|
140
|
+
- Rakefile
|
|
141
|
+
- lib/light_mapper.rb
|
|
142
|
+
- lib/light_mapper/version.rb
|
|
143
|
+
- light_mapper.gemspec
|
|
144
|
+
- spec/lib/light_mapper_spec.rb
|
|
145
|
+
- spec/spec_helper.rb
|
|
146
|
+
homepage: https://github.com/pniemczyk/light_mapper
|
|
147
|
+
licenses:
|
|
148
|
+
- MIT
|
|
149
|
+
metadata: {}
|
|
150
|
+
post_install_message:
|
|
151
|
+
rdoc_options: []
|
|
152
|
+
require_paths:
|
|
153
|
+
- lib
|
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
|
+
requirements:
|
|
156
|
+
- - ">="
|
|
157
|
+
- !ruby/object:Gem::Version
|
|
158
|
+
version: '0'
|
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
|
+
requirements:
|
|
161
|
+
- - ">="
|
|
162
|
+
- !ruby/object:Gem::Version
|
|
163
|
+
version: '0'
|
|
164
|
+
requirements: []
|
|
165
|
+
rubyforge_project:
|
|
166
|
+
rubygems_version: 2.4.5
|
|
167
|
+
signing_key:
|
|
168
|
+
specification_version: 4
|
|
169
|
+
summary: Very light hash mapper
|
|
170
|
+
test_files:
|
|
171
|
+
- spec/lib/light_mapper_spec.rb
|
|
172
|
+
- spec/spec_helper.rb
|