sinclair 1.16.0 → 1.16.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: 54cfb901ecd8185d00862d7c0b5a99e9cb626d2bbadf45db59553ae980ef9dc1
4
- data.tar.gz: 7f0f0a291a659fbc5eaa0d6b56a8bc0f2dfe08b3c0a0d290dad2a6136c7ccc53
3
+ metadata.gz: '0633819d57447ccb757e81a154d58e8b5c47ed5fb49a6b738b6e3b27801ceeb0'
4
+ data.tar.gz: 0b50ae42aa0c487d3ae12d5e2b0c0933b4cff0040d7635340d82a5122a038c47
5
5
  SHA512:
6
- metadata.gz: d788efed427695e2b001e7b38cc7fa4ef41fb8f6e6b855d321e88f24cb7c97b71b7f4d2622041a5f36ed9921b88513bb26beb4d3b0f11c37a19425a2d1698d9b
7
- data.tar.gz: 66f7170ee3a639fa43219f10f3c984369d72ac3e58f182ac00bf0fecf947efa0e5f25107cffa45db30048366085c7c329cd214b5ed5659d854af93f0588b264b
6
+ metadata.gz: a72bfc2c48a33ef60fa56a4a7dd8009a12737752ffa3075ef58a50f43968779155f95b095afc7b01d2f9172b2f6d88a2cdf1f2b1e010036686cdb4be7ae376fb
7
+ data.tar.gz: 3e0e0a9a8bc66d1d13c427895bd9473d1a984b30bd66a8fbc961d2f80d9f54910381a2ec6d3f1ab256590a9c6aaf559b71bba921f8c1bd2466501c02e835ced0
data/README.md CHANGED
@@ -15,13 +15,13 @@ create custom comparators, configure your application, create powerfull options,
15
15
 
16
16
  Employing Sinclair in your applications helps you streamline your development workflow and enhance your development process through more efficient, cleaner code
17
17
 
