mapable 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58fc46e41c3b130c5db57b94c2dc637857475c32fa34db0da1bafc4d4849f641
4
+ data.tar.gz: 83af0506c30c291c6a9a5f896e5ad2b93c4dcfe9a3a32b0d57d39d85914892e3
5
+ SHA512:
6
+ metadata.gz: b547e51d0ab35c0c60c39ccf67d4aec95c4118852d8d539b753ec47a5c5caa390d2057bd872b173ac9a6c7e0fb109ffde80eee81d28658da695cf7773200edb2
7
+ data.tar.gz: 169d287c8121c73d19552fce68d4b15cffe2861a61974bd30029f732a70ab906ea2120977de53cdb26695729f1ac4dcc8ba05a76b6733a0971ad8a0cebb1e6bf
@@ -0,0 +1,51 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ .DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ *~
39
+ \#*
40
+ .\#*
41
+
42
+ # For vim:
43
+ *.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ *.gem
@@ -0,0 +1,12 @@
1
+ Naming/FileName:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Max: 120
5
+ Metrics/ModuleLength:
6
+ Max: 120
7
+ Metrics/MethodLength:
8
+ Max: 20
9
+ AllCops:
10
+ Exclude:
11
+ - 'spec/spec_helper.rb'
12
+ - 'spec/**/*_spec.rb'
@@ -0,0 +1 @@
1
+ mapable
@@ -0,0 +1 @@
1
+ 2.6.3
@@ -0,0 +1,17 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=b741b9c10232b4a3fc3e48cc03e24298c8b7adaa85da8c470c17646b572eab1f
4
+ rvm:
5
+ - 2.6.3
6
+ - 2.1.9
7
+ - 1.9.3
8
+ gemfile: gemfiles/travis.gemfile
9
+ language: ruby
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
14
+ script:
15
+ - bundle exec rspec
16
+ after_script:
17
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ gem 'inheritance-helper'
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ gem 'rubocop'
10
+ end
11
+
12
+ group :spec do
13
+ gem 'rspec'
14
+ gem 'simplecov'
15
+ end
@@ -0,0 +1,54 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ast (2.4.0)
5
+ diff-lcs (1.3)
6
+ docile (1.3.2)
7
+ inheritance-helper (0.1.0)
8
+ jaro_winkler (1.5.3)
9
+ json (2.2.0)
10
+ parallel (1.17.0)
11
+ parser (2.6.4.0)
12
+ ast (~> 2.4.0)
13
+ rainbow (3.0.0)
14
+ rake (12.3.3)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.2)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.4)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.2)
28
+ rubocop (0.74.0)
29
+ jaro_winkler (~> 1.5.1)
30
+ parallel (~> 1.10)
31
+ parser (>= 2.6)
32
+ rainbow (>= 2.2.2, < 4.0)
33
+ ruby-progressbar (~> 1.7)
34
+ unicode-display_width (>= 1.4.0, < 1.7)
35
+ ruby-progressbar (1.10.1)
36
+ simplecov (0.17.0)
37
+ docile (~> 1.1)
38
+ json (>= 1.8, < 3)
39
+ simplecov-html (~> 0.10.0)
40
+ simplecov-html (0.10.2)
41
+ unicode-display_width (1.6.0)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ inheritance-helper
48
+ rake
49
+ rspec
50
+ rubocop
51
+ simplecov
52
+
53
+ BUNDLED WITH
54
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 dougyouch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ # mapable
2
+
3
+ [![Build Status](https://travis-ci.org/dougyouch/mapable.svg?branch=master)](https://travis-ci.org/dougyouch/mapable)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c67c80c8351faff52580/maintainability)](https://codeclimate.com/github/dougyouch/mapable/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c67c80c8351faff52580/test_coverage)](https://codeclimate.com/github/dougyouch/mapable/test_coverage)
@@ -0,0 +1 @@
1
+ gemfiles/../Gemfile
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'inheritance-helper'
4
+
5
+ # Transfer/Map data from one model to the next
6
+ module Mapable
7
+ autoload :Mapping, 'mapable/mapping'
8
+ autoload :Utils, 'mapable/utils'
9
+
10
+ def self.included(base)
11
+ base.extend InheritanceHelper::Methods
12
+ base.extend ClassMethods
13
+ end
14
+
15
+ # no-doc
16
+ module ClassMethods
17
+ def maps
18
+ {}.freeze
19
+ end
20
+
21
+ def map_to(name, options = {}, &block)
22
+ mapping = Mapping.create(self, name, options, &block)
23
+ add_value_to_class_method(:maps, name => mapping)
24
+
25
+ class_eval(
26
+ <<-STR, __FILE__, __LINE__ + 1
27
+ def map_to_#{name}(dest)
28
+ ::#{mapping.name}.new.map(self, dest)
29
+ dest
30
+ end
31
+ STR
32
+ )
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mapable
4
+ # Defines what fields to map
5
+ module Mapping
6
+ def self.included(base)
7
+ base.extend InheritanceHelper::Methods
8
+ base.extend ClassMethods
9
+ end
10
+
11
+ def self.default_mapping_options(src, dest)
12
+ {
13
+ src: src.to_sym,
14
+ src_getter: src.to_s.freeze,
15
+ src_setter: "#{src}=",
16
+ dest: dest.to_sym,
17
+ dest_getter: dest.to_s.freeze,
18
+ dest_setter: "#{dest}="
19
+ }
20
+ end
21
+
22
+ # no-doc
23
+ module ClassMethods
24
+ def mappings
25
+ {}.freeze
26
+ end
27
+
28
+ def map(src, dest = nil, options = {})
29
+ if dest.is_a?(Hash)
30
+ options = dest
31
+ dest = nil
32
+ end
33
+
34
+ dest ||= src
35
+
36
+ options = ::Mapable::Mapping.default_mapping_options(src, dest)
37
+ .merge(options)
38
+
39
+ add_value_to_class_method(:mappings, src.to_sym => options)
40
+ end
41
+ end
42
+
43
+ def map(src_model, dest_model)
44
+ self.class.mappings.each do |_, info|
45
+ dest_model.public_send(info[:dest_setter], src_model.public_send(info[:src_getter]))
46
+ end
47
+ dest_model
48
+ end
49
+
50
+ def self.create(base_module, name, options = {}, &block)
51
+ options[:class_name] ||= ::Mapable::Utils.classify_name(name.to_s) + 'Mapping'
52
+ kls = Class.new(options[:base_class] || Object)
53
+ kls = base_module.const_set(options[:class_name], kls)
54
+ kls.send(:include, ::Mapable::Mapping)
55
+ kls.class_eval(&block) if block
56
+ kls
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mapable
4
+ # General purpouse utility methods
5
+ module Utils
6
+ module_function
7
+
8
+ def classify_name(name)
9
+ name.gsub(/[^\da-z_-]/, '').gsub(/(^.|[_|-].)/) { |m| m[-1].upcase }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'mapable'
5
+ s.version = '0.1.0'
6
+ s.licenses = ['MIT']
7
+ s.summary = 'Map data between models'
8
+ s.description = 'Easy way to configure what data is mapped between models'
9
+ s.authors = ['Doug Youch']
10
+ s.email = 'dougyouch@gmail.com'
11
+ s.homepage = 'https://github.com/dougyouch/mapable'
12
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|script)/}) }
13
+
14
+ s.add_runtime_dependency 'inheritance-helper'
15
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mapable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doug Youch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: inheritance-helper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Easy way to configure what data is mapped between models
28
+ email: dougyouch@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rubocop.yml"
35
+ - ".ruby-gemset"
36
+ - ".ruby-version"
37
+ - ".travis.yml"
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - LICENSE
41
+ - README.md
42
+ - gemfiles/travis.gemfile
43
+ - lib/mapable.rb
44
+ - lib/mapable/mapping.rb
45
+ - lib/mapable/utils.rb
46
+ - mapable.gemspec
47
+ homepage: https://github.com/dougyouch/mapable
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.7.10
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Map data between models
71
+ test_files: []