rggen-core 0.18.0 → 0.19.0

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: a3d870cf0f36dd58dd0f6b8916139330c671669bee9bca328f1e980915d0ecd8
4
- data.tar.gz: d637d69bf089c9f4092bb9891dc6cb4c81c682620728868878b83d88daf80dbe
3
+ metadata.gz: 07b141658bda7d5c43afba30ecbff539ab05beb383844f5a5b8fc9d9b605ebb5
4
+ data.tar.gz: faac4148e8c6c2e1bfa2632e1e1a589139db03280e3d25af8d39a1172708950e
5
5
  SHA512:
6
- metadata.gz: b9cab065f30c61edd6a60005019502d60f00ec8c796232a6fdaa50cf000927bdb7aaebbdcf0e558bc1c1d71fde256a2f4ebf451cdb13aab65dde548c70226383
7
- data.tar.gz: c4134d3eee4fbeb0b23c922a4108cd8878c80ee21164947cf6bd8905c871d109b5f70098822c0838cc02482353eea19ac0a218dcdc5f1b685840a12c04f09616
6
+ metadata.gz: 4838ab9d430ae360da7d223db91171e4460221ecec07e8ed475053eec91ed3a6af1ac10f62350731fb9593e34d7c332f135e68d4d459290cc440b9c7b882065e
7
+ data.tar.gz: 696f4186513d88b855434a295182dea303b54c52b6a04c251bb8a8dd2910bbeb42147abd9dfe292e28e42c91e4aba4971901490895b3685d375a18c988dd9d70
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2019 Taichi Ishitani
3
+ Copyright (c) 2017-2020 Taichi Ishitani
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/rggen-core.svg)](https://badge.fury.io/rb/rggen-core)
2
- [![Build Status](https://travis-ci.com/rggen/rggen-core.svg?branch=master)](https://travis-ci.com/rggen/rggen-core)
2
+ [![CI](https://github.com/rggen/rggen-core/workflows/CI/badge.svg)](https://github.com/rggen/rggen-core/actions?query=workflow%3ACI)
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/53c8e6654c2b5ecb9142/maintainability)](https://codeclimate.com/github/rggen/rggen-core/maintainability)
4
4
  [![codecov](https://codecov.io/gh/rggen/rggen-core/branch/master/graph/badge.svg)](https://codecov.io/gh/rggen/rggen-core)
5
5
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=rggen_rggen-core&metric=alert_status)](https://sonarcloud.io/dashboard?id=rggen_rggen-core)
@@ -43,7 +43,7 @@ Feedbacks, bug reports, questions and etc. are wellcome! You can post them by us
43
43
 
44
44
  ## Copyright & License
45
45
 
46
- Copyright © 2017-2019 Taichi Ishitani. RgGen::Core is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
46
+ Copyright © 2017-2020 Taichi Ishitani. RgGen::Core is licensed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE](LICENSE) for futher details.
47
47
 
48
48
  ## Code of Conduct
49
49
 
data/lib/rggen/core.rb CHANGED
@@ -13,7 +13,6 @@ require 'yaml'
13
13
  require_relative 'core/version'
14
14
 
15
15
  require_relative 'core/facets'
16
- require_relative 'core/core_extensions/casecmp'
17
16
  require_relative 'core/core_extensions/object'
18
17
 
19
18
  require_relative 'core/utility/attribute_setter'
@@ -44,7 +44,7 @@ module RgGen
44
44
 
45
45
  def input_pattern(pattern_or_patterns, **options, &converter)
46
46
  @input_matcher =
47
- InputMatcher.new(pattern_or_patterns, options, &converter)
47
+ InputMatcher.new(pattern_or_patterns, **options, &converter)
48
48
  end
49
49
 
50
50
  attr_reader :input_matcher
@@ -4,7 +4,7 @@ module RgGen
4
4
  module Core
5
5
  module InputBase
6
6
  class InputMatcher
7
- def initialize(pattern_or_patterns, options, &converter)
7
+ def initialize(pattern_or_patterns, **options, &converter)
8
8
  @options = options
9
9
  @converter = converter
10
10
  @patterns = format_patterns(pattern_or_patterns)
@@ -22,23 +22,22 @@ module RgGen
22
22
 
23
23
  private
24
24
 
25
- def format_patterns(patterns)
25
+ def format_patterns(pattern_or_patterns)
26
26
  if @options.fetch(:match_wholly, true)
27
- patterns_hash(patterns)
28
- .map { |i, pattern| [i, /\A#{pattern}\z/] }
29
- .to_h
27
+ expand_patterns(pattern_or_patterns)
28
+ .transform_values { |pattern| /\A#{pattern}\z/ }
30
29
  else
31
- patterns_hash(patterns)
30
+ expand_patterns(pattern_or_patterns)
32
31
  end
33
32
  end
34
33
 
35
- def patterns_hash(patterns)
36
- if patterns.is_a?(Hash)
37
- patterns
38
- else
39
- Array(patterns)
40
- .map.with_index { |pattern, i| [i, pattern] }
41
- .to_h
34
+ def expand_patterns(pattern_or_patterns)
35
+ Array(pattern_or_patterns).each_with_object({}) do |pattern, patterns|
36
+ if pattern.is_a? Hash
37
+ patterns.update(pattern)
38
+ else
39
+ patterns[patterns.size] = pattern
40
+ end
42
41
  end
43
42
  end
44
43
 
@@ -62,11 +61,11 @@ module RgGen
62
61
  end
63
62
 
64
63
  def match_patterns(rhs)
65
- match_data, index =
64
+ index, match_data =
66
65
  @patterns
67
- .map { |i, pattern| pattern.match(rhs) { |m| [m, i] } }
66
+ .transform_values { |pattern| pattern.match(rhs) }
68
67
  .compact
69
- .max { |m| m[0].length }
68
+ .max_by { |_, m| m[0].length }
70
69
  match_data && [convert_match_data(match_data), index]
71
70
  end
72
71
 
@@ -6,34 +6,38 @@ module RgGen
6
6
  module YAMLLoader
7
7
  private
8
8
 
9
- def load_yaml(file)
10
- result = yaml_safe_load(File.binread(file), file)
11
- symbolize_key(result)
12
- end
13
-
14
- if Psych::VERSION >= '3.1.0'
9
+ if RUBY_VERSION >= '2.6.0'
15
10
  def yaml_safe_load(yaml, file)
16
11
  YAML.safe_load(
17
12
  yaml,
18
- permitted_classes: [Symbol], aliases: true, filename: file
13
+ permitted_classes: [Symbol], aliases: true, filename: file,
14
+ symbolize_names: true
19
15
  )
20
16
  end
17
+ elsif RUBY_VERSION >= '2.5.0'
18
+ def yaml_safe_load(yaml, file)
19
+ YAML.safe_load(yaml, [Symbol], [], true, file, symbolize_names: true)
20
+ end
21
21
  else
22
22
  def yaml_safe_load(yaml, file)
23
- YAML.safe_load(yaml, [Symbol], [], true, file)
23
+ reuslt = YAML.safe_load(yaml, [Symbol], [], true, file)
24
+ symbolize_keys(reuslt)
24
25
  end
25
- end
26
26
 
27
- def symbolize_key(result)
28
- case result
29
- when Hash
30
- result.keys.each do |key|
31
- result[key.to_sym] = symbolize_key(result.delete(key))
27
+ def symbolize_keys(result)
28
+ if result.is_a? Hash
29
+ result.keys.each do |key|
30
+ result[key.to_sym] = symbolize_keys(result.delete(key))
31
+ end
32
+ elsif result.is_a? Array
33
+ result.map! { |value| symbolize_keys(value) }
32
34
  end
33
- when Array
34
- result.map! { |value| symbolize_key(value) }
35
+ result
35
36
  end
36
- result
37
+ end
38
+
39
+ def load_yaml(file)
40
+ yaml_safe_load(File.binread(file), file)
37
41
  end
38
42
  end
39
43
  end
@@ -3,7 +3,7 @@
3
3
  module RgGen
4
4
  module Core
5
5
  MAJOR = 0
6
- MINOR = 18
6
+ MINOR = 19
7
7
  PATCH = 0
8
8
  VERSION = "#{MAJOR}.#{MINOR}.#{PATCH}"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rggen-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taichi Ishitani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-19 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docile
@@ -111,7 +111,6 @@ files:
111
111
  - lib/rggen/core/configuration/loader.rb
112
112
  - lib/rggen/core/configuration/ruby_loader.rb
113
113
  - lib/rggen/core/configuration/yaml_loader.rb
114
- - lib/rggen/core/core_extensions/casecmp.rb
115
114
  - lib/rggen/core/core_extensions/object.rb
116
115
  - lib/rggen/core/dsl.rb
117
116
  - lib/rggen/core/exceptions.rb
@@ -177,15 +176,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
176
  requirements:
178
177
  - - ">="
179
178
  - !ruby/object:Gem::Version
180
- version: '2.3'
179
+ version: '2.4'
181
180
  required_rubygems_version: !ruby/object:Gem::Requirement
182
181
  requirements:
183
182
  - - ">="
184
183
  - !ruby/object:Gem::Version
185
184
  version: '0'
186
185
  requirements: []
187
- rubygems_version: 3.0.3
186
+ rubygems_version: 3.1.2
188
187
  signing_key:
189
188
  specification_version: 4
190
- summary: rggen-core-0.18.0
189
+ summary: rggen-core-0.19.0
191
190
  test_files: []
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if RUBY_VERSION < '2.4'
4
- casecmp = Module.new do
5
- def casecmp?(other)
6
- casecmp(other).zero?
7
- end
8
- end
9
-
10
- String.send(:include, casecmp)
11
- Symbol.send(:include, casecmp)
12
- end