invoca-utils 0.1.1 → 0.2.0.pre.1

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
- SHA1:
3
- metadata.gz: 415752871460b9b105317298a448748ab21d3e66
4
- data.tar.gz: f946ff261cbc342c34d3a82da9c1d4bb31328317
2
+ SHA256:
3
+ metadata.gz: c649aa42003b13eb382b508255bbfcac81b8b923bb851716a5d2e3c6894e0e81
4
+ data.tar.gz: 1c2eb05eccb83b374ad1caeeec48d3a74e2be1354697df021055e7a6f033559d
5
5
  SHA512:
6
- metadata.gz: dc7d2f1aa0a27e6afcdbcb32fecf90dd39e987145ef5d0f875711cc8631e676bc9551f8d761710426d3d7a96343c03e1b25a3a4fba0fc93b0fa610815385375f
7
- data.tar.gz: ed4627548537d4c8d8d79c177a605f45920f494aa3e747b5b5585801e4837ebaf88db6c48035ad59bd4d7d89a87ba2eccf1c88028803036cc5c2262cb1ab68a5
6
+ metadata.gz: 9b2b6ea11bb6e6c2157e15ba05703705fb46623e48bbe7eaff9cd2a7a5cbcbf5ad8747c0eca4190047defa003024ecc0496c92cac6c489b01073049dca672f6c
7
+ data.tar.gz: da808833388e650a1cd8e55d773fcf4319dab6551fee8a36fb47cac68b0a17363e31475f0c152e242728aae7b7d3f131e404e3c1946e95146028832909fd17c3
data/.gitignore CHANGED
@@ -10,10 +10,12 @@ coverage
10
10
  doc/
11
11
  lib/bundler/man
12
12
  pkg
13
+ pkg/
13
14
  rdoc
14
- spec/reports
15
+ test/reports
15
16
  test/tmp
16
17
  test/version_tmp
18
+
17
19
  tmp
18
20
  *.bundle
19
21
  *.so
@@ -22,4 +24,3 @@ tmp
22
24
  mkmf.log
23
25
  .idea/
24
26
  .rubocop-http*
