acts_as_hashable 1.2.0.pre.alpha.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0dede2b7914dcb91cd030c65e5385220553d7cd523172e40c5390a644598cb5
4
- data.tar.gz: 47a708a122c7c12d80fa9932b24c2d5cbe4ab8cab97264afb818c0a0781ac308
3
+ metadata.gz: a65b9069ee49d32c52627fd9ef82275b065f11a4b823baf014e8b4dd0da378ab
4
+ data.tar.gz: e94f87a51dd6e013787402ca03f6be9118a07f5e9d5c922eb1707bfb8a812bfb
5
5
  SHA512:
6
- metadata.gz: 1720b09fddd1101546b452bde063e5d7a516d5883ce75cd4a5bca09726cf6d97ad7e28a7ca1dee4966fa926ffddc7a293b1dc7bc5e19888b420525ea156e4037
7
- data.tar.gz: 69d1012dddafed50c20503cb27049d4df950182587f7d911f658b0fb239e36f103a62d70a6a5d3a35bc2ed535c28ef8cd309726ec18dd98825d1e1d2fcd7e169
6
+ metadata.gz: a898e36e34decb4cbb3cdea1bc0126babda2d3a5be4e67423ba02f600102f9763553a7ed26451cb56d4008a45571f96374716e737130def6192940eb99084000
7
+ data.tar.gz: 6740620f589c266e32ad37b4e7edd1685b1c87357dbdb530a51d25f2cbb8dde65104562ae6198300b0fee10b852bf9fc336fcc4dc99ae98283f89b5e389d4569
@@ -0,0 +1,71 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ status_to_ms_teams: bluemarblepayroll/status_to_ms_teams_pure_bash@1.0.0
5
+
6
+ jobs:
7
+ build:
8
+ parameters:
9
+ use-bundler-cache:
10
+ type: boolean
11
+ default: true
12
+
13
+ docker:
14
+ - image: circleci/ruby:2.6.6-buster
15
+ environment:
16
+ FORBID_FOCUSED_SPECS: 1
17
+ working_directory: ~/acts_as_hashable
18
+ steps:
19
+ - checkout
20
+
21
+ # TODO: wrap bundler caching logic into an Orb:
22
+ - when:
23
+ condition: << parameters.use-bundler-cache >>
24
+ steps:
25
+ - restore_cache:
26
+ key: v1.0.0-build-ruby-dependency-cache-{{ checksum "acts_as_hashable.gemspec" }}-{{ checksum "Gemfile" }}-{{ checksum ".ruby-version" }}
27
+
28
+ - run: bundle install --path vendor/bundle
29
+
30
+ - when:
31
+ condition: << parameters.use-bundler-cache >>
32
+ steps:
33
+ - save_cache:
34
+ key: v1.0.0-build-ruby-dependency-cache-{{ checksum "acts_as_hashable.gemspec" }}-{{ checksum "Gemfile" }}-{{ checksum ".ruby-version" }}
35
+ paths:
36
+ - vendor/bundle
37
+
38
+ - store_artifacts:
39
+ path: Gemfile.lock
40
+
41
+ - run: bundle exec rubocop
42
+
43
+ - run: COVERAGE=true bundle exec rspec -r rspec_junit_formatter --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
44
+
45
+ - store_test_results:
46
+ path: test-results
47
+
48
+ - store_artifacts:
49
+ path: coverage
50
+
51
+ - status_to_ms_teams/report:
52
+ webhook_url: $MS_TEAMS_WEBHOOK_URL
53
+
54
+ workflows:
55
+ version: 2.1
56
+ build:
57
+ jobs:
58
+ - build:
59
+ context: org-global
60
+ monthly-gem-dependency-refresh-check:
61
+ triggers:
62
+ - schedule:
63
+ cron: '0 0 1 * *'
64
+ filters:
65
+ branches:
66
+ only:
67
+ - master
68
+ jobs:
69
+ - build:
70
+ context: org-global
71
+ use-bundler-cache: false
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  /coverage
5
5
  /pkg
6
6
  Gemfile.lock
7
+ /test-results
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.6.6
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- # 1.2.0 (une 8th, 2020)
1
+ # 1.3.0 (September 5th, 2020)
2
+
3
+ Additions:
4
+
5
+ * Added dynamic class constantization when a string is registered for a Factory.
6
+
7
+ # 1.2.0 (June 9th, 2020)
2
8
 
3
9
  * Bumped minimum Ruby version to >= 2.5
