deep_class_compare 1.0.3 → 1.0.4

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: 2a81d53c15eaa2641d219e497526761801eb20313976e5814481497451dda787
4
+ data.tar.gz: fbf943bc407f55f51621e7fb67f8f8aaa99924f5a83901ed7e11e849ee2ca77a
5
5
  SHA512:
6
- metadata.gz: 945b06a01324a61f10180ae6f42bddc15950b278bdcbeb04a5fe6e87d043b59a5c0adb683cbd045693d56abe1cb83b5cdc4a3d70351c6ce177d55414a9305069
7
- data.tar.gz: 31edaf6970388f51416445c5a631bc24c305c0e9c24f3b947c1bcfeb62df2c83e62297c4ee36184834048ce4f1e8ca20122be3364b6417861b4697a840fa1a90
6
+ metadata.gz: 2e7b4e3fe1f1bc61847215f5bca6221560f3805854fb3d6e73861876641bca20058e9ec0cd3bcbfb162bd7f6e1a78b6819cf7e1d275d5bae090b1612db236b75
7
+ data.tar.gz: f8792829f2d6528d7c2d60e0df5ed6e69b594e36611549268d2aac8182f27f2bc65384e15c14060115d7b607ef24a6f052e5a0adf934ddc2e90292228f2d1446
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deep_class_compare (1.0.2)
4
+ deep_class_compare (1.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- ```ruby
25
+ ```
26
26
  # Could compare container and value class with simple pattern
27
27
  ['string', 'string'].like_a? Array.of(String) => true
28
28
  [1, 2].like_a? Array.of(Hash) => false
@@ -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
@@ -6,23 +6,24 @@ module DeepClassCompare
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,7 +1,6 @@
1
1
  module DeepClassCompare
2
2
  class HashMatcher < Matcher
3
3
  include ContainerComparable
4
-
5
4
  def initialize
6
5
  super(Hash)
7
6
  end
@@ -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.0.4"
5
5
  end
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.0.4
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-26 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.
@@ -28,6 +28,7 @@ files:
28
28
  - Rakefile
29
29
  - bin/console
30
30
  - bin/setup
31
+ - deep_class_compare.gemspec
31
32
  - lib/deep_class_compare.rb
32
33
  - lib/deep_class_compare/array_matcher.rb
33
34
  - lib/deep_class_compare/container_comparable.rb