interfaceable 0.1.2 → 0.1.3

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: fd1c5e3e374f3cf828348678b04342a04e332598682e16e95cbb69bf60a84da2
4
- data.tar.gz: 2dfc160484c025e9ec543849ec4b5c9d3e681493caa290b7bab5ae9d47754ef3
3
+ metadata.gz: 8e3a31246fb0aa84aec2f5d0be9e096931c53d55802f0a87d019f265a2258f59
4
+ data.tar.gz: 5c237f422ee9e564317302f0adb11b1d18b19a2e00b96e26c8bcc0c515dfd93e
5
5
  SHA512:
6
- metadata.gz: 8987daa2e42f955ae1099b67e6787556f1c49e6d2b563f7571db6734d34fee5c1d6636f0bd5c9fc735d7400d4972fdbb3cc70b4ad3f51be04ce3799b7f4fa48a
7
- data.tar.gz: 2ffcdadc6dfb51bb9cd1a0dc04cd316f2686ef53dcc98b0918fa4b48cf37a100a7161efd16b0751a5b75a50f5221766e9226ea60ab22058410a775985dd58e82
6
+ metadata.gz: 9170e1afde83592b35817e76d5e101cb609f62ae49030f6b98e39f085f4b44a10ceb408781a2c6b6317776e765c66e25372787012014d203b60ee03d92e92b99
7
+ data.tar.gz: e8f2a50b19dc800f19ce6b08f3e9ef0986f9f0f94afdb66f0726dd15cd3f5669f9750ee2a201be5eb8b481cd56ebbd59a73159763e5b6d5e0d659eaec2efbaf6
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.7', '3.2']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- interfaceable (0.1.1)
4
+ interfaceable (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Interfaceable [![Build Status](https://travis-ci.org/featurist/interfaceable.svg?branch=master)](https://travis-ci.org/featurist/interfaceable) [![Gem Version](https://badge.fury.io/rb/interfaceable.svg)](https://badge.fury.io/rb/interfaceable)
1
+ # Interfaceable [![Ruby](https://github.com/featurist/interfaceable/actions/workflows/ruby.yml/badge.svg)](https://github.com/featurist/interfaceable/actions/workflows/ruby.yml) [![Gem Version](https://badge.fury.io/rb/interfaceable.svg)](https://badge.fury.io/rb/interfaceable)
2
2
 
3
3
  Impose interfaces on classes and let this gem automatically check that the interface constraints are met.
4
4
 
@@ -57,6 +57,24 @@ Will fail because of method signature mismatch:
57
57
  - expected arguments: (req, req)
58
58
  - actual arguments: (req, opt=)
59
59
 
60
+ Classes may define additional optional or rest arguments.
61
+
62
+ ```ruby
63
+ module Carrier
64
+ def call(number); end
65
+
66
+ def text(number, text); end
67
+ end
68
+
69
+ class Giffgaff
70
+ def call(number, *opts); end
71
+
72
+ def text(number, text, opt1 = nil, opt2 = nil); end
73
+ end
74
+ ```
75
+
76
+ This will not generate any errors since `Giffgaff` implements the required methods with correct arguments only adding new optional ones.
77
+
60
78
  ### Rails
61
79
 
62
80
  Mix in `Interfaceable` before any of the application code is loaded. For example, in the initializer. For extra peace of mind, you can noop interface checking in production:
@@ -73,6 +73,16 @@ module Interfaceable
73
73
  methods - Object.methods
74
74
  end
75
75
 
76
+ OPTIONAL_PARAMETERS = %w[opt rest keyrest]
77
+
78
+ def check_if_parameters_are_compatible(expected_parameters, actual_parameters)
79
+ return false if actual_parameters.length < expected_parameters.length
80
+ return false if actual_parameters.take(expected_parameters.length) != expected_parameters
81
+
82
+ additional_parameters = actual_parameters[expected_parameters.length..]
83
+ additional_parameters.all? { OPTIONAL_PARAMETERS.include?(_1) }
84
+ end
85
+
76
86
  # rubocop:disable Metrics/MethodLength
77
87
  def check_method_signature(expected_parameters, actual_parameters)
78
88
  expected_keyword_parameters, expected_positional_parameters = simplify_parameters(
@@ -85,6 +95,9 @@ module Interfaceable
85
95
  return if expected_positional_parameters == actual_positional_parameters &&
86
96
  expected_keyword_parameters == actual_keyword_parameters
87
97
 
98
+ return if check_if_parameters_are_compatible(expected_positional_parameters, actual_positional_parameters) &&
99
+ check_if_parameters_are_compatible(expected_keyword_parameters, actual_keyword_parameters)
100
+
88
101
  {
89
102
  expected_positional_parameters: expected_positional_parameters,
90
103
  expected_keyword_parameters: expected_keyword_parameters,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Interfaceable
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,25 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interfaceable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - artemave
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-30 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - artemave@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/workflows/ruby.yml"
20
21
  - ".gitignore"
21
22
  - ".rspec"
22
- - ".travis.yml"
23
23
  - Gemfile
24
24
  - Gemfile.lock
25
25
  - LICENSE.txt
@@ -38,7 +38,7 @@ licenses:
38
38
  metadata:
39
39
  homepage_uri: https://github.com/featurist/interfaceable
40
40
  source_code_uri: https://github.com/artemave/interfaceable.git
41
- post_install_message:
41
+ post_install_message:
42
42
  rdoc_options: []
43
43
  require_paths:
44
44
  - lib
@@ -53,8 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubygems_version: 3.1.6
57
- signing_key:
56
+ rubygems_version: 3.4.10
57
+ signing_key:
58
58
  specification_version: 4
59
59
  summary: Strict interfaces in Ruby
60
60
  test_files: []
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.6
6
- before_install: gem install bundler -v 2.1.4
7
- install: bundle
8
- script:
9
- - bundle exec rubocop
10
- - COVERAGE=1 bundle exec rspec