interfaceable 0.1.2 → 0.1.3
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 +4 -4
- data/.github/workflows/ruby.yml +38 -0
- data/Gemfile.lock +1 -1
- data/README.md +19 -1
- data/lib/interfaceable/implementation_check.rb +13 -0
- data/lib/interfaceable/version.rb +1 -1
- metadata +8 -8
- data/.travis.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3a31246fb0aa84aec2f5d0be9e096931c53d55802f0a87d019f265a2258f59
|
4
|
+
data.tar.gz: 5c237f422ee9e564317302f0adb11b1d18b19a2e00b96e26c8bcc0c515dfd93e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Interfaceable [](https://github.com/featurist/interfaceable/actions/workflows/ruby.yml) [](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,
|
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.
|
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:
|
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.
|
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: []
|