acts_as_hashable 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 217324e6b005f92191c5cef6ea14dadc12defe0d
4
- data.tar.gz: a1bb063e19bfc8b0a3ca0f88b70abad248874ccb
3
+ metadata.gz: aeda82e04843a1f805a0e056f3a1a988cf3fa624
4
+ data.tar.gz: 129e4222c77d0527b9932d36761a354b7e237f3f
5
5
  SHA512:
6
- metadata.gz: 33170c36d1877dd1bbd66a750ed8411cc79a7e4f9d78af9b69e0f058115ee105a7652f6a4eede7a7052949be257110be449f6c1d2308d90dfb0363c5802eddd3
7
- data.tar.gz: 279f2504eb4139cd5d5c4eb3f92b0bf72f85be84bc8a005a55cebcc76f2b453553be2dc376033cc2e186d3719d43c86dff21b6e9cf5035c5296a6f1a68d72414
6
+ metadata.gz: 70e823f2d22dc978bdc537c6bf3f74163daa796db9035f6dd3afb49d30868974f475626d14d0e046d121428efb2acca4889771f03532bb73354c20391e23feb2
7
+ data.tar.gz: c5520831734e879970e1abea57eead97a92794345d8d0ac6c1fc40990ba9e641fef2b983b16aa7e438d1e43fb24bac2751dd8b9d29f4fad7f2f553b29500766e
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics/LineLength:
4
+ Max: 100
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,50 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-09-27 15:44:50 -0500 using RuboCop version 0.59.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 5
10
+ # Configuration parameters: CountComments, ExcludedMethods.
11
+ # ExcludedMethods: refine
12
+ Metrics/BlockLength:
13
+ Max: 128
14
+
15
+ # Offense count: 1
16
+ Metrics/CyclomaticComplexity:
17
+ Max: 7
18
+
19
+ # Offense count: 1
20
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
21
+ # URISchemes: http, https
22
+ Metrics/LineLength:
23
+ Max: 105
24
+
25
+ # Offense count: 1
26
+ # Configuration parameters: CountComments, ExcludedMethods.
27
+ Metrics/MethodLength:
28
+ Max: 11
29
+
30
+ # Offense count: 1
31
+ Metrics/PerceivedComplexity:
32
+ Max: 8
33
+
34
+ # Offense count: 1
35
+ Style/DoubleNegation:
36
+ Exclude:
37
+ - 'lib/acts_as_hashable/hashable.rb'
38
+
39
+ # Offense count: 1
40
+ # Cop supports --auto-correct.
41
+ # Configuration parameters: InverseMethods, InverseBlocks.
42
+ Style/InverseMethods:
43
+ Exclude:
44
+ - 'lib/acts_as_hashable/hashable.rb'
45
+
46
+ # Offense count: 1
47
+ # Cop supports --auto-correct.
48
+ Style/RescueModifier:
49
+ Exclude:
50
+ - 'lib/acts_as_hashable/utilities.rb'
data/.travis.yml CHANGED
@@ -4,4 +4,5 @@ rvm:
4
4
  - 2.3.7
5
5
  cache: bundler
6
6
  script:
