deep_class_compare 1.0.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6727cb333485bd308ec54f9b8a370ca4cf26188fa5c4c9fb11a3bccae3c00023
4
- data.tar.gz: 7b8c6c2bfe125d67fefcbbfe3a4596fd416b158fdfd899ad11cc68b0ec7d3a3d
3
+ metadata.gz: d1314a84c10e3451db03f8f7ae49d30882d3141ca195fdc814d32be8106a7ab7
4
+ data.tar.gz: 3d588cad72468cbc5e4f228883277e9d43151487298985a8e672be3171b0db7a
5
5
  SHA512:
6
- metadata.gz: 945b06a01324a61f10180ae6f42bddc15950b278bdcbeb04a5fe6e87d043b59a5c0adb683cbd045693d56abe1cb83b5cdc4a3d70351c6ce177d55414a9305069
7
- data.tar.gz: 31edaf6970388f51416445c5a631bc24c305c0e9c24f3b947c1bcfeb62df2c83e62297c4ee36184834048ce4f1e8ca20122be3364b6417861b4697a840fa1a90
6
+ metadata.gz: 006b39582ee835dcc33164c4af63518d24082293da5c3545a6e0b65ba9006f0c96760c5b59f05f7a3444e104b0bd4e355f41131231da63d99936cc5e6aeb10bf
7
+ data.tar.gz: 47f013d36af50c17c167f2ddb19821bb19ce131f9929fb046314988fbeb9abbc0a03c2a38d3e1b1de2e1731807b2d4010a3b09a0ba677b42e8322c8491e3f24b
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/deep_class_compare/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "deep_class_compare"
7
+ spec.version = DeepClassCompare::VERSION
8
+ spec.authors = ["Koten"]
9
+ spec.email = ["koten0224@gmail.com"]
10
+
11
+ spec.summary = "Deep class compare"
12
+ spec.description = "A container class extend gem that could compare the values class in it easily, clearly, and more colloquialism."
13
+ spec.homepage = "https://github.com/koten0224/deep_class_compare"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.2.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/koten0224/deep_class_compare"
21
+ spec.metadata["changelog_uri"] = "https://github.com/koten0224/deep_class_compare/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -1,28 +1,29 @@
1
1
  module DeepClassCompare
2
2
  class ArrayMatcher < Matcher
3
3
  include ContainerComparable
4
- def initialize
5
- super(Array)
4
+ def initialize(klass = Array)
5
+ super(klass)
6
6
  end
7
7
 
8
8
  def match?(array)
9
- # p @chain
10
9
  super && compare_array_with_chain(array)
11
10
  end
12
11
 
13
12
  def of(*comparable)
14
13
  dup.tap do |matcher|
15
- matcher.instance_eval do
16
- @chain = if @chain.nil?
17
- parse_comparable_to_chain(comparable.first)
18
- elsif @chain.is_a?(Matcher)
19
- @chain.of(*comparable)
20
- end
21
- raise_pattern_error! if @chain.nil?
22
- end
14
+ matcher.build_chain(*comparable)
23
15
  end
24
16
  end
25
17
 
18
+ def build_chain(*comparable)
19
+ @chain = if @chain.nil?
20
+ parse_comparable_to_chain(comparable.first)
21
+ elsif @chain.is_a?(Matcher)
22
+ @chain.of(*comparable)
23
+ end
24
+ raise_pattern_error! if @chain.nil?
25
+ end
26
+
26
27
  private
27
28
  def compare_array_with_chain(array)
28
29
  array.all? do |value|
@@ -13,7 +13,7 @@ module DeepClassCompare
13
13
  case comparable
14
14
  when Matcher then comparable
15
15
  when Array then parse_array_to_chain(comparable)
16
- when Class then parse_class_to_matcher(comparable)
16
+ when Class then Matcher.build(comparable)
17
17
  else raise_pattern_error!
18
18
  end
19
19
  end
@@ -28,12 +28,5 @@ module DeepClassCompare
28
28
  end
29
29
  end
30
30
  end
31
-
32
- def parse_class_to_matcher(klass)
33
- if klass == Array then ArrayMatcher.new
34
- elsif klass == Hash then HashMatcher.new
35
- else Matcher.new(klass)
36
- end
37
- end
38
31
  end
39
32
  end
@@ -1,9 +1,8 @@
1
1
  module DeepClassCompare
