attributes-mapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7374884ab90c0b7fca54225029a9d03a1e1c63774317a334bda4e141c3dc9d0
4
+ data.tar.gz: f14efe5a80d9c8db745593bfd462ee4db268b1b5c0e4b10b513bd181086652e0
5
+ SHA512:
6
+ metadata.gz: 20c7c98145f99ae436ed07174c87cf145b3b8b86d8430c8e274bdebcbc15df0b11f74574b8b81c0c1646e299f3b2176691202bcd368f92b8e41a2c024740ee6d
7
+ data.tar.gz: 6431ea10562ce748be42951d94b59c13d8aba8eddf7ca97ce6a4bdb6ea46d726a2961031dc52bca748b329cc06a857ee4785bca9f882b2a606b27cafb85a51e0
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '2.7.6'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /rdoc/
10
+ /.idea/
11
+
12
+ *.gem
13
+ *.rbc
14
+
15
+ .config
16
+ .yardoc
17
+ Gemfile.lock
18
+
19
+ # rspec failure tracking
20
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format progress
3
+ --require spec_helper
4
+ --order rand
data/.rubocop.yml ADDED
@@ -0,0 +1,247 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+ - rubocop-performance
5
+
6
+ AllCops:
7
+ NewCops: enable
8
+ TargetRubyVersion: 2.7
9
+ Exclude:
10
+ - 'lib/attributes-mapper.rb'
11
+ - 'vendor/bundle/**/*'
12
+ - 'gemfiles/vendor/bundle/**/*'
13
+ - 'bin/*'
14
+ - 'attributes-mapper.gemspec'
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/FrozenStringLiteralComment:
20
+ Enabled: false
21
+
22
+ Style/Encoding:
23
+ Enabled: false
24
+
25
+ Style/StringLiterals:
26
+ Enabled: false
27
+
28
+ Style/FormatStringToken:
29
+ Enabled: false
30
+
31
+ Style/RedundantReturn:
32
+ Enabled: false
33
+
34
+ Style/SignalException:
35
+ Enabled: true
36
+
37
+ Style/HashSyntax:
38
+ EnforcedStyle: ruby19_no_mixed_keys
39
+
40
+ Style/TrivialAccessors:
41
+ AllowPredicates: true
42
+
43
+ Naming/PredicateName:
44
+ Enabled: false
45
+
46
+ Metrics/MethodLength:
47
+ Max: 15
48
+
49
+ Metrics/BlockLength:
50
+ Max: 35
51
+ Exclude:
52
+ - 'spec/**/*.rb'
53
+
54
+ Layout/TrailingEmptyLines:
55
+ Enabled: false
56
+
57
+ Layout/EndOfLine:
58
+ EnforcedStyle: lf
59
+
60
+ Lint/ConstantDefinitionInBlock:
61
+ Exclude:
62
+ - 'spec/**/*.rb'
63
+
64
+ Lint/EmptyClass:
65
+ Exclude:
66
+ - 'spec/**/*.rb'
67
+
68
+ # Defaults after the Rubocop upgrade
69
+ Gemspec/DeprecatedAttributeAssignment: # new in 1.10
70
+ Enabled: true
71
+
72
+ Layout/LineEndStringConcatenationIndentation: # new in 1.18
73
+ Enabled: true
74
+
75
+ Layout/SpaceBeforeBrackets: # new in 1.7
76
+ Enabled: true
77
+
78
+ Lint/AmbiguousAssignment: # new in 1.7
79
+ Enabled: true
80
+
81
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
82
+ Enabled: true
83
+
84
+ Lint/AmbiguousRange: # new in 1.19
85
+ Enabled: true
86
+
87
+ Lint/DeprecatedConstants: # new in 1.8
88
+ Enabled: true
89
+
90
+ Lint/DuplicateBranch: # new in 1.3
91
+ Enabled: true
92
+
93
+ Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
94
+ Enabled: true
95
+
96
+ Lint/EmptyBlock: # new in 1.1
97
+ Enabled: true
98
+
99
+ Lint/EmptyInPattern: # new in 1.16
100
+ Enabled: true
101
+
102
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
103
+ Enabled: true
104
+
105
+ Lint/LambdaWithoutLiteralBlock: # new in 1.8
106
+ Enabled: true
107
+
108
+ Lint/NoReturnInBeginEndBlocks: # new in 1.2
109
+ Enabled: true
110
+
111
+ Lint/NumberedParameterAssignment: # new in 1.9
112
+ Enabled: true
113
+
114
+ Lint/OrAssignmentToConstant: # new in 1.9
115
+ Enabled: true
116
+
117
+ Lint/RedundantDirGlobSort: # new in 1.8
118
+ Enabled: true
119
+
120
+ Lint/SymbolConversion: # new in 1.9
121
+ Enabled: true
122
+
123
+ Lint/ToEnumArguments: # new in 1.1
124
+ Enabled: true
125
+
126
+ Lint/TripleQuotes: # new in 1.9
127
+ Enabled: true
128
+
129
+ Lint/UnexpectedBlockArity: # new in 1.5
130
+ Enabled: true
131
+
132
+ Lint/UnmodifiedReduceAccumulator: # new in 1.1
133
+ Enabled: true
134
+
135
+ Style/ArgumentsForwarding: # new in 1.1
136
+ Enabled: true
137
+
138
+ Style/CollectionCompact: # new in 1.2
139
+ Enabled: true
140
+
141
+ Style/DocumentDynamicEvalDefinition: # new in 1.1
142
+ Enabled: true
143
+
144
+ Style/EndlessMethod: # new in 1.8
145
+ Enabled: true
146
+
147
+ Style/HashConversion: # new in 1.10
148
+ Enabled: true
149
+
150
+ Style/HashExcept: # new in 1.7
151
+ Enabled: true
152
+
153
+ Style/IfWithBooleanLiteralBranches: # new in 1.9
154
+ Enabled: true
155
+
156
+ Style/InPatternThen: # new in 1.16
157
+ Enabled: true
158
+
159
+ Style/MultilineInPatternThen: # new in 1.16
160
+ Enabled: true
161
+
162
+ Style/NegatedIfElseCondition: # new in 1.2
163
+ Enabled: true
164
+
165
+ Style/NilLambda: # new in 1.3
166
+ Enabled: true
167
+
168
+ Style/QuotedSymbols: # new in 1.16
169
+ Enabled: true
170
+
171
+ Style/RedundantArgument: # new in 1.4
172
+ Enabled: true
173
+
174
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
175
+ Enabled: true
176
+
177
+ Style/StringChars: # new in 1.12
178
+ Enabled: true
179
+
180
+ Style/SwapValues: # new in 1.1
181
+ Enabled: true
182
+
183
+ Gemspec/RequireMFA: # new in 1.23
184
+ Enabled: true
185
+
186
+ Lint/RequireRelativeSelfPath: # new in 1.22
187
+ Enabled: true
188
+
189
+ Lint/UselessRuby2Keywords: # new in 1.23
190
+ Enabled: true
191
+
192
+ Naming/BlockForwarding: # new in 1.24
193
+ Enabled: true
194
+
195
+ Security/IoMethods: # new in 1.22
196
+ Enabled: true
197
+
198
+ Style/FileRead: # new in 1.24
199
+ Enabled: true
200
+
201
+ Style/FileWrite: # new in 1.24
202
+ Enabled: true
203
+
204
+ Style/MapToHash: # new in 1.24
205
+ Enabled: true
206
+
207
+ Style/NestedFileDirname: # new in 1.26
208
+ Enabled: true
209
+
210
+ Style/NumberedParameters: # new in 1.22
211
+ Enabled: true
212
+
213
+ Style/NumberedParametersLimit: # new in 1.22
214
+ Enabled: true
215
+
216
+ Style/OpenStructUse: # new in 1.23
217
+ Enabled: true
218
+
219
+ Style/SelectByRegexp: # new in 1.22
220
+ Enabled: true
221
+
222
+ RSpec/NestedGroups:
223
+ Enabled: false
224
+
225
+ RSpec/MultipleExpectations:
226
+ Enabled: false
227
+
228
+ RSpec/LeakyConstantDeclaration:
229
+ Enabled: false
230
+
231
+ RSpec/ExampleLength:
232
+ Enabled: false
233
+
234
+ RSpec/MultipleMemoizedHelpers:
235
+ Enabled: false
236
+
237
+ RSpec/PredicateMatcher:
238
+ Enabled: false
239
+
240
+ RSpec/FilePath:
241
+ Enabled: false
242
+
243
+ RSpec/SubjectStub:
244
+ Enabled: false
245
+
246
+ RSpec/VerifiedDoubles:
247
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-03-01
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at desoleary@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in attributes-mapper.gemspec
6
+ gemspec
7
+
8
+ gem "rubocop", "~> 1.44.1"
9
+ gem "rubocop-performance", ">= 1.16.0"
10
+ gem "rubocop-rake", ">= 0.6.0"
11
+ gem "rubocop-rspec", ">= 2.18.1"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Desmond O'Leary
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # AttributesMapper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/attributes/mapper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'attributes-mapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install attributes-mapper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/attributes-mapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/attributes-mapper/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Attributes::Mapper project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/attributes-mapper/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/attributes-mapper/version', __dir__)
4
+
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.authors = ["Desmond O'Leary"]
8
+ gem.email = ["desoleary@gmail.com"]
9
+ gem.description = 'Declarative attributes mapping'
10
+ gem.summary = 'Declarative attributes mapping'
11
+ gem.homepage = "https://github.com/omnitech-solutions/attributes-mapper"
12
+ gem.license = "MIT"
13
+
14
+ gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
15
+ gem.executables = gem.files.grep(%r{^exe/}).map { |f| File.basename(f) }
16
+ gem.name = "attributes-mapper"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = AttributesMapper::VERSION
19
+ gem.required_ruby_version = ">= 2.7"
20
+
21
+ gem.metadata["homepage_uri"] = gem.homepage
22
+ gem.metadata["source_code_uri"] = gem.homepage
23
+ gem.metadata["changelog_uri"] = "#{gem.homepage}/CHANGELOG.md"
24
+
25
+ gem.add_runtime_dependency 'json-path-builder', '~> 0.1.0'
26
+ gem.add_runtime_dependency 'rordash', '~> 0.1.2'
27
+
28
+ gem.add_development_dependency("codecov", "~> 0.6.0")
29
+ gem.add_development_dependency("rake", "~> 13.0.6")
30
+ gem.add_development_dependency("rspec", "~> 3.12.0")
31
+ gem.add_development_dependency("simplecov", "~> 0.21.2")
32
+ gem.metadata['rubygems_mfa_required'] = 'true'
33
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "attributes_mapper"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dev/setup.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Sets up environment for running specs and via irb e.g. `$ irb -r ./dev/setup`
4
+
5
+ require 'rspec/core'
6
+
7
+ require 'active_support/core_ext/hash/keys'
8
+ require 'active_support/core_ext/module/delegation'
9
+ require 'active_support/core_ext/object/blank'
10
+ require 'active_support/core_ext/object/json'
11
+ require 'active_support/core_ext/enumerable'
12
+ require 'active_support/configurable'
13
+
14
+ %w[../../lib/attributes_mapper ../../spec/spec_helper].each do |rel_path|
15
+ require File.expand_path(rel_path, Pathname.new(__FILE__).realpath)
16
+ end
@@ -0,0 +1,23 @@
1
+ module AttributesMapper
2
+ class Configuration
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor(:required_attributes) { [] }
6
+ config_accessor(:optional_attributes) { [] }
7
+ config_accessor(:scopes) { {} }
8
+ config_accessor(:source_data_wrapper_class) { nil }
9
+ config_accessor(:apply_input_data_transform_proc) { nil }
10
+
11
+ def ordered_path_context_names
12
+ required_attributes + optional_attributes
13
+ end
14
+
15
+ def source_data_wrapper_class?
16
+ source_data_wrapper_class.present?
17
+ end
18
+
19
+ def apply_input_data_transform?
20
+ apply_input_data_transform_proc.is_a?(Proc)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,93 @@
1
+ module AttributesMapper
2
+ module HasAttributes
3
+ extend ActiveSupport::Concern
4
+
5
+ SCOPE = :scope
6
+
7
+ ALLOWED_PARAMETERS = [
8
+ :from,
9
+ :transform,
10
+ :fallback,
11
+ :skip_if,
12
+ SCOPE
13
+ ].freeze
14
+
15
+ # rubocop:disable Metrics/BlockLength
16
+ class_methods do
17
+ attr_writer :path_context_attr_list_map
18
+
19
+ delegate :required_attributes, :optional_attributes, :ordered_path_context_names, to: :configuration
20
+
21
+ def path_context_attr_list_map
22
+ @path_context_attr_list_map ||= {}
23
+ end
24
+
25
+ def path_context_params_for(key)
26
+ path_context_attr_list_map[key.to_sym]
27
+ end
28
+
29
+ def each_path_context_key_value_pair(&block)
30
+ path_context_attr_list_map.slice(*configuration.ordered_path_context_names).each_pair(&block)
31
+ end
32
+
33
+ def add_path_context_attrs(key, **path_context_args)
34
+ path_context_attr_list_map[key] = path_context_args
35
+
36
+ self
37
+ end
38
+
39
+ def find_path_by_scope_name(name)
40
+ path_scopes[name.to_sym]
41
+ end
42
+
43
+ def define_attribute_methods
44
+ configuration.ordered_path_context_names.each { |name| define_attribute_method(name) }
45
+ end
46
+
47
+ def define_attribute_method(name)
48
+ singleton_class.send(:define_method, name) do |&block|
49
+ params = block.call
50
+ raise "block must return valid hash path params" unless params.is_a?(Hash)
51
+
52
+ apply_attribute(name, params.slice(*(ALLOWED_PARAMETERS + [SCOPE])))
53
+ end
54
+ end
55
+
56
+ def apply_attribute(name, **params)
57
+ add_path_context_attrs(name, **params)
58
+ nil
59
+ end
60
+
61
+ private
62
+
63
+ def path_scopes
64
+ @path_scopes ||= configuration.scopes.symbolize_keys
65
+ end
66
+ end
67
+ # rubocop:enable Metrics/BlockLength
68
+
69
+ module ConfigurationMethods
70
+ def configuration
71
+ @configuration ||= Configuration.new
72
+ end
73
+
74
+ def configure
75
+ yield configuration
76
+ define_attribute_methods
77
+ end
78
+ end
79
+
80
+ module ConfigurationInstanceMethods
81
+ delegate :config, to: :configuration
82
+
83
+ def configuration
84
+ self.class.configuration
85
+ end
86
+ end
87
+
88
+ def self.included(base)
89
+ base.singleton_class.include(ConfigurationMethods)
90
+ base.include(ConfigurationInstanceMethods)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AttributesMapper
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rordash'
4
+ require 'json-path/builder'
5
+
6
+ %w[
7
+ version
8
+ configuration
9
+ has_attributes
10
+ ].each do |filename|
11
+ require File.expand_path("../attributes-mapper/#{filename}", Pathname.new(__FILE__).realpath)
12
+ end
13
+
14
+ module AttributesMapper; end
@@ -0,0 +1,4 @@
1
+ module AttributesMapper
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable RSpec/NamedSubject
4
+ module AttributesMapper
5
+ RSpec.describe Configuration do
6
+ describe '.scopes' do
7
+ it 'returns a hash' do
8
+ expect(described_class.scopes).to be_a(Hash)
9
+ end
10
+ end
11
+
12
+ describe '.source_data_wrapper_class' do
13
+ it 'returns nil by default' do
14
+ expect(described_class.source_data_wrapper_class).to be_nil
15
+ end
16
+ end
17
+
18
+ describe '#source_data_wrapper_class?' do
19
+ context 'when source_data_wrapper_class is set' do
20
+ before { subject.source_data_wrapper_class = 'WrapperClass' }
21
+
22
+ it 'returns true' do
23
+ expect(subject.source_data_wrapper_class?).to be_truthy
24
+ end
25
+ end
26
+
27
+ context 'when source_data_wrapper_class is not set' do
28
+ it 'returns false' do
29
+ expect(subject.source_data_wrapper_class?).to be_falsey
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '.apply_input_data_transform_proc' do
35
+ it 'returns nil by default' do
36
+ expect(described_class.apply_input_data_transform_proc).to be_nil
37
+ end
38
+ end
39
+
40
+ describe '#apply_input_data_transform?' do
41
+ context 'when apply_input_data_transform_proc is set' do
42
+ before { subject.apply_input_data_transform_proc = proc {} }
43
+
44
+ it 'returns true' do
45
+ expect(subject.apply_input_data_transform?).to be_truthy
46
+ end
47
+ end
48
+
49
+ context 'when apply_input_data_transform_proc is not set' do
50
+ it 'returns false' do
51
+ expect(subject.apply_input_data_transform?).to be_falsey
52
+ end
53
+ end
54
+ end
55
+ end
56
+ # rubocop:enable RSpec/NamedSubject
57
+ end
58
+
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/ModuleLength
4
+ module AttributesMapper
5
+ # rubocop:disable Layout/LineLength,RSpec/StubbedMock,RSpec/MessageSpies
6
+ RSpec.describe HasAttributes do
7
+ describe 'ClassMethods' do
8
+ let(:subject_class) do
9
+ Class.new do
10
+ include HasAttributes
11
+
12
+ configure do |config|
13
+ config.required_attributes = %i[name age]
14
+ config.optional_attributes = [:email]
15
+ config.scopes = { profile: 'user.profile' }
16
+ end
17
+
18
+ name { { from: :username } }
19
+ age { { from: :age } }
20
+ email { { from: :email } }
21
+ end
22
+ end
23
+
24
+ describe ".required_attributes" do
25
+ it "returns an empty hash when @required_attributes is not set" do
26
+ expect(subject_class.required_attributes).to eq(%i[name age])
27
+ end
28
+
29
+ it "returns the value of @required_attributes when it is set" do
30
+ subject_class.instance_variable_set(:@required_attributes, %i[name age])
31
+ expect(subject_class.configuration.required_attributes).to eq(%i[name age])
32
+ end
33
+ end
34
+
35
+ describe ".optional_attributes" do
36
+ it "returns an empty hash when @optional_attributes is not set" do
37
+ expect(subject_class.optional_attributes).to eq([:email])
38
+ end
39
+
40
+ it "returns the value of @optional_attributes when it is set" do
41
+ subject_class.instance_variable_set(:@optional_attributes, [:email])
42
+ expect(subject_class.optional_attributes).to eq([:email])
43
+ end
44
+ end
45
+
46
+ describe ".required_attributes=" do
47
+ it "sets the value of @required_attributes" do
48
+ subject_class.configure do |config|
49
+ config.required_attributes = %i[username other]
50
+ end
51
+
52
+ expect(subject_class.required_attributes).to eq(%i[username other])
53
+ end
54
+ end
55
+
56
+ describe ".optional_attributes=" do
57
+ it "sets the value of @optional_attributes" do
58
+ expect(subject_class.optional_attributes).to eq([:email])
59
+ end
60
+ end
61
+
62
+ describe ".ordered_path_context_names" do
63
+ it "returns the concatenation of required_attributes and optional_attributes" do
64
+ subject_class.configure do |config|
65
+ config.required_attributes = %i[username other]
66
+ config.optional_attributes = [:key]
67
+ end
68
+
69
+ expect(subject_class.ordered_path_context_names).to eq(%i[username other key])
70
+ end
71
+ end
72
+
73
+ describe ".path_context_attr_list_map" do
74
+ it "returns an empty hash when @path_context_attr_list_map is not set" do
75
+ expect(subject_class.path_context_attr_list_map).to eq({ age: { from: :age }, email: { from: :email },
76
+ name: { from: :username } })
77
+ end
78
+
79
+ it "returns the value of @path_context_attr_list_map when it is set" do
80
+ subject_class.instance_variable_set(:@path_context_attr_list_map, { user: { name: String, age: Integer } })
81
+ expect(subject_class.path_context_attr_list_map).to eq({ user: { name: String, age: Integer } })
82
+ end
83
+ end
84
+
85
+ describe ".path_context_params_for" do
86
+ it "returns the value for the specified key in path_context_attr_list_map" do
87
+ subject_class.path_context_attr_list_map = { user: { from: :user } }
88
+ expect(subject_class.path_context_params_for(:user)).to eq({ from: :user })
89
+ end
90
+
91
+ it "returns nil if the specified key is not in path_context_attr_list_map" do
92
+ expect(subject_class.path_context_params_for(:unknown)).to be_nil
93
+ end
94
+ end
95
+
96
+ describe ".each_path_context_key_value_pair" do
97
+ it "yields each key-value pair in path_context_attr_list_map that is included in ordered_path_context_names" do
98
+ subject_class.path_context_attr_list_map = { name: { from: :name }, age: { from: :age },
99
+ email: { from: :email }, other: { from: :other } }
100
+ expect do |b|
101
+ subject_class.each_path_context_key_value_pair(&b)
102
+ end.to yield_successive_args([:name, { from: :name }], [:age, { from: :age }], [:email, { from: :email }])
103
+ end
104
+ end
105
+
106
+ describe ".add_path_context_attrs" do
107
+ it "adds a new key-value pair to path_context_attr_list_map" do
108
+ subject_class.add_path_context_attrs(:user, { from: :username })
109
+ expect(subject_class.path_context_attr_list_map).to include(user: { from: :username })
110
+ end
111
+
112
+ it "returns self" do
113
+ expect(subject_class.add_path_context_attrs(:user, name: String, age: Integer)).to eq(subject_class)
114
+ end
115
+ end
116
+
117
+ describe ".find_path_by_scope_name" do
118
+ it "returns the path scope for the specified name" do
119
+ expect(subject_class.find_path_by_scope_name(:profile)).to eq("user.profile")
120
+ end
121
+ end
122
+
123
+ describe ".define_attribute_methods" do
124
+ it "defines attribute methods for each name in ordered_path_context_names" do
125
+ subject_class.configure do |config|
126
+ config.required_attributes = %i[username other]
127
+ config.optional_attributes = [:key]
128
+ end
129
+
130
+ expect(subject_class).to receive(:define_attribute_method).with(:username)
131
+ expect(subject_class).to receive(:define_attribute_method).with(:other)
132
+ expect(subject_class).to receive(:define_attribute_method).with(:key)
133
+ subject_class.define_attribute_methods
134
+ end
135
+ end
136
+
137
+ describe ".define_attribute_method" do
138
+ it "defines an attribute method with the specified name" do
139
+ expect(subject_class.singleton_class).to receive(:define_method).with(:name).and_return(nil)
140
+ subject_class.define_attribute_method(:name)
141
+ end
142
+ end
143
+
144
+ describe ".apply_attribute" do
145
+ it "adds the specified params to path_context_attr_list_map for the specified name" do
146
+ expect(subject_class).to receive(:add_path_context_attrs).with(:name, :from => :name, :transform => :capitalize,
147
+ HasAttributes::SCOPE => :users).and_return(nil)
148
+ subject_class.apply_attribute(:name, :from => :name, :transform => :capitalize,
149
+ HasAttributes::SCOPE => :users)
150
+ end
151
+
152
+ it "returns nil" do
153
+ expect(subject_class.apply_attribute(:name, :from => :name, :transform => :capitalize,
154
+ HasAttributes::SCOPE => :users)).to be_nil
155
+ end
156
+ end
157
+ end
158
+ end
159
+ # rubocop:enable Layout/LineLength,RSpec/StubbedMock,RSpec/MessageSpies
160
+ end
161
+ # rubocop:enable Metrics/ModuleLength
162
+
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe AttributesMapper do
4
+ it "has a version number" do
5
+ expect(described_class::VERSION).not_to be_nil
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ if ENV['RUN_COVERAGE_REPORT']
2
+ require 'simplecov'
3
+
4
+ SimpleCov.start do
5
+ add_filter 'vendor/'
6
+ add_filter %r{^/spec/}
7
+ end
8
+ SimpleCov.minimum_coverage_by_file 90
9
+
10
+ require 'codecov'
11
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(__dir__, "..", 'dev', 'setup')
4
+ require Pathname.new(__dir__).realpath.join('coverage_helper').to_s
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = ".rspec_status"
9
+
10
+ # Disable RSpec exposing methods globally on `Module` and `main`
11
+ config.disable_monkey_patching!
12
+
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attributes-mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Desmond O'Leary
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json-path-builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.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.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rordash
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.21.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.21.2
97
+ description: Declarative attributes mapping
98
+ email:
99
+ - desoleary@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".github/workflows/main.yml"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - CHANGELOG.md
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - attributes-mapper.gemspec
115
+ - bin/console
116
+ - bin/rspec
117
+ - bin/rubocop
118
+ - bin/setup
119
+ - dev/setup.rb
120
+ - lib/attributes-mapper/configuration.rb
121
+ - lib/attributes-mapper/has_attributes.rb
122
+ - lib/attributes-mapper/version.rb
123
+ - lib/attributes_mapper.rb
124
+ - sig/attributes/mapper.rbs
125
+ - spec/attributes-mapper/configuration_spec.rb
126
+ - spec/attributes-mapper/has_attributes_spec.rb
127
+ - spec/attributes_mapper_spec.rb
128
+ - spec/coverage_helper.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/omnitech-solutions/attributes-mapper
131
+ licenses:
132
+ - MIT
133
+ metadata:
134
+ homepage_uri: https://github.com/omnitech-solutions/attributes-mapper
135
+ source_code_uri: https://github.com/omnitech-solutions/attributes-mapper
136
+ changelog_uri: https://github.com/omnitech-solutions/attributes-mapper/CHANGELOG.md
137
+ rubygems_mfa_required: 'true'
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '2.7'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubygems_version: 3.1.6
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Declarative attributes mapping
157
+ test_files: []