25
- test/reports
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/groovy
2
+ @Library('jenkins-pipeline@v0.4.5')
3
+ import com.invoca.docker.*;
4
+ pipeline {
5
+ agent {
6
+ kubernetes {
7
+ defaultContainer "ruby"
8
+ yamlFile ".jenkins/ruby_build_pod.yml"
9
+ }
10
+ }
11
+
12
+ environment {
13
+ GITHUB_TOKEN = credentials('github_token')
14
+ BUNDLE_GEM__FURY__IO = credentials('gemfury_deploy_token')
15
+ }
16
+
17
+ stages {
18
+ stage('Setup') {
19
+ steps {
20
+ script {
21
+ sh 'bundle install'
22
+ }
23
+ }
24
+ }
25
+ stage('Unit Test') {
26
+ steps {
27
+ script {
28
+ sh 'bundle exec rake'
29
+ }
30
+ }
31
+ post {
32
+ always { junit '*/reports/*.xml' }
33
+ success { updateGitHubStatus('clean-build', 'success', 'Unit tests.') }
34
+ failure { updateGitHubStatus('clean-build', 'failure', 'Unit tests.') }
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ void updateGitHubStatus(String context, String status, String description) {
41
+ gitHubStatus([
42
+ repoSlug: 'Invoca/invoca-utils',
43
+ sha: env.GIT_COMMIT,
44
+ description: description,
45
+ context: context,
46
+ targetURL: env.BUILD_URL,
47
+ token: env.GITHUB_TOKEN,
48
+ status: status
49
+ ])
50
+ }
@@ -0,0 +1,19 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: Pod
4
+ metadata:
5
+ labels:
6
+ jenkins/invoca-utils: 'true'
7
+ namespace: jenkins
8
+ name: invoca-utils
9
+ spec:
10
+ containers:
11
+ - name: ruby
12
+ image: ruby:2.6.5
13
+ tty: true
14
+ resources:
15
+ requests:
16
+ memory: "100Mi"
17
+ command:
18
+ - cat
19
+
@@ -1 +1 @@
1
- 2.4.2
1
+ 2.6.5
@@ -0,0 +1,12 @@
1
+ # CHANGELOG for `invoca-utils`
2
+
3
+ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
+
5
+ Note: This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.0] - Unreleased
8
+ ### Added
9
+ - Enumerable::build_hash method ported from HoboSupport
10
+ - Enumerable::* operator ported from HoboSupport
11
+
12
+ [0.2.0]: https://github.com/Invoca/process_settings/compare/v0.1.1...v0.2.0
data/Gemfile CHANGED
@@ -5,12 +5,13 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development do
8
+ gem 'minitest'
9
+ gem 'minitest-reporters'
10
+ gem 'pry'
8
11
  gem 'rake'
9
- gem 'test-unit', '= 1.2.3'
10
12
  gem 'rr', '=1.1.2'
11
- gem 'shoulda', '= 3.5.0'
12
- gem 'pry'
13
13
  gem 'ruby-prof'
14
- gem 'minitest'
14
+ gem 'shoulda', '= 3.5.0'
15
+ gem 'test-unit', '= 1.2.3'
15
16
  gem 'tzinfo'
16
17
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- invoca-utils (0.1.1)
4
+ invoca-utils (0.2.0.pre.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,20 +11,28 @@ GEM
11
11
  i18n (~> 0.7)
12
12
  minitest (~> 5.1)
13
13
  tzinfo (~> 1.1)
14
+ ansi (1.5.0)
15
+ builder (3.2.4)
14
16
  coderay (1.1.2)
15
17
  concurrent-ruby (1.0.5)
16
- hoe (3.16.2)
17
- rake (>= 0.8, < 13.0)
18
+ hoe (3.22.1)
19
+ rake (>= 0.8, < 15.0)
18
20
  i18n (0.9.1)
19
21
  concurrent-ruby (~> 1.0)
20
22
  method_source (0.9.0)
21
23
  minitest (5.11.1)
24
+ minitest-reporters (1.1.14)
25
+ ansi
26
+ builder
27
+ minitest (>= 5.0)
28
+ ruby-progressbar
22
29
  pry (0.11.3)
23
30
  coderay (~> 1.1.0)
24
31
  method_source (~> 0.9.0)
25
- rake (12.3.0)
32
+ rake (13.0.1)
26
33
  rr (1.1.2)
27
34
  ruby-prof (0.17.0)
35
+ ruby-progressbar (1.10.1)
28
36
  shoulda (3.5.0)
29
37
  shoulda-context (~> 1.0, >= 1.0.1)
30
38
  shoulda-matchers (>= 1.4.1, < 3.0)
@@ -43,6 +51,7 @@ PLATFORMS
43
51
  DEPENDENCIES
44
52
  invoca-utils!
45
53
  minitest
54
+ minitest-reporters
46
55
  pry
47
56
  rake
48
57
  rr (= 1.1.2)
data/Rakefile CHANGED
@@ -4,14 +4,8 @@
4
4
  require "bundler/gem_tasks"
5
5
  require 'rake/testtask'
6
6
 
7
- Rake::TestTask.new(:test) do |t|
8
- t.libs << 'lib'
9
- t.libs << 'test'
10
- t.pattern = 'test/**/*_test.rb'
11
- t.verbose = false
12
- end
13
-
14
7
  task default: :test
15
8
 
16
- task :default => 'test'
17
-
9
+ Rake::TestTask.new do |t|
10
+ t.pattern = "test/**/*_test.rb"
11
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "invoca/utils/array"
4
+ require "invoca/utils/enumerable"
3
5
  require "invoca/utils/diff"
4
6
  require "invoca/utils/http"
5
7
  require "invoca/utils/map_compact"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './multi_sender'
4
+
5
+ # Invoca ::Array extensions
6
+ module Invoca
7
+ module Utils
8
+ module ArrayMultiply
9
+ def *(rhs = nil)
10
+ if rhs
11
+ super
12
+ else
13
+ Invoca::Utils::MultiSender.new(self, :map)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ Array.prepend(Invoca::Utils::ArrayMultiply)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './multi_sender'
4
+
5
+ # Invoca ::Enumerable extensions
6
+ module Enumerable
7
+ def build_hash(res = {})
8
+ each do |x|
9
+ pair = block_given? ? yield(x) : x
10
+ res[pair.first] = pair.last if pair
11
+ end
12
+ res
13
+ end
14
+
15
+ def *
16
+ Invoca::Utils::MultiSender.new(self, :map)
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Invoca
4
+ module Utils
5
+ class MultiSender
6
+ undef_method(*(instance_methods - [:__id__, :__send__, :object_id]))
7
+
8
+ def initialize(enumerable, method)
9
+ @enumerable = enumerable
10
+ @method = method
11
+ end
12
+
13
+ # rubocop:disable Style/MethodMissingSuper
14
+ # rubocop:disable Style/MissingRespondToMissing
15
+ def method_missing(name, *args, &block)
16
+ @enumerable.send(@method) { |x| x.send(name, *args, &block) }
17
+ end
18
+ # rubocop:enable Style/MethodMissingSuper
19
+ # rubocop:enable Style/MissingRespondToMissing
20
+ end
21
+ end
22
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Invoca
4
4
  module Utils
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0.pre.1"
6
6
  end
7
7
  end
@@ -7,3 +7,8 @@ require 'pry'
7
7
  require 'active_support/all'
8
8
 
9
9
  require 'invoca/utils'
10
+ require "minitest/reporters"
11
+ Minitest::Reporters.use! [
12
+ Minitest::Reporters::DefaultReporter.new,
13
+ Minitest::Reporters::JUnitReporter.new
14
+ ]
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../lib/invoca/utils/array.rb'
4
+ require_relative '../test_helper'
5
+
6
+ class ArrayTest < Minitest::Test
7
+ context '* operator' do
8
+ should 'call the same method on each item in an array and return the results as an array' do
9
+ assert_equal([4, 5, 5], ['some', 'short', 'words'].*.length)
10
+ end
11
+
12
+ should 'handle methods with arguments' do
13
+ assert_equal(['om', 'ho', 'or'], ['some', 'short', 'words'].*.slice(1, 2))
14
+ end
15
+
16
+ should 'not alter normal behavior (multiplication) when there is a right hand side to the expression' do
17
+ assert_equal(['some', 'short', 'words', 'some', 'short', 'words'], ['some', 'short', 'words'] * 2)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+ require_relative '../../lib/invoca/utils/enumerable.rb'
5
+ require_relative '../test_helper'
6
+
7
+ class EnumerableTest < Minitest::Test
8
+
9
+ context 'build_hash' do
10
+ should 'convert arrays of [key, value] to a hash of { key => value }' do
11
+ assert_equal({ 'some' => 4, 'short' => 5, 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| [s, s.length] })
12
+ end
13
+
14
+ should 'ignore nils returned from map' do
15
+ assert_equal({ 'some' => 4, 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? nil : [s, s.length] })
16
+ end
17
+
18
+ # these seem like erroneous behavior, but, they have been left as-is for backward compatibility with hobosupport::Enumerable::build_hash
19
+
20
+ should 'convert arrays of [single_value] to a hash of { single_value => single_value }' do
21
+ assert_equal({ 'some' => 4, 'short' => 'short', 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? [s] : [s, s.length] })
22
+ end
23
+
24
+ should 'convert arrays of [first, ..., last] to a hash of { first => last }' do
25
+ assert_equal({ 'some' => 4, 'short' => 'three', 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? [s, 'two', 'three'] : [s, s.length] })
26
+ end
27
+
28
+ should 'convert empty arrays to a hash of { nil => nil }' do
29
+ assert_equal({ 'some' => 4, nil => nil, 'words' => 5 }, ['some', 'short', 'words'].build_hash { |s| s == 'short' ? [] : [s, s.length] })
30
+ end
31
+ end
32
+
33
+ context '* operator' do
34
+ should 'call the same method on each item in an Set and return the results as an array' do
35
+ assert_equal([4, 5, 5], Set['some', 'short', 'words'].*.length)
36
+ end
37
+
38
+ should 'call the same method on each item in an Hash and return the results as an array' do
39
+ assert_equal(['key1:value1', 'key2:value2'], { key1: 'value1', key2: 'value2' }.*.join(':'))
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../lib/invoca/utils/multi_sender.rb'
4
+ require_relative '../test_helper'
5
+
6
+ class MultiSenderTest < Minitest::Test
7
+ # create enumerable class for testing
8
+ class LinkedList
9
+ include Enumerable
10
+
11
+ def initialize(head, tail = nil)
12
+ @head, @tail = head, tail
13
+ end
14
+
15
+ def <<(item)
16
+ LinkedList.new(item, self)
17
+ end
18
+
19
+ def inspect
20
+ [@head, @tail].inspect
21
+ end
22
+
23
+ def each(&block)
24
+ if block_given?
25
+ block.call(@head)
26
+ @tail&.each(&block)
27
+ else
28
+ to_enum(:each)
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'MultiSender' do
34
+ context 'with custom Enumerable' do
35
+ setup do
36
+ linked_list = LinkedList.new('some') << 'short' << 'words'
37
+ @multi_sender = Invoca::Utils::MultiSender.new(linked_list, :map)
38
+ end
39
+
40
+ should 'call the same method on each item in an Enumerable and return the results as an array' do
41
+ assert_equal([5, 5, 4], @multi_sender.length)
42
+ end
43
+
44
+ should 'handle methods with arguments' do
45
+ assert_equal(['or', 'ho', 'om'], @multi_sender.slice(1, 2))
46
+ end
47
+ end
48
+
49
+ context 'with built-in Array' do
50
+ should 'call the same method on each item in an Array and return the results as an array' do
51
+ multi_sender = Invoca::Utils::MultiSender.new(['some', 'short', 'words'], :map)
52
+ assert_equal([4, 5, 5], multi_sender.length)
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoca-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-16 00:00:00.000000000 Z
11
+ date: 2020-04-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A public collection of helpers used in multiple projects
14
14
  email:
@@ -18,8 +18,11 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
+ - ".jenkins/Jenkinsfile"
22
+ - ".jenkins/ruby_build_pod.yml"
21
23
  - ".rubocop.yml"
22
24
  - ".ruby-version"
25
+ - CHANGELOG.md
23
26
  - Gemfile
24
27
  - Gemfile.lock
25
28
  - LICENSE.txt
@@ -27,18 +30,24 @@ files:
27
30
  - Rakefile
28
31
  - invoca-utils.gemspec
29
32
  - lib/invoca/utils.rb
33
+ - lib/invoca/utils/array.rb
30
34
  - lib/invoca/utils/diff.rb
35
+ - lib/invoca/utils/enumerable.rb
31
36
  - lib/invoca/utils/guaranteed_utf8_string.rb
32
37
  - lib/invoca/utils/http.rb
33
38
  - lib/invoca/utils/map_compact.rb
34
39
  - lib/invoca/utils/min_max.rb
40
+ - lib/invoca/utils/multi_sender.rb
35
41
  - lib/invoca/utils/stable_sort.rb
36
42
  - lib/invoca/utils/time.rb
37
43
  - lib/invoca/utils/version.rb
38
44
  - test/helpers/constant_overrides.rb
39
45
  - test/test_helper.rb
46
+ - test/unit/array_test.rb
47
+ - test/unit/enumerable_test.rb
40
48
  - test/unit/guaranteed_utf8_string_test.rb
41
49
  - test/unit/map_compact_test.rb
50
+ - test/unit/multi_sender_test.rb
42
51
  - test/unit/stable_sort_test.rb
43
52
  - test/unit/time_calculations_test.rb
44
53
  - test/unit/utils_test.rb
@@ -58,20 +67,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
67
  version: '0'
59
68
  required_rubygems_version: !ruby/object:Gem::Requirement
60
69
  requirements:
61
- - - ">="
70
+ - - ">"
62
71
  - !ruby/object:Gem::Version
63
- version: '0'
72
+ version: 1.3.1
64
73
  requirements: []
65
- rubyforge_project:
66
- rubygems_version: 2.6.13
74
+ rubygems_version: 3.0.3
67
75
  signing_key:
68
76
  specification_version: 4
69
77
  summary: A public collection of helpers used in multiple projects
70
78
  test_files:
71
79
  - test/helpers/constant_overrides.rb
72
80
  - test/test_helper.rb
81
+ - test/unit/array_test.rb
82
+ - test/unit/enumerable_test.rb
73
83
  - test/unit/guaranteed_utf8_string_test.rb
74
84
  - test/unit/map_compact_test.rb
85
+ - test/unit/multi_sender_test.rb
75
86
  - test/unit/stable_sort_test.rb
76
87
  - test/unit/time_calculations_test.rb
77
88
  - test/unit/utils_test.rb