4
10
  * Do not pass in any constructor arguments unless we have at least one key.
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Acts as Hashable
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/acts_as_hashable.svg)](https://badge.fury.io/rb/acts_as_hashable) [![Build Status](https://travis-ci.org/bluemarblepayroll/acts_as_hashable.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/acts_as_hashable) [![Maintainability](https://api.codeclimate.com/v1/badges/647dac37b9a8177f3d84/maintainability)](https://codeclimate.com/github/bluemarblepayroll/acts_as_hashable/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/647dac37b9a8177f3d84/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/acts_as_hashable/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
-
5
3
  This is a small library that helps increase the pliability of object constructor signatures.
6
4
  Instead of instantiating via the constructor, this library can install helper factory
7
5
  class-level methods that you can use with hashes:
@@ -19,7 +17,7 @@ The two class-level factory methods are just meant to create a syntactic hash-li
19
17
  To install through Rubygems:
20
18
 
21
19
  ````
22
- gem install install acts_as_hashable
20
+ gem install acts_as_hashable
23
21
  ````
24
22
 
25
23
  You can also add this to your Gemfile:
@@ -197,6 +195,22 @@ end
197
195
 
198
196
  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
197
 
198
+ ### Resolving Constants at Runtime
199
+
200
+ Factories can also be resolved using Ruby's Object#const_get and Object#const_missing. Simply register a string representing the class in order to use these mechanics, such as:
201
+
202
+ ```ruby
203
+ class ExampleFactory
204
+ acts_as_hashable_factory
205
+
206
+ type_key 'object_type'
207
+
208
+ register 'Pet', 'Pet'
209
+
210
+ register 'HeadOfHousehold', ->(_key) { HeadOfHousehold }
211
+ end
212
+ ```
213
+
200
214
  ## Contributing
201
215
 
202
216
  ### Development Environment Configuration
@@ -20,13 +20,6 @@ Gem::Specification.new do |s|
20
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
- }
30
23
 
31
24
  s.required_ruby_version = '>= 2.5'
32
25
 
@@ -37,6 +30,7 @@ Gem::Specification.new do |s|
37
30
  s.add_development_dependency('pry-byebug', '~> 3')
38
31
  s.add_development_dependency('rake', '~> 13.0')
39
32
  s.add_development_dependency('rspec')
33
+ s.add_development_dependency('rspec_junit_formatter')
40
34
  s.add_development_dependency('rubocop', '~> 0.63.1')
41
35
  s.add_development_dependency('simplecov', '~>0.16.1')
42
36
  s.add_development_dependency('simplecov-console', '~>0.4.2')
@@ -0,0 +1,34 @@
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 is responsible for turning strings and symbols into constants.
12
+ # It does not deal with inflection, simply just constant resolution.
13
+ class ConstantResolver # :nodoc: all
14
+ # Only use Module constant resolution if a string or symbol was passed in.
15
+ # Any other type is defined as an acceptable constant and is simply returned.
16
+ def constantize(value)
17
+ value.is_a?(String) || value.is_a?(Symbol) ? object_constant(value) : value
18
+ end
19
+
20
+ private
21
+
22
+ # If the constant has been loaded, we can safely use it through const_get.
23
+ # If the constant has not been loaded, we need to defer to const_missing to resolve it.
24
+ # If we blindly call const_get, it may return false positives for namespaced constants
25
+ # or anything nested.
26
+ def object_constant(value)
27
+ if Object.const_defined?(value, false)
28
+ Object.const_get(value, false)
29
+ else
30
+ Object.const_missing(value)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -38,22 +38,22 @@ module ActsAsHashable
38
38
  end
39
39
  end
40
40
 
41
- def registry
41
+ def registry # :nodoc:
42
42
  @registry ||= {}
43
43
  end
44
44
 
45
- def materialize_registry
45
+ def materialize_registry # :nodoc:
46
46
  @registry.map do |k, v|
47
47
  value = v.is_a?(Proc) ? v.call(k) : v
48
48
  [k, value]
49
49
  end.to_h
50
50
  end
51
51
 
52
- def type_key(key)
52
+ def type_key(key) # :nodoc:
53
53
  @typed_with = key
54
54
  end
55
55
 
56
- def typed_with
56
+ def typed_with # :nodoc:
57
57
  @typed_with || TypeFactory::DEFAULT_TYPE_KEY
58
58
  end
59
59
 
@@ -10,7 +10,7 @@
10
10
  module ActsAsHashable
11
11
  # Let's provide a refinenment instead of monkey-patching Hash. That way we can stop
12
12
  # polluting other libraries and internalize our specific needs.
13
- module HashRefinements
13
+ module HashRefinements # :nodoc: all
14
14
  refine Hash do
15
15
  def symbolize_keys
16
16
  map { |k, v| [k.to_sym, v] }.to_h