7
+ - bundle exec rubocop
7
8
  - bundle exec rspec
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,12 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acts_as_hashable (1.0.2)
4
+ acts_as_hashable (1.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ast (2.4.0)
9
10
  diff-lcs (1.3)
11
+ jaro_winkler (1.5.1)
12
+ parallel (1.12.1)
13
+ parser (2.5.1.2)
14
+ ast (~> 2.4.0)
15
+ powerpack (0.1.2)
16
+ rainbow (3.0.0)
10
17
  rspec (3.8.0)
11
18
  rspec-core (~> 3.8.0)
12
19
  rspec-expectations (~> 3.8.0)
@@ -20,6 +27,16 @@ GEM
20
27
  diff-lcs (>= 1.2.0, < 2.0)
21
28
  rspec-support (~> 3.8.0)
22
29
  rspec-support (3.8.0)
30
+ rubocop (0.59.2)
31
+ jaro_winkler (~> 1.5.1)
32
+ parallel (~> 1.10)
33
+ parser (>= 2.5, != 2.5.1.1)
34
+ powerpack (~> 0.1)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ ruby-progressbar (~> 1.7)
37
+ unicode-display_width (~> 1.0, >= 1.0.1)
38
+ ruby-progressbar (1.10.0)
39
+ unicode-display_width (1.4.0)
23
40
 
24
41
  PLATFORMS
25
42
  ruby
@@ -27,6 +44,7 @@ PLATFORMS
27
44
  DEPENDENCIES
28
45
  acts_as_hashable!
29
46
  rspec
47
+ rubocop (~> 0.59.2)
30
48
 
31
49
  BUNDLED WITH
32
50
  1.16.3
@@ -1,25 +1,28 @@
1
- require "./lib/acts_as_hashable/version"
1
+ # frozen_string_literal: true
2
+
3
+ require './lib/acts_as_hashable/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
6
  s.name = 'acts_as_hashable'
5
7
  s.version = ActsAsHashable::VERSION
6
- s.summary = "Simple hash-based factory methods for objects."
8
+ s.summary = 'Simple hash-based factory methods for objects.'
7
9
 
8
- s.description = <<-EOS
10
+ s.description = <<-DESCRIPTION
9
11
  This is a small library that helps increase the pliability of object constructor signatures.
10
12
  Instead of instantiating via the constructor, this library can install helper factory
11
13
  class-level methods that you can use with hashes.
12
- EOS
14
+ DESCRIPTION
13
15
 
14
- s.authors = [ 'Matthew Ruggio' ]
15
- s.email = [ 'mruggio@bluemarblepayroll.com' ]
16
+ s.authors = ['Matthew Ruggio']
17
+ s.email = ['mruggio@bluemarblepayroll.com']
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
21
  s.homepage = 'https://github.com/bluemarblepayroll/acts_as_hashable'
20
22
  s.license = 'MIT'
21
23
 
22
24
  s.required_ruby_version = '>= 2.3.1'
23
25
 
24
26
  s.add_development_dependency('rspec')
27
+ s.add_development_dependency('rubocop', '~> 0.59.2')
25
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -9,6 +11,7 @@ require_relative 'utilities'
9
11
  require_relative 'hashable'
10
12
 
11
13
  module ActsAsHashable
14
+ # This module adds the class-level method that marks a class as hashable.
12
15
  module DslHook
13
16
  def acts_as_hashable
14
17
  extend ::ActsAsHashable::Hashable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,31 +8,27 @@
6
8
  #
7
9
 
8
10
  module ActsAsHashable
11
+ # This class contains the main set of class-level methods that can be used by
12
+ # hashable classes.
9
13
  module Hashable
10
-
11
14
  def array(object, nullable: true)
12
- if object.is_a?(Hash)
13
- objects = [ object ]
14
- else
15
- objects = Array(object)
16
- end
15
+ objects = object.is_a?(Hash) ? [object] : Array(object)
17
16
 
18
17
  objects.select { |o| !!o }.map { |o| make(o, nullable: nullable) }
19
18
  end
20
19
 
21
20
  def make(object, nullable: true)
22
21
  if object.is_a?(Hash)
23
- self.new(**::ActsAsHashable::Utilities.symbolize_keys(object))
22
+ new(**::ActsAsHashable::Utilities.symbolize_keys(object))
24
23
  elsif object.is_a?(self)
25
24
  object
26
25
  elsif object.nil? && nullable
27
26
  nil
28
27
  elsif object.nil? && !nullable
29
- self.new
28
+ new
30
29
  else
31
30
  raise "Cannot create hashable object with class name: #{object.class.name}"
32
31
  end
33
32
  end
34
-
35
33
  end
36
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,9 +8,10 @@
6
8
  #
7
9
 
8
10
  module ActsAsHashable
11
+ # Some extra functions that are either ancillary to the main domain or polyfill other
12
+ # mainstream imnplementations.
9
13
  class Utilities
10
14
  class << self
11
-
12
15
  # https://apidock.com/rails/Hash/symbolize_keys
13
16
  def symbolize_keys(hash)
14
17
  transform_keys(hash) { |key| key.to_sym rescue key }
@@ -26,7 +29,6 @@ module ActsAsHashable
26
29
 
27
30
  result
28
31
  end
29
-
30
32
  end
31
33
  end
32
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,5 +8,5 @@
6
8
  #
7
9
 
8
10
  module ActsAsHashable
9
- VERSION = "1.0.2"
11
+ VERSION = '1.0.3'
10
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Copyright (c) 2018-present, Blue Marble Payroll, LLC
3
5
  #
@@ -6,68 +8,12 @@
6
8
  #
7
9
 
8
10
  require './lib/acts_as_hashable'
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
11
+ require './spec/examples'
63
12
 
64
13
  describe ActsAsHashable do
65
14
  context '#make' do
66
-
67
15
  context 'with a hash constructor interface' do
68
-
69
16
  it 'should properly instantiate objects from a symbol-keyed hash' do
70
-
71
17
  pet = {
72
18
  name: 'Doug the dog',
73
19
  toy: { squishy: true }
@@ -78,20 +24,18 @@ describe ActsAsHashable do
78
24
  expect(pet_obj.name).to eq('Doug the dog')
79
25
  expect(pet_obj.toy.squishy).to be true
80
26
  end
81
-
82
27
  end
83
28
 
84
29
  context 'with keyword arguments interface' do
85
-
86
30
  it 'should properly instantiate objects from symbol-keyed hash' do
87
31
  head_of_household = {
88
32
  person: {
89
33
  name: 'Matt',
90
- age: 109,
34
+ age: 109
91
35
  },
92
36
  partner: {
93
37
  name: 'Katie',
94
- age: 110,
38
+ age: 110
95
39
  }
96
40
  }
97
41
 
@@ -107,11 +51,11 @@ describe ActsAsHashable do
107
51
  head_of_household = {
108
52
  'person' => {
109
53
  'name' => 'Matt',
110
- 'age' => 109,
54
+ 'age' => 109
111
55
  },
112
56
  'partner' => {
113
57
  'name' => 'Katie',
114
- 'age' => 110,
58
+ 'age' => 110
115
59
  }
116
60
  }
117
61
 
@@ -127,11 +71,11 @@ describe ActsAsHashable do
127
71
  head_of_household = {
128
72
  person: {
129
73
  # name: 'Matt',
130
- age: 109,
74
+ age: 109
131
75
  },
132
76
  partner: {
133
77
  name: 'Katie',
134
- age: 110,
78
+ age: 110
135
79
  }
136
80
  }
137
81
 
@@ -143,36 +87,34 @@ describe ActsAsHashable do
143
87
  person: {
144
88
  name: 'Matt',
145
89
  age: 109,
146
- height_in_inches: 700,
90
+ height_in_inches: 700
147
91
  },
148
92
  partner: {
149
93
  name: 'Katie',
150
- age: 110,
94
+ age: 110
151
95
  }
152
96
  }
153
97
 
154
98
  expect { HeadOfHousehold.make(head_of_household) }.to raise_error(ArgumentError)
155
99
  end
156
-
157
100
  end
158
101
 
159
102
  context '#array' do
160
-
161
- it 'should properly instantiate objects and arrays of objects from symbol-keyed hash and arrays' do
103
+ it 'should properly create objects and arrays of objects from symbol-keyed hash and arrays' do
162
104
  family = {
163
105
  head_of_household: {
164
106
  person: {
165
107
  name: 'Matt',
166
- age: 109,
108
+ age: 109
167
109
  },
168
110
  partner: {
169
111
  name: 'Katie',
170
- age: 110,
112
+ age: 110
171
113
  }
172
114
  },
173
115
  children: [
174
116
  { name: 'Martin', age: 29 },
175
- { name: 'Short', age: 99 },
117
+ { name: 'Short', age: 99 }
176
118
  ]
177
119
  }
178
120
 
@@ -195,11 +137,11 @@ describe ActsAsHashable do
195
137
  head_of_household: {
196
138
  person: {
197
139
  name: 'Matt',
198
- age: 109,
140
+ age: 109
199
141
  },
200
142
  partner: {
201
143
  name: 'Katie',
202
- age: 110,
144
+ age: 110
203
145
  }
204
146
  },
205
147
  children: { name: 'Martin', age: 29 }
@@ -216,7 +158,6 @@ describe ActsAsHashable do
216
158
  expect(family_obj.children[0].name).to eq('Martin')
217
159
  expect(family_obj.children[0].age).to eq(29)
218
160
  end
219
-
220
161
  end
221
162
  end
222
163
  end
data/spec/examples.rb ADDED
@@ -0,0 +1,62 @@
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
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.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.59.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.59.2
27
41
  description: |2
28
42
  This is a small library that helps increase the pliability of object constructor signatures.
29
43
  Instead of instantiating via the constructor, this library can install helper factory
@@ -36,6 +50,8 @@ extra_rdoc_files: []
36
50
  files:
37
51
  - ".editorconfig"
38
52
  - ".gitignore"
53
+ - ".rubocop.yml"
54
+ - ".rubocop_todo.yml"
39
55
  - ".ruby-version"
40
56
  - ".travis.yml"
41
57
  - Gemfile
@@ -49,6 +65,7 @@ files:
49
65
  - lib/acts_as_hashable/utilities.rb
50
66
  - lib/acts_as_hashable/version.rb
51
67
  - spec/acts_as_hashable_spec.rb
68
+ - spec/examples.rb
52
69
  homepage: https://github.com/bluemarblepayroll/acts_as_hashable
53
70
  licenses:
54
71
  - MIT
@@ -75,3 +92,4 @@ specification_version: 4
75
92
  summary: Simple hash-based factory methods for objects.
76
93
  test_files:
77
94
  - spec/acts_as_hashable_spec.rb
95
+ - spec/examples.rb