2
2
  class HashMatcher < Matcher
3
3
  include ContainerComparable
4
-
5
- def initialize
6
- super(Hash)
4
+ def initialize(klass = Hash)
5
+ super(klass)
7
6
  end
8
7
 
9
8
  def match?(hash)
@@ -11,16 +10,18 @@ module DeepClassCompare
11
10
  end
12
11
 
13
12
  def of(key_comparable, value_comparable = nil)
14
- key_comparable, value_comparable = Object, key_comparable if value_comparable.nil?
13
+ raise_pattern_error! unless @key_chain.nil? && @value_chain.nil?
15
14
  dup.tap do |matcher|
16
- matcher.instance_eval do
17
- raise_pattern_error! unless @key_chain.nil? && @value_chain.nil?
18
- @key_chain = parse_comparable_to_chain(key_comparable)
19
- @value_chain = parse_comparable_to_chain(value_comparable)
20
- end
15
+ matcher.build_chain(key_comparable, value_comparable)
21
16
  end
22
17
  end
23
18
 
19
+ def build_chain(key_comparable, value_comparable = nil)
20
+ key_comparable, value_comparable = Object, key_comparable if value_comparable.nil?
21
+ @key_chain = parse_comparable_to_chain(key_comparable)
22
+ @value_chain = parse_comparable_to_chain(value_comparable)
23
+ end
24
+
24
25
  private
25
26
  def compare_hash_with_chain(hash)
26
27
  hash.all? do |key, value|
@@ -1,5 +1,12 @@
1
1
  module DeepClassCompare
2
2
  class Matcher
3
+ def self.build(klass)
4
+ if klass == Array then ArrayMatcher.new
5
+ elsif klass == Hash then HashMatcher.new
6
+ else new(klass)
7
+ end
8
+ end
9
+
3
10
  def initialize(base)
4
11
  @base = base
5
12
  raise_class_required_error! unless @base.is_a?(Class)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepClassCompare
4
- VERSION = "1.0.3"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -12,14 +12,14 @@ end
12
12
 
13
13
  class Array
14
14
  def self.of(value_comparable)
15
- DeepClassCompare::ArrayMatcher.new.of(value_comparable)
15
+ DeepClassCompare::ArrayMatcher.new(self).of(value_comparable)
16
16
  end
17
17
  end
18
18
 
19
19
  class Hash
20
20
  def self.of(key_comparable, value_comparable = nil)
21
21
  key_comparable, value_comparable = Object, key_comparable if value_comparable.nil?
22
- DeepClassCompare::HashMatcher.new.of(key_comparable, value_comparable)
22
+ DeepClassCompare::HashMatcher.new(self).of(key_comparable, value_comparable)
23
23
  end
24
24
  end
25
25
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_class_compare
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koten
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-25 00:00:00.000000000 Z
11
+ date: 2021-12-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A container class extend gem that could compare the values class in it
14
14
  easily, clearly, and more colloquialism.
@@ -22,12 +22,12 @@ files:
22
22
  - CHANGELOG.md
23
23
  - CODE_OF_CONDUCT.md
24
24
  - Gemfile
25
- - Gemfile.lock
26
25
  - LICENSE.txt
27
26
  - README.md
28
27
  - Rakefile
29
28
  - bin/console
30
29
  - bin/setup
30
+ - deep_class_compare.gemspec
31
31
  - lib/deep_class_compare.rb
32
32
  - lib/deep_class_compare/array_matcher.rb
33
33
  - lib/deep_class_compare/container_comparable.rb
data/Gemfile.lock DELETED
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- deep_class_compare (1.0.2)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.4.4)
10
- rake (13.0.3)
11
- rspec (3.9.0)
12
- rspec-core (~> 3.9.0)
13
- rspec-expectations (~> 3.9.0)
14
- rspec-mocks (~> 3.9.0)
15
- rspec-core (3.9.2)
16
- rspec-support (~> 3.9.3)
17
- rspec-expectations (3.9.2)
18
- diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.9.0)
20
- rspec-mocks (3.9.1)
21
- diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.9.0)
23
- rspec-support (3.9.3)
24
-
25
- PLATFORMS
26
- x86_64-darwin-18
27
-
28
- DEPENDENCIES
29
- deep_class_compare!
30
- rake (~> 13.0)
31
- rspec (~> 3.0)
32
-
33
- BUNDLED WITH
34
- 2.3.0