@@ -7,6 +7,8 @@
7
7
  # LICENSE file in the root directory of this source tree.
8
8
  #
9
9
 
10
+ require_relative 'constant_resolver'
11
+
10
12
  module ActsAsHashable
11
13
  # A TypeFactory object understands how to build objects using a special designated 'type' key.
12
14
  class TypeFactory
@@ -17,8 +19,9 @@ module ActsAsHashable
17
19
  attr_reader :registry, :type_key
18
20
 
19
21
  def initialize(registry = {}, type_key = DEFAULT_TYPE_KEY)
20
- @registry = registry.symbolize_keys
21
- @type_key = type_key.to_s.to_sym
22
+ @constant_resolver = ConstantResolver.new
23
+ @registry = registry.symbolize_keys
24
+ @type_key = type_key.to_s.to_sym
22
25
 
23
26
  freeze
24
27
  end
@@ -34,9 +37,7 @@ module ActsAsHashable
34
37
  def make(config = {})
35
38
  config = (config || {}).symbolize_keys
36
39
  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
+ object_class = resolve_object_class(type)
40
41
 
41
42
  config_without_type = config.reject { |k| k == type_key }
42
43
 
@@ -47,5 +48,19 @@ module ActsAsHashable
47
48
 
48
49
  object_class.send(method_name, config_without_type)
49
50
  end
51
+
52
+ private
53
+
54
+ attr_reader :constant_resolver
55
+
56
+ def resolve_object_class(type)
57
+ object_class = registry[type]
58
+
59
+ raise ArgumentError, "cannot find registration for: '#{type}'" unless object_class
60
+
61
+ return object_class unless object_class.is_a?(String)
62
+
63
+ constant_resolver.constantize(object_class)
64
+ end
50
65
  end
51
66
  end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module ActsAsHashable
11
- VERSION = '1.2.0-alpha.1'
11
+ VERSION = '1.3.1'
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_hashable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre.alpha.1
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-09 00:00:00.000000000 Z
11
+ date: 2021-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caution
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -146,22 +160,23 @@ executables: []
146
160
  extensions: []
147
161
  extra_rdoc_files: []
148
162
  files:
163
+ - ".circleci/config.yml"
149
164
  - ".editorconfig"
150
165
  - ".gitignore"
151
166
  - ".rubocop.yml"
152
167
  - ".ruby-version"
153
- - ".travis.yml"
168
+ - ".tool-versions"
154
169
  - CHANGELOG.md
155
170
  - CODE_OF_CONDUCT.md
156
171
  - Gemfile
157
172
  - Guardfile
158
- - LICENSE
159
173
  - README.md
160
174
  - Rakefile
161
175
  - acts_as_hashable.gemspec
162
176
  - bin/console
163
177
  - exe/.gitkeep
164
178
  - lib/acts_as_hashable.rb
179
+ - lib/acts_as_hashable/constant_resolver.rb
165
180
  - lib/acts_as_hashable/factory.rb
166
181
  - lib/acts_as_hashable/hash_refinements.rb
167
182
  - lib/acts_as_hashable/hashable.rb
@@ -170,13 +185,8 @@ files:
170
185
  homepage: https://github.com/bluemarblepayroll/acts_as_hashable
171
186
  licenses:
172
187
  - MIT
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
179
- post_install_message:
188
+ metadata: {}
189
+ post_install_message:
180
190
  rdoc_options: []
181
191
  require_paths:
182
192
  - lib
@@ -187,12 +197,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
197
  version: '2.5'
188
198
  required_rubygems_version: !ruby/object:Gem::Requirement
189
199
  requirements:
190
- - - ">"
200
+ - - ">="
191
201
  - !ruby/object:Gem::Version
192
- version: 1.3.1
202
+ version: '0'
193
203
  requirements: []
194
204
  rubygems_version: 3.0.3
195
- signing_key:
205
+ signing_key:
196
206
  specification_version: 4
197
207
  summary: Simple hash-based factory methods for objects.
198
208
  test_files: []
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- env:
2
- global:
3
- - CC_TEST_REPORTER_ID=830db02445429888fcdd7d1406dd82e9b32535e863ac54a538a162c0c4acd4d1
4
- language: ruby
5
- rvm:
6
- # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
7
- - 2.5.8
8
- - 2.6.6
9
- - 2.7.1
10
- cache: bundler
11
- before_script:
12
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
- - chmod +x ./cc-test-reporter
14
- - ./cc-test-reporter before-build
15
- script:
16
- - bundle exec rubocop
17
- - bundle exec rspec
18
- after_script:
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/LICENSE DELETED
@@ -1,7 +0,0 @@
1
- Copyright 2018 Blue Marble Payroll, LLC
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.