acts_as_hashable 1.0.5 → 1.2.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +3 -1
- data/.ruby-version +1 -1
- data/.travis.yml +8 -4
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Guardfile +1 -1
- data/README.md +77 -4
- data/Rakefile +10 -0
- data/acts_as_hashable.gemspec +16 -4
- data/bin/console +2 -6
- data/exe/.gitkeep +0 -0
- data/lib/acts_as_hashable.rb +24 -1
- data/lib/acts_as_hashable/factory.rb +66 -0
- data/lib/acts_as_hashable/hash_refinements.rb +20 -0
- data/lib/acts_as_hashable/hashable.rb +22 -4
- data/lib/acts_as_hashable/type_factory.rb +51 -0
- data/lib/acts_as_hashable/version.rb +1 -1
- metadata +75 -18
- data/Gemfile.lock +0 -102
- data/lib/acts_as_hashable/acts_as_hashable.rb +0 -24
- data/lib/acts_as_hashable/utilities.rb +0 -34
- data/spec/acts_as_hashable_spec.rb +0 -203
- data/spec/examples.rb +0 -62
- data/spec/spec_helper.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5f83e22faa7ed0b0ff1d37038a51dcb92b5bbf07e2ae4e0256091d5954da642
|
4
|
+
data.tar.gz: 7c6d956f731420f46a1c924a6e7c8f2213aede31fb6f90ec397b734482eeb806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67ac75655f768375a9148cb86b51d9e39ab2071376a6480d03d33d93a289fb745fa18cb74ec55e31e16e729a86ae5c3e4d79d71314da44c80d8e0bfc324252ea
|
7
|
+
data.tar.gz: ba7c1cbcbc7c1a538c7d8b7d9905f9f9a581cba4264339f5d1e41497128c3d512e817046b87c2964b44230997203bd2d138684732604bfd289c6c6230dd6c398
|
data/.rubocop.yml
CHANGED
@@ -3,9 +3,11 @@ Metrics/LineLength:
|
|
3
3
|
|
4
4
|
Metrics/BlockLength:
|
5
5
|
ExcludedMethods: ['it', 'describe', 'context', 'let', 'specify']
|
6
|
+
Exclude:
|
7
|
+
- acts_as_hashable.gemspec
|
6
8
|
|
7
9
|
AllCops:
|
8
|
-
TargetRubyVersion: 2.
|
10
|
+
TargetRubyVersion: 2.5
|
9
11
|
|
10
12
|
Style/RescueModifier:
|
11
13
|
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.6
|
data/.travis.yml
CHANGED
@@ -4,10 +4,9 @@ env:
|
|
4
4
|
language: ruby
|
5
5
|
rvm:
|
6
6
|
# Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
|
7
|
-
- 2.
|
8
|
-
- 2.
|
9
|
-
- 2.
|
10
|
-
- 2.6.0
|
7
|
+
- 2.5.8
|
8
|
+
- 2.6.6
|
9
|
+
- 2.7.1
|
11
10
|
cache: bundler
|
12
11
|
before_script:
|
13
12
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
@@ -18,3 +17,8 @@ script:
|
|
18
17
|
- bundle exec rspec
|
19
18
|
after_script:
|
20
19
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
20
|
+
addons:
|
21
|
+
# https://docs.travis-ci.com/user/uploading-artifacts/
|
22
|
+
artifacts:
|
23
|
+
paths:
|
24
|
+
- Gemfile.lock
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 1.2.0 (June 9th, 2020)
|
2
|
+
|
3
|
+
* Bumped minimum Ruby version to >= 2.5
|
4
|
+
* Do not pass in any constructor arguments unless we have at least one key.
|
5
|
+
* Add more detail to construction errors.
|
6
|
+
|
7
|
+
# 1.1.0 (May 3rd, 2019)
|
8
|
+
|
9
|
+
* Added acts_as_hashable_factory to dynamically create objects.
|
10
|
+
|
1
11
|
# 1.0.5 (February 5th, 2019)
|
2
12
|
|
3
13
|
* Fixed equality bug in array reject block.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at oss@bluemarblepayroll.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,8 @@ bundle add acts_as_hashable
|
|
30
30
|
|
31
31
|
## Examples
|
32
32
|
|
33
|
+
### Utilizing Classes on Hashabled Classes
|
34
|
+
|
33
35
|
Consider the following example:
|
34
36
|
|
35
37
|
````
|
@@ -125,6 +127,76 @@ class Pet
|
|
125
127
|
end
|
126
128
|
````
|
127
129
|
|
130
|
+
### Dynamic Factory Building
|
131
|
+
|
132
|
+
More complex relationships may contain objects with disparate types. In this case we can use the included factory
|
133
|
+
pattern to help us build these. Based on our examples above:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
class ExampleFactory
|
137
|
+
acts_as_hashable_factory
|
138
|
+
|
139
|
+
register 'Pet', Pet
|
140
|
+
|
141
|
+
register 'HeadOfHousehold', HeadOfHousehold
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
Now we can dynamically build these using:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
objects = [
|
149
|
+
{
|
150
|
+
type: 'Pet',
|
151
|
+
name: 'Doug the dog',
|
152
|
+
toy: { squishy: true }
|
153
|
+
},
|
154
|
+
{
|
155
|
+
type: 'HeadOfHousehold',
|
156
|
+
person: {
|
157
|
+
name: 'Matt',
|
158
|
+
age: 109
|
159
|
+
},
|
160
|
+
partner: {
|
161
|
+
name: 'Katie',
|
162
|
+
age: 110
|
163
|
+
}
|
164
|
+
}
|
165
|
+
]
|
166
|
+
|
167
|
+
hydrated_objects = ExampleFactory.array(objects)
|
168
|
+
```
|
169
|
+
|
170
|
+
If the type key does not happen to be `type` then you can explicitly set this as:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
class ExampleFactory
|
174
|
+
acts_as_hashable_factory
|
175
|
+
|
176
|
+
type_key 'object_type'
|
177
|
+
|
178
|
+
register 'Pet', Pet
|
179
|
+
|
180
|
+
register 'HeadOfHousehold', HeadOfHousehold
|
181
|
+
end
|
182
|
+
```
|
183
|
+
|
184
|
+
You can also choose to pass in a proc/lambda instead of a class constant:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
class ExampleFactory
|
188
|
+
acts_as_hashable_factory
|
189
|
+
|
190
|
+
type_key 'object_type'
|
191
|
+
|
192
|
+
register 'Pet', Pet
|
193
|
+
|
194
|
+
register 'HeadOfHousehold', ->(_key) { HeadOfHousehold }
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
198
|
+
In case you need full control of the registry you can also choose to simply override the class-level `registry` method which will simply return a hash of keys (names) and values (class constants).
|
199
|
+
|
128
200
|
## Contributing
|
129
201
|
|
130
202
|
### Development Environment Configuration
|
@@ -168,10 +240,11 @@ After code changes have successfully gone through the Pull Request review proces
|
|
168
240
|
3. Install dependencies: ```bundle```
|
169
241
|
4. Update ```CHANGELOG.md``` with release notes
|
170
242
|
5. Commit & push master to remote and ensure CI builds master successfully
|
171
|
-
6.
|
172
|
-
|
173
|
-
|
174
|
-
|
243
|
+
6. Run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
244
|
+
|
245
|
+
## Code of Conduct
|
246
|
+
|
247
|
+
Everyone interacting in this codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bluemarblepayroll/acts_as_hashable/blob/master/CODE_OF_CONDUCT.md).
|
175
248
|
|
176
249
|
## License
|
177
250
|
|
data/Rakefile
ADDED
data/acts_as_hashable.gemspec
CHANGED
@@ -14,16 +14,28 @@ Gem::Specification.new do |s|
|
|
14
14
|
DESCRIPTION
|
15
15
|
|
16
16
|
s.authors = ['Matthew Ruggio']
|
17
|
+
s.bindir = 'exe'
|
17
18
|
s.email = ['mruggio@bluemarblepayroll.com']
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
19
|
+
s.executables = []
|
20
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
21
|
s.homepage = 'https://github.com/bluemarblepayroll/acts_as_hashable'
|
22
22
|
s.license = 'MIT'
|
23
|
+
s.metadata = {
|
24
|
+
'bug_tracker_uri' => 'https://github.com/bluemarblepayroll/acts_as_hashable/issues',
|
25
|
+
'changelog_uri' => 'https://github.com/bluemarblepayroll/acts_as_hashable/blob/master/CHANGELOG.md',
|
26
|
+
'documentation_uri' => 'https://www.rubydoc.info/gems/acts_as_hashable',
|
27
|
+
'homepage_uri' => s.homepage,
|
28
|
+
'source_code_uri' => s.homepage
|
29
|
+
}
|
23
30
|
|
24
|
-
s.required_ruby_version = '>= 2.
|
31
|
+
s.required_ruby_version = '>= 2.5'
|
32
|
+
|
33
|
+
s.add_dependency('caution', '~>1')
|
25
34
|
|
26
35
|
s.add_development_dependency('guard-rspec', '~>4.7')
|
36
|
+
s.add_development_dependency('pry')
|
37
|
+
s.add_development_dependency('pry-byebug', '~> 3')
|
38
|
+
s.add_development_dependency('rake', '~> 13.0')
|
27
39
|
s.add_development_dependency('rspec')
|
28
40
|
s.add_development_dependency('rubocop', '~> 0.63.1')
|
29
41
|
s.add_development_dependency('simplecov', '~>0.16.1')
|
data/bin/console
CHANGED
@@ -7,9 +7,5 @@ require 'acts_as_hashable'
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
# Pry.start
|
13
|
-
|
14
|
-
require 'irb'
|
15
|
-
IRB.start
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
data/exe/.gitkeep
ADDED
File without changes
|
data/lib/acts_as_hashable.rb
CHANGED
@@ -7,4 +7,27 @@
|
|
7
7
|
# LICENSE file in the root directory of this source tree.
|
8
8
|
#
|
9
9
|
|
10
|
-
|
10
|
+
require 'caution'
|
11
|
+
require 'forwardable'
|
12
|
+
|
13
|
+
require_relative 'acts_as_hashable/factory'
|
14
|
+
require_relative 'acts_as_hashable/hash_refinements'
|
15
|
+
require_relative 'acts_as_hashable/type_factory'
|
16
|
+
require_relative 'acts_as_hashable/hashable'
|
17
|
+
|
18
|
+
module ActsAsHashable
|
19
|
+
# This module adds the class-level method that marks a class as hashable.
|
20
|
+
module DslHook
|
21
|
+
def acts_as_hashable
|
22
|
+
extend ::ActsAsHashable::Hashable
|
23
|
+
end
|
24
|
+
|
25
|
+
def acts_as_hashable_factory
|
26
|
+
extend ActsAsHashable::Factory
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Object.class_eval do
|
32
|
+
extend ::ActsAsHashable::DslHook
|
33
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module ActsAsHashable
|
11
|
+
# This class serves as a singleton that can make mapped acts_as_hashable components.
|
12
|
+
# It is important to note that these components *must* be acts_as_hashable objects.
|
13
|
+
# In order to use you just have to subclass this class and implement
|
14
|
+
# a method called 'registry', such as:
|
15
|
+
# def registry
|
16
|
+
# {
|
17
|
+
# 'Table': Table,
|
18
|
+
# 'Text': Text
|
19
|
+
# }
|
20
|
+
# end
|
21
|
+
# You can also use the 'register' DSL:
|
22
|
+
# register 'some_class_name', SomeClassName
|
23
|
+
# register 'some_class_name', '', SomeClassName
|
24
|
+
# or:
|
25
|
+
# register 'some_class_name', ->(_key) { SomeClassName }
|
26
|
+
module Factory
|
27
|
+
extend Forwardable
|
28
|
+
|
29
|
+
def_delegators :factory, :array, :make
|
30
|
+
|
31
|
+
def register(*args)
|
32
|
+
raise ArgumentError, "missing at least one key and value: #{args}" if args.length < 2
|
33
|
+
|
34
|
+
value = args.last
|
35
|
+
|
36
|
+
args[0..-2].each do |key|
|
37
|
+
registry[key] = value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def registry
|
42
|
+
@registry ||= {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def materialize_registry
|
46
|
+
@registry.map do |k, v|
|
47
|
+
value = v.is_a?(Proc) ? v.call(k) : v
|
48
|
+
[k, value]
|
49
|
+
end.to_h
|
50
|
+
end
|
51
|
+
|
52
|
+
def type_key(key)
|
53
|
+
@typed_with = key
|
54
|
+
end
|
55
|
+
|
56
|
+
def typed_with
|
57
|
+
@typed_with || TypeFactory::DEFAULT_TYPE_KEY
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def factory
|
63
|
+
@factory ||= TypeFactory.new(materialize_registry, typed_with)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module ActsAsHashable
|
11
|
+
# Let's provide a refinenment instead of monkey-patching Hash. That way we can stop
|
12
|
+
# polluting other libraries and internalize our specific needs.
|
13
|
+
module HashRefinements
|
14
|
+
refine Hash do
|
15
|
+
def symbolize_keys
|
16
|
+
map { |k, v| [k.to_sym, v] }.to_h
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -11,11 +11,21 @@ module ActsAsHashable
|
|
11
11
|
# This class contains the main set of class-level methods that can be used by
|
12
12
|
# hashable classes.
|
13
13
|
module Hashable
|
14
|
+
using HashRefinements
|
15
|
+
|
16
|
+
class HydrationError < Caution::CauseInjectingError; end
|
17
|
+
|
14
18
|
HASHABLE_HYDRATORS = [
|
15
19
|
{
|
16
20
|
condition: ->(_context, object, _nullable) { object.is_a?(Hash) },
|
17
21
|
converter: lambda do |context, object, _nullable|
|
18
|
-
|
22
|
+
args = (object || {}).symbolize_keys
|
23
|
+
|
24
|
+
if args.keys.any?
|
25
|
+
context.new(**args)
|
26
|
+
else
|
27
|
+
context.new
|
28
|
+
end
|
19
29
|
end
|
20
30
|
},
|
21
31
|
{
|
@@ -43,12 +53,20 @@ module ActsAsHashable
|
|
43
53
|
|
44
54
|
def make(object, nullable: true)
|
45
55
|
HASHABLE_HYDRATORS.each do |hydrator|
|
46
|
-
|
47
|
-
|
48
|
-
|
56
|
+
next unless hydrator[:condition].call(self, object, nullable)
|
57
|
+
|
58
|
+
return hydrate(hydrator, object, nullable)
|
49
59
|
end
|
50
60
|
|
51
61
|
raise ArgumentError, "Cannot create hashable object with class name: #{object.class.name}"
|
52
62
|
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def hydrate(hydrator, object, nullable)
|
67
|
+
hydrator[:converter].call(self, object, nullable)
|
68
|
+
rescue ArgumentError
|
69
|
+
raise HydrationError, "#{name} cannot be hydrated using arguments: #{object}"
|
70
|
+
end
|
53
71
|
end
|
54
72
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
|
5
|
+
#
|
6
|
+
# This source code is licensed under the MIT license found in the
|
7
|
+
# LICENSE file in the root directory of this source tree.
|
8
|
+
#
|
9
|
+
|
10
|
+
module ActsAsHashable
|
11
|
+
# A TypeFactory object understands how to build objects using a special designated 'type' key.
|
12
|
+
class TypeFactory
|
13
|
+
using HashRefinements
|
14
|
+
|
15
|
+
DEFAULT_TYPE_KEY = :type
|
16
|
+
|
17
|
+
attr_reader :registry, :type_key
|
18
|
+
|
19
|
+
def initialize(registry = {}, type_key = DEFAULT_TYPE_KEY)
|
20
|
+
@registry = registry.symbolize_keys
|
21
|
+
@type_key = type_key.to_s.to_sym
|
22
|
+
|
23
|
+
freeze
|
24
|
+
end
|
25
|
+
|
26
|
+
def array(objects = [])
|
27
|
+
objects = objects.is_a?(Hash) ? [objects] : Array(objects)
|
28
|
+
|
29
|
+
objects.map do |object|
|
30
|
+
object.is_a?(Hash) ? make(object) : object
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def make(config = {})
|
35
|
+
config = (config || {}).symbolize_keys
|
36
|
+
type = config[type_key].to_s.to_sym
|
37
|
+
object_class = registry[type]
|
38
|
+
|
39
|
+
raise ArgumentError, "cannot find registration for: '#{type}'" unless object_class
|
40
|
+
|
41
|
+
config_without_type = config.reject { |k| k == type_key }
|
42
|
+
|
43
|
+
# We want to defer to the classes proper maker if it exists.
|
44
|
+
# Technically, this factory should only make classes that include Hashable, but just to be
|
45
|
+
# sure we do not break any existing compatibility, lets make it work for both.
|
46
|
+
method_name = object_class.respond_to?(:make) ? :make : :new
|
47
|
+
|
48
|
+
object_class.send(method_name, config_without_type)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_hashable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: caution
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: guard-rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,48 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '4.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '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'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: rspec
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,8 +142,7 @@ description: |2
|
|
86
142
|
class-level methods that you can use with hashes.
|
87
143
|
email:
|
88
144
|
- mruggio@bluemarblepayroll.com
|
89
|
-
executables:
|
90
|
-
- console
|
145
|
+
executables: []
|
91
146
|
extensions: []
|
92
147
|
extra_rdoc_files: []
|
93
148
|
files:
|
@@ -97,25 +152,30 @@ files:
|
|
97
152
|
- ".ruby-version"
|
98
153
|
- ".travis.yml"
|
99
154
|
- CHANGELOG.md
|
155
|
+
- CODE_OF_CONDUCT.md
|
100
156
|
- Gemfile
|
101
|
-
- Gemfile.lock
|
102
157
|
- Guardfile
|
103
158
|
- LICENSE
|
104
159
|
- README.md
|
160
|
+
- Rakefile
|
105
161
|
- acts_as_hashable.gemspec
|
106
162
|
- bin/console
|
163
|
+
- exe/.gitkeep
|
107
164
|
- lib/acts_as_hashable.rb
|
108
|
-
- lib/acts_as_hashable/
|
165
|
+
- lib/acts_as_hashable/factory.rb
|
166
|
+
- lib/acts_as_hashable/hash_refinements.rb
|
109
167
|
- lib/acts_as_hashable/hashable.rb
|
110
|
-
- lib/acts_as_hashable/
|
168
|
+
- lib/acts_as_hashable/type_factory.rb
|
111
169
|
- lib/acts_as_hashable/version.rb
|
112
|
-
- spec/acts_as_hashable_spec.rb
|
113
|
-
- spec/examples.rb
|
114
|
-
- spec/spec_helper.rb
|
115
170
|
homepage: https://github.com/bluemarblepayroll/acts_as_hashable
|
116
171
|
licenses:
|
117
172
|
- MIT
|
118
|
-
metadata:
|
173
|
+
metadata:
|
174
|
+
bug_tracker_uri: https://github.com/bluemarblepayroll/acts_as_hashable/issues
|
175
|
+
changelog_uri: https://github.com/bluemarblepayroll/acts_as_hashable/blob/master/CHANGELOG.md
|
176
|
+
documentation_uri: https://www.rubydoc.info/gems/acts_as_hashable
|
177
|
+
homepage_uri: https://github.com/bluemarblepayroll/acts_as_hashable
|
178
|
+
source_code_uri: https://github.com/bluemarblepayroll/acts_as_hashable
|
119
179
|
post_install_message:
|
120
180
|
rdoc_options: []
|
121
181
|
require_paths:
|
@@ -124,18 +184,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
184
|
requirements:
|
125
185
|
- - ">="
|
126
186
|
- !ruby/object:Gem::Version
|
127
|
-
version: 2.
|
187
|
+
version: '2.5'
|
128
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
189
|
requirements:
|
130
190
|
- - ">="
|
131
191
|
- !ruby/object:Gem::Version
|
132
192
|
version: '0'
|
133
193
|
requirements: []
|
134
|
-
rubygems_version: 3.0.
|
194
|
+
rubygems_version: 3.0.3
|
135
195
|
signing_key:
|
136
196
|
specification_version: 4
|
137
197
|
summary: Simple hash-based factory methods for objects.
|
138
|
-
test_files:
|
139
|
-
- spec/acts_as_hashable_spec.rb
|
140
|
-
- spec/examples.rb
|
141
|
-
- spec/spec_helper.rb
|
198
|
+
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
acts_as_hashable (1.0.5)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ansi (1.5.0)
|
10
|
-
ast (2.4.0)
|
11
|
-
coderay (1.1.2)
|
12
|
-
diff-lcs (1.3)
|
13
|
-
docile (1.3.1)
|
14
|
-
ffi (1.10.0)
|
15
|
-
formatador (0.2.5)
|
16
|
-
guard (2.15.0)
|
17
|
-
formatador (>= 0.2.4)
|
18
|
-
listen (>= 2.7, < 4.0)
|
19
|
-
lumberjack (>= 1.0.12, < 2.0)
|
20
|
-
nenv (~> 0.1)
|
21
|
-
notiffany (~> 0.0)
|
22
|
-
pry (>= 0.9.12)
|
23
|
-
shellany (~> 0.0)
|
24
|
-
thor (>= 0.18.1)
|
25
|
-
guard-compat (1.2.1)
|
26
|
-
guard-rspec (4.7.3)
|
27
|
-
guard (~> 2.1)
|
28
|
-
guard-compat (~> 1.1)
|
29
|
-
rspec (>= 2.99.0, < 4.0)
|
30
|
-
hirb (0.7.3)
|
31
|
-
jaro_winkler (1.5.2)
|
32
|
-
json (2.1.0)
|
33
|
-
listen (3.1.5)
|
34
|
-
rb-fsevent (~> 0.9, >= 0.9.4)
|
35
|
-
rb-inotify (~> 0.9, >= 0.9.7)
|
36
|
-
ruby_dep (~> 1.2)
|
37
|
-
lumberjack (1.0.13)
|
38
|
-
method_source (0.9.2)
|
39
|
-
nenv (0.3.0)
|
40
|
-
notiffany (0.1.1)
|
41
|
-
nenv (~> 0.1)
|
42
|
-
shellany (~> 0.0)
|
43
|
-
parallel (1.13.0)
|
44
|
-
parser (2.6.0.0)
|
45
|
-
ast (~> 2.4.0)
|
46
|
-
powerpack (0.1.2)
|
47
|
-
pry (0.12.2)
|
48
|
-
coderay (~> 1.1.0)
|
49
|
-
method_source (~> 0.9.0)
|
50
|
-
rainbow (3.0.0)
|
51
|
-
rb-fsevent (0.10.3)
|
52
|
-
rb-inotify (0.10.0)
|
53
|
-
ffi (~> 1.0)
|
54
|
-
rspec (3.8.0)
|
55
|
-
rspec-core (~> 3.8.0)
|
56
|
-
rspec-expectations (~> 3.8.0)
|
57
|
-
rspec-mocks (~> 3.8.0)
|
58
|
-
rspec-core (3.8.0)
|
59
|
-
rspec-support (~> 3.8.0)
|
60
|
-
rspec-expectations (3.8.1)
|
61
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.8.0)
|
63
|
-
rspec-mocks (3.8.0)
|
64
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
-
rspec-support (~> 3.8.0)
|
66
|
-
rspec-support (3.8.0)
|
67
|
-
rubocop (0.63.1)
|
68
|
-
jaro_winkler (~> 1.5.1)
|
69
|
-
parallel (~> 1.10)
|
70
|
-
parser (>= 2.5, != 2.5.1.1)
|
71
|
-
powerpack (~> 0.1)
|
72
|
-
rainbow (>= 2.2.2, < 4.0)
|
73
|
-
ruby-progressbar (~> 1.7)
|
74
|
-
unicode-display_width (~> 1.4.0)
|
75
|
-
ruby-progressbar (1.10.0)
|
76
|
-
ruby_dep (1.5.0)
|
77
|
-
shellany (0.0.1)
|
78
|
-
simplecov (0.16.1)
|
79
|
-
docile (~> 1.1)
|
80
|
-
json (>= 1.8, < 3)
|
81
|
-
simplecov-html (~> 0.10.0)
|
82
|
-
simplecov-console (0.4.2)
|
83
|
-
ansi
|
84
|
-
hirb
|
85
|
-
simplecov
|
86
|
-
simplecov-html (0.10.2)
|
87
|
-
thor (0.20.3)
|
88
|
-
unicode-display_width (1.4.1)
|
89
|
-
|
90
|
-
PLATFORMS
|
91
|
-
ruby
|
92
|
-
|
93
|
-
DEPENDENCIES
|
94
|
-
acts_as_hashable!
|
95
|
-
guard-rspec (~> 4.7)
|
96
|
-
rspec
|
97
|
-
rubocop (~> 0.63.1)
|
98
|
-
simplecov (~> 0.16.1)
|
99
|
-
simplecov-console (~> 0.4.2)
|
100
|
-
|
101
|
-
BUNDLED WITH
|
102
|
-
1.17.2
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
5
|
-
#
|
6
|
-
# This source code is licensed under the MIT license found in the
|
7
|
-
# LICENSE file in the root directory of this source tree.
|
8
|
-
#
|
9
|
-
|
10
|
-
require_relative 'utilities'
|
11
|
-
require_relative 'hashable'
|
12
|
-
|
13
|
-
module ActsAsHashable
|
14
|
-
# This module adds the class-level method that marks a class as hashable.
|
15
|
-
module DslHook
|
16
|
-
def acts_as_hashable
|
17
|
-
extend ::ActsAsHashable::Hashable
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Object.class_eval do
|
23
|
-
extend ::ActsAsHashable::DslHook
|
24
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
5
|
-
#
|
6
|
-
# This source code is licensed under the MIT license found in the
|
7
|
-
# LICENSE file in the root directory of this source tree.
|
8
|
-
#
|
9
|
-
|
10
|
-
module ActsAsHashable
|
11
|
-
# Some extra functions that are either ancillary to the main domain or polyfill other
|
12
|
-
# mainstream imnplementations.
|
13
|
-
class Utilities
|
14
|
-
class << self
|
15
|
-
# https://apidock.com/rails/Hash/symbolize_keys
|
16
|
-
def symbolize_keys(hash)
|
17
|
-
transform_keys(hash) { |key| key.to_sym rescue key }
|
18
|
-
end
|
19
|
-
|
20
|
-
# https://apidock.com/rails/v4.2.7/Hash/transform_keys
|
21
|
-
def transform_keys(hash)
|
22
|
-
return enum_for(:transform_keys) unless block_given?
|
23
|
-
|
24
|
-
result = {}
|
25
|
-
|
26
|
-
hash.keys.each do |key|
|
27
|
-
result[yield(key)] = hash[key]
|
28
|
-
end
|
29
|
-
|
30
|
-
result
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,203 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
5
|
-
#
|
6
|
-
# This source code is licensed under the MIT license found in the
|
7
|
-
# LICENSE file in the root directory of this source tree.
|
8
|
-
#
|
9
|
-
|
10
|
-
require './spec/spec_helper'
|
11
|
-
|
12
|
-
describe ActsAsHashable do
|
13
|
-
context '#make' do
|
14
|
-
context 'when passing in unacceptable input' do
|
15
|
-
it 'should raise ArgumentError for number' do
|
16
|
-
expect { Pet.make(1) }.to raise_error(ArgumentError)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should raise ArgumentError for string' do
|
20
|
-
expect { Pet.make('') }.to raise_error(ArgumentError)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should raise ArgumentError for true' do
|
24
|
-
expect { Pet.make(true) }.to raise_error(ArgumentError)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should raise ArgumentError for array' do
|
28
|
-
expect { Pet.make([]) }.to raise_error(ArgumentError)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'with a hash constructor interface' do
|
33
|
-
it 'should properly return object if object is already the same type' do
|
34
|
-
original_pet_obj = Pet.new
|
35
|
-
pet_obj = Pet.make(original_pet_obj)
|
36
|
-
|
37
|
-
expect(pet_obj.hash).to eq(original_pet_obj.hash)
|
38
|
-
expect(pet_obj.name).to be nil
|
39
|
-
expect(pet_obj.toy).to be nil
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should properly return hydrated object if nil is passed in and is not nullable' do
|
43
|
-
pet_obj = Pet.make(nil, nullable: false)
|
44
|
-
|
45
|
-
expect(pet_obj.name).to be nil
|
46
|
-
expect(pet_obj.toy).to be nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should properly return nil if nil is passed in and is nullable' do
|
50
|
-
pet_obj = Pet.make(nil, nullable: false)
|
51
|
-
|
52
|
-
expect(pet_obj.name).to be nil
|
53
|
-
expect(pet_obj.toy).to be nil
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should properly instantiate objects from a symbol-keyed hash' do
|
57
|
-
pet = {
|
58
|
-
name: 'Doug the dog',
|
59
|
-
toy: { squishy: true }
|
60
|
-
}
|
61
|
-
|
62
|
-
pet_obj = Pet.make(pet)
|
63
|
-
|
64
|
-
expect(pet_obj.name).to eq('Doug the dog')
|
65
|
-
expect(pet_obj.toy.squishy).to be true
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with keyword arguments interface' do
|
70
|
-
it 'should properly instantiate objects from symbol-keyed hash' do
|
71
|
-
head_of_household = {
|
72
|
-
person: {
|
73
|
-
name: 'Matt',
|
74
|
-
age: 109
|
75
|
-
},
|
76
|
-
partner: {
|
77
|
-
name: 'Katie',
|
78
|
-
age: 110
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
head_of_household_obj = HeadOfHousehold.make(head_of_household)
|
83
|
-
|
84
|
-
expect(head_of_household_obj.person.name).to eq('Matt')
|
85
|
-
expect(head_of_household_obj.person.age).to eq(109)
|
86
|
-
expect(head_of_household_obj.partner.name).to eq('Katie')
|
87
|
-
expect(head_of_household_obj.partner.age).to eq(110)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should properly instantiate objects from string-keyed hash' do
|
91
|
-
head_of_household = {
|
92
|
-
'person' => {
|
93
|
-
'name' => 'Matt',
|
94
|
-
'age' => 109
|
95
|
-
},
|
96
|
-
'partner' => {
|
97
|
-
'name' => 'Katie',
|
98
|
-
'age' => 110
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
head_of_household_obj = HeadOfHousehold.make(head_of_household)
|
103
|
-
|
104
|
-
expect(head_of_household_obj.person.name).to eq('Matt')
|
105
|
-
expect(head_of_household_obj.person.age).to eq(109)
|
106
|
-
expect(head_of_household_obj.partner.name).to eq('Katie')
|
107
|
-
expect(head_of_household_obj.partner.age).to eq(110)
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should raise an ArgumentError for missing required keyword' do
|
111
|
-
head_of_household = {
|
112
|
-
person: {
|
113
|
-
# name: 'Matt',
|
114
|
-
age: 109
|
115
|
-
},
|
116
|
-
partner: {
|
117
|
-
name: 'Katie',
|
118
|
-
age: 110
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
expect { HeadOfHousehold.make(head_of_household) }.to raise_error(ArgumentError)
|
123
|
-
end
|
124
|
-
|
125
|
-
it 'should raise an ArgumentError for unknown required keyword' do
|
126
|
-
head_of_household = {
|
127
|
-
person: {
|
128
|
-
name: 'Matt',
|
129
|
-
age: 109,
|
130
|
-
height_in_inches: 700
|
131
|
-
},
|
132
|
-
partner: {
|
133
|
-
name: 'Katie',
|
134
|
-
age: 110
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
|
-
expect { HeadOfHousehold.make(head_of_household) }.to raise_error(ArgumentError)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
context '#array' do
|
143
|
-
it 'should properly create objects and arrays of objects from symbol-keyed hash and arrays' do
|
144
|
-
family = {
|
145
|
-
head_of_household: {
|
146
|
-
person: {
|
147
|
-
name: 'Matt',
|
148
|
-
age: 109
|
149
|
-
},
|
150
|
-
partner: {
|
151
|
-
name: 'Katie',
|
152
|
-
age: 110
|
153
|
-
}
|
154
|
-
},
|
155
|
-
children: [
|
156
|
-
{ name: 'Martin', age: 29 },
|
157
|
-
{ name: 'Short', age: 99 }
|
158
|
-
]
|
159
|
-
}
|
160
|
-
|
161
|
-
family_obj = Family.make(family)
|
162
|
-
|
163
|
-
expect(family_obj.head_of_household.person.name).to eq('Matt')
|
164
|
-
expect(family_obj.head_of_household.person.age).to eq(109)
|
165
|
-
expect(family_obj.head_of_household.partner.name).to eq('Katie')
|
166
|
-
expect(family_obj.head_of_household.partner.age).to eq(110)
|
167
|
-
|
168
|
-
expect(family_obj.children.length).to eq(2)
|
169
|
-
expect(family_obj.children[0].name).to eq('Martin')
|
170
|
-
expect(family_obj.children[0].age).to eq(29)
|
171
|
-
expect(family_obj.children[1].name).to eq('Short')
|
172
|
-
expect(family_obj.children[1].age).to eq(99)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should properly instantiate arrays of objects when only a single hash is passed in' do
|
176
|
-
family = {
|
177
|
-
head_of_household: {
|
178
|
-
person: {
|
179
|
-
name: 'Matt',
|
180
|
-
age: 109
|
181
|
-
},
|
182
|
-
partner: {
|
183
|
-
name: 'Katie',
|
184
|
-
age: 110
|
185
|
-
}
|
186
|
-
},
|
187
|
-
children: { name: 'Martin', age: 29 }
|
188
|
-
}
|
189
|
-
|
190
|
-
family_obj = Family.make(family)
|
191
|
-
|
192
|
-
expect(family_obj.head_of_household.person.name).to eq('Matt')
|
193
|
-
expect(family_obj.head_of_household.person.age).to eq(109)
|
194
|
-
expect(family_obj.head_of_household.partner.name).to eq('Katie')
|
195
|
-
expect(family_obj.head_of_household.partner.age).to eq(110)
|
196
|
-
|
197
|
-
expect(family_obj.children.length).to eq(1)
|
198
|
-
expect(family_obj.children[0].name).to eq('Martin')
|
199
|
-
expect(family_obj.children[0].age).to eq(29)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
data/spec/examples.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
5
|
-
#
|
6
|
-
# This source code is licensed under the MIT license found in the
|
7
|
-
# LICENSE file in the root directory of this source tree.
|
8
|
-
#
|
9
|
-
|
10
|
-
class Toy
|
11
|
-
acts_as_hashable
|
12
|
-
|
13
|
-
attr_reader :squishy
|
14
|
-
|
15
|
-
def initialize(opts = {})
|
16
|
-
@squishy = opts[:squishy] || false
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Pet
|
21
|
-
acts_as_hashable
|
22
|
-
|
23
|
-
attr_reader :name, :toy
|
24
|
-
|
25
|
-
def initialize(opts = {})
|
26
|
-
@name = opts[:name]
|
27
|
-
@toy = Toy.make(opts[:toy])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class Person
|
32
|
-
acts_as_hashable
|
33
|
-
|
34
|
-
attr_reader :name, :age
|
35
|
-
|
36
|
-
def initialize(name:, age:)
|
37
|
-
@name = name
|
38
|
-
@age = age
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class HeadOfHousehold
|
43
|
-
acts_as_hashable
|
44
|
-
|
45
|
-
attr_reader :person, :partner
|
46
|
-
|
47
|
-
def initialize(person:, partner: nil)
|
48
|
-
@person = Person.make(person)
|
49
|
-
@partner = Person.make(partner)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class Family
|
54
|
-
acts_as_hashable
|
55
|
-
|
56
|
-
attr_reader :head_of_household, :children
|
57
|
-
|
58
|
-
def initialize(head_of_household:, children: [])
|
59
|
-
@head_of_household = HeadOfHousehold.make(head_of_household)
|
60
|
-
@children = Person.array(children)
|
61
|
-
end
|
62
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Copyright (c) 2018-present, Blue Marble Payroll, LLC
|
5
|
-
#
|
6
|
-
# This source code is licensed under the MIT license found in the
|
7
|
-
# LICENSE file in the root directory of this source tree.
|
8
|
-
#
|
9
|
-
|
10
|
-
require 'simplecov'
|
11
|
-
require 'simplecov-console'
|
12
|
-
SimpleCov.formatter = SimpleCov::Formatter::Console
|
13
|
-
SimpleCov.start
|
14
|
-
|
15
|
-
require './lib/acts_as_hashable'
|
16
|
-
require './spec/examples'
|