18
- Current Release: [1.16.0](https://github.com/darthjee/sinclair/tree/1.16.0)
18
+ Current Release: [1.16.1](https://github.com/darthjee/sinclair/tree/1.16.1)
19
19
 
20
- [Next release](https://github.com/darthjee/sinclair/compare/1.16.0...master)
20
+ [Next release](https://github.com/darthjee/sinclair/compare/1.16.1...master)
21
21
 
22
22
  Yard Documentation
23
23
  -------------------
24
- [https://www.rubydoc.info/gems/sinclair/1.16.0](https://www.rubydoc.info/gems/sinclair/1.16.0)
24
+ [https://www.rubydoc.info/gems/sinclair/1.16.1](https://www.rubydoc.info/gems/sinclair/1.16.1)
25
25
 
26
26
  Installation
27
27
  ---------------
data/config/yardstick.yml CHANGED
@@ -57,6 +57,7 @@ rules:
57
57
  - Sinclair::EnvSettable::Builder#initialize
58
58
  - Sinclair::Exception::InvalidOptions#initialize
59
59
  - Sinclair::EqualsChecker#initialize
60
+ - Sinclair::EqualsChecker::Reader#initialize
60
61
  - Sinclair::InputHash#initialize
61
62
  - Sinclair::Matchers::AddInstanceMethodTo#initialize
62
63
  - Sinclair::Matchers::AddClassMethodTo#initialize
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Sinclair
4
+ class EqualsChecker
5
+ # @api private
6
+ # @author darthjee
7
+ #
8
+ # Class capable of reading an attribute from models
9
+ class Reader
10
+ # @private
11
+ # @api private
12
+ #
13
+ # Checks if two attributes from 2 object match
14
+ #
15
+ # @param attribute [Symbol] attribute name
16
+ # @param model [Object] object to be compared with other
17
+ # @param other [Object] object to be compared with model
18
+ #
19
+ # @see #match?
20
+ # @return [TrueClass,FalseClass]
21
+ def self.attributes_match?(attribute, model, other)
22
+ reader = new(attribute)
23
+
24
+ reader.read_from(model) == reader.read_from(other)
25
+ end
26
+
27
+ # @param attribute [Symbol] name of the attribute (method or variable)
28
+ # to be accessed in the models
29
+ def initialize(attribute)
30
+ @attribute = attribute
31
+ end
32
+
33
+ # Reads the +attribute+ from the model
34
+ #
35
+ # When attribute is a method name, calls that method on the model
36
+ #
37
+ # When attribute is an instance variable name, that is read directly from the model
38
+ #
39
+ # @param model [Object] the model to be read
40
+ #
41
+ # @return [Object]
42
+ def read_from(model)
43
+ return model.send(attribute) unless attribute.to_s.match?(/^@.*/)
44
+
45
+ model.instance_variable_get(attribute)
46
+ end
47
+
48
+ private
49
+
50
+ # @attr_reader :attribute
51
+ #
52
+ # Reads the attribute that will be used to extract the value
53
+ #
54
+ # @return [Symbol]
55
+ attr_reader :attribute
56
+ end
57
+ end
58
+ end
@@ -50,6 +50,8 @@ class Sinclair
50
50
  #
51
51
  # checker.match?(model1, model2) # returns false
52
52
  class EqualsChecker
53
+ autoload :Reader, 'sinclair/equals_checker/reader'
54
+
53
55
  # @param attributes [Array<Symbol,String>] list of relevant attributes
54
56
  def initialize(*attributes)
55
57
  @attributes = Set.new(attributes.flatten)
@@ -91,7 +93,7 @@ class Sinclair
91
93
  return false unless model.class == other.class
92
94
 
93
95
  attributes.all? do |attr|
94
- model.send(attr) == other.send(attr)
96
+ Reader.attributes_match?(attr, model, other)
95
97
  end
96
98
  end
97
99
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinclair
4
- VERSION = '1.16.0'
4
+ VERSION = '1.16.1'
5
5
  end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Sinclair::EqualsChecker::Reader do
6
+ subject(:reader) { described_class.new(attribute) }
7
+
8
+ let(:attribute) { :information }
9
+ let(:model) { SampleModel.new(name: name, age: age) }
10
+ let(:name) { 'The Name' }
11
+ let(:age) { 25 }
12
+
13
+ describe '.attributes_match?' do
14
+ let(:other) { SampleModel.new(name: other_name) }
15
+ let(:attribute) { :name }
16
+
17
+ context 'when the value match' do
18
+ let(:other_name) { name }
19
+
20
+ it do
21
+ expect(described_class)
22
+ .to be_attributes_match(attribute, model, other)
23
+ end
24
+ end
25
+
26
+ context 'when the value does not match' do
27
+ let(:other_name) { 'Other Name' }
28
+
29
+ it do
30
+ expect(described_class)
31
+ .not_to be_attributes_match(attribute, model, other)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#read_from' do
37
+ context 'when reading from a method' do
38
+ it 'returns the value from the method' do
39
+ expect(reader.read_from(model)).to eq('The Name: 25 yo')
40
+ end
41
+ end
42
+
43
+ context 'when reading from a variable' do
44
+ let(:attribute) { :@inner_variable }
45
+
46
+ before do
47
+ model.instance_variable_set(:@inner_variable, 301)
48
+ end
49
+
50
+ it 'returns the value from the variable' do
51
+ expect(reader.read_from(model)).to eq(301)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -119,6 +119,18 @@ describe Sinclair::EqualsChecker do
119
119
  end
120
120
  end
121
121
  end
122
+
123
+ context 'when one of the attributes is an instance variable' do
124
+ let(:attributes) { %i[name @age] }
125
+
126
+ context 'when the instance variable is different and the method the same' do
127
+ let(:name2) { name1 }
128
+
129
+ it do
130
+ expect(checker).not_to be_match(model1, model2)
131
+ end
132
+ end
133
+ end
122
134
  end
123
135
 
124
136
  describe '#add' do
@@ -6,6 +6,10 @@ class SampleModel
6
6
  @age = age
7
7
  end
8
8
 
9
+ def information
10
+ "#{name}: #{age} yo"
11
+ end
12
+
9
13
  protected
10
14
 
11
15
  attr_reader :name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinclair
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
@@ -288,6 +288,7 @@ files:
288
288
  - lib/sinclair/env_settable.rb
289
289
  - lib/sinclair/env_settable/builder.rb
290
290
  - lib/sinclair/equals_checker.rb
291
+ - lib/sinclair/equals_checker/reader.rb
291
292
  - lib/sinclair/exception.rb
292
293
  - lib/sinclair/input_hash.rb
293
294
  - lib/sinclair/matchers.rb
@@ -380,6 +381,7 @@ files:
380
381
  - spec/lib/sinclair/core_ext/object_spec.rb
381
382
  - spec/lib/sinclair/env_settable/builder_spec.rb
382
383
  - spec/lib/sinclair/env_settable_spec.rb
384
+ - spec/lib/sinclair/equals_checker/reader_spec.rb
383
385
  - spec/lib/sinclair/equals_checker_spec.rb
384
386
  - spec/lib/sinclair/exception/invalid_options_spec.rb
385
387
  - spec/lib/sinclair/input_hash_spec.rb
@@ -455,13 +457,13 @@ files:
455
457
  - spec/support/models/purchase.rb
456
458
  - spec/support/models/random_generator.rb
457
459
  - spec/support/models/ruby_string_caster.rb
460
+ - spec/support/models/sample_model.rb
458
461
  - spec/support/models/server.rb
459
462
  - spec/support/models/server_config.rb
460
463
  - spec/support/models/service_client.rb
461
464
  - spec/support/models/string_parser.rb
462
465
  - spec/support/models/tv.rb
463
466
  - spec/support/models/validator_builder.rb
464
- - spec/support/sample_model.rb
465
467
  - spec/support/shared_examples/attribute_accessor.rb
466
468
  - spec/support/shared_examples/class_method_definition.rb
467
469
  - spec/support/shared_examples/config.rb