strong_interface 0.1.0 → 0.2.0
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/CHANGELOG.md +16 -0
- data/README.md +12 -7
- data/lib/strong_interface/parameters_validator.rb +39 -0
- data/lib/strong_interface/version.rb +1 -1
- data/lib/strong_interface.rb +8 -1
- data/strong_interface.gemspec +1 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a3cd6f325e9f01905b2c69da7391e760d6e0bd55d60f5038a478ba7a14a055
|
4
|
+
data.tar.gz: b8d5f89c62dda435cfac22d81efb744414465b45d6d3f455c7f70e68e5c73540
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef2277ee74a7426e83b7345929f3b36013ab9e955f2bc23f581b497349ca690baae4882b1fe0ee571ba03de831215548415fbd3b7e0b1ebe5cd2721716f13b8a
|
7
|
+
data.tar.gz: 8685a1b66e1a5dcc9e8a15458c2e5ea0e5db95ba148947027b88437c3b79912e27f3d23bab46444771c820b0ae4f44adf6277b9f8b19149e9220aa9596dc4c48
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## main (unreleased)
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
## 0.2.0
|
8
|
+
|
9
|
+
### New features
|
10
|
+
|
11
|
+
- [9506eb3](https://github.com/programyan/strong_interface/commit/9506eb31666628cd6d06a4a4608ca81081a1315b) Add validation parameters
|
12
|
+
|
13
|
+
## 0.1.0
|
14
|
+
|
15
|
+
- DSL
|
16
|
+
- Basic implementation of methods presence
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ Or install it yourself as:
|
|
33
33
|
```ruby
|
34
34
|
module IDog
|
35
35
|
def self.create(*); end
|
36
|
-
def eat(
|
36
|
+
def eat(food); end
|
37
37
|
def voice; end
|
38
38
|
end
|
39
39
|
```
|
@@ -46,11 +46,11 @@ class Lessy
|
|
46
46
|
implements IDog
|
47
47
|
|
48
48
|
def self.create(name)
|
49
|
-
...
|
49
|
+
# Creating...
|
50
50
|
end
|
51
51
|
|
52
52
|
def eat(food)
|
53
|
-
...
|
53
|
+
# Eating...
|
54
54
|
end
|
55
55
|
|
56
56
|
def voice
|
@@ -66,6 +66,10 @@ class Lessy
|
|
66
66
|
extend StrongInterface
|
67
67
|
implements IDog
|
68
68
|
|
69
|
+
def eat(food, water)
|
70
|
+
# Eating...
|
71
|
+
end
|
72
|
+
|
69
73
|
def voice
|
70
74
|
'Gav'
|
71
75
|
end
|
@@ -76,7 +80,7 @@ end
|
|
76
80
|
|
77
81
|
```shell
|
78
82
|
StrongInterface::MethodNotImplemented (Class method `create` is not implemented at `Lessy`)
|
79
|
-
|
83
|
+
Invalid parameters at method `eat`, expected: `def eat(food)`, got: `def eat(food, water)`
|
80
84
|
```
|
81
85
|
|
82
86
|
## Validation Strategies
|
@@ -100,7 +104,8 @@ even if it has this kind of a problem in code.
|
|
100
104
|
## TODO
|
101
105
|
|
102
106
|
- [x] Check if methods of interfaces all exists in a class or module
|
103
|
-
- [
|
107
|
+
- [x] Check the arguments of methods
|
108
|
+
- [ ] Allow optional arguments at interface methods???
|
104
109
|
|
105
110
|
## Development
|
106
111
|
|
@@ -110,7 +115,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
110
115
|
|
111
116
|
## Contributing
|
112
117
|
|
113
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
118
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/programyan/strong_interface. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/programyan/strong_interface/blob/main/CODE_OF_CONDUCT.md).
|
114
119
|
|
115
120
|
|
116
121
|
## License
|
@@ -119,4 +124,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
119
124
|
|
120
125
|
## Code of Conduct
|
121
126
|
|
122
|
-
Everyone interacting in the StrongInterface project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
127
|
+
Everyone interacting in the StrongInterface project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/programyan/strong_interface/blob/main/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StrongInterface
|
4
|
+
class ParametersValidator
|
5
|
+
def initialize(interface_method, klass_method)
|
6
|
+
@interface_method = interface_method
|
7
|
+
@interface_method_parameters = interface_method.parameters.map { |param| param[0] }
|
8
|
+
@klass_method = klass_method
|
9
|
+
@klass_method_parameters = klass_method.parameters.map { |param| param[0] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate
|
13
|
+
return if valid?
|
14
|
+
|
15
|
+
"Invalid parameters at method `#{@klass_method.name}`, expected: `def #{description(@interface_method)}`," \
|
16
|
+
" got: `def #{description(@klass_method)}`"
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid?
|
20
|
+
return true if @interface_method_parameters == [:rest]
|
21
|
+
return true if @klass_method_parameters == [:rest]
|
22
|
+
|
23
|
+
return true if @interface_method_parameters == @klass_method_parameters
|
24
|
+
return false if @interface_method_parameters.size != @klass_method_parameters.size
|
25
|
+
|
26
|
+
@interface_method_parameters.each.with_index.all? do |key, index|
|
27
|
+
if key == :req
|
28
|
+
%i(req opt).include? @klass_method_parameters[index]
|
29
|
+
elsif key == :keyreq
|
30
|
+
%i(keyreq key).include? @klass_method_parameters[index]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def description(m)
|
36
|
+
m.inspect.scan(/[\.|#](\S+?\(.*?\))/).last.first
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/strong_interface.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'strong_interface/version'
|
4
|
+
require 'strong_interface/parameters_validator'
|
4
5
|
|
5
6
|
module StrongInterface
|
6
7
|
MethodNotImplemented = Class.new(StandardError)
|
@@ -39,7 +40,11 @@ module StrongInterface
|
|
39
40
|
|
40
41
|
def validate_class_methods(interface)
|
41
42
|
interface.methods(false).filter_map do |klass_method|
|
42
|
-
|
43
|
+
unless methods(false).include?(klass_method)
|
44
|
+
"Class method `#{klass_method}` is not implemented at `#{self}`"
|
45
|
+
else
|
46
|
+
ParametersValidator.new(interface.method(klass_method), method(klass_method)).validate
|
47
|
+
end
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
@@ -47,6 +52,8 @@ module StrongInterface
|
|
47
52
|
interface.instance_methods.filter_map do |instance_method|
|
48
53
|
unless instance_methods.include?(instance_method)
|
49
54
|
"Instance method `#{instance_method}` is not implemented at `#{self}`"
|
55
|
+
else
|
56
|
+
ParametersValidator.new(interface.instance_method(instance_method), instance_method(instance_method)).validate
|
50
57
|
end
|
51
58
|
end
|
52
59
|
end
|
data/strong_interface.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = 'https://github.com/programyan/strong_interface'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/programyan/strong_interface/blob/main/CHANGELOG.md'
|
19
20
|
|
20
21
|
# Specify which files should be added to the gem when it is released.
|
21
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Ageev
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
21
|
- ".rspec"
|
22
|
+
- CHANGELOG.md
|
22
23
|
- CODE_OF_CONDUCT.md
|
23
24
|
- Gemfile
|
24
25
|
- Gemfile.lock
|
@@ -28,6 +29,7 @@ files:
|
|
28
29
|
- bin/console
|
29
30
|
- bin/setup
|
30
31
|
- lib/strong_interface.rb
|
32
|
+
- lib/strong_interface/parameters_validator.rb
|
31
33
|
- lib/strong_interface/version.rb
|
32
34
|
- strong_interface.gemspec
|
33
35
|
homepage: https://github.com/programyan/strong_interface
|
@@ -36,6 +38,7 @@ licenses:
|
|
36
38
|
metadata:
|
37
39
|
homepage_uri: https://github.com/programyan/strong_interface
|
38
40
|
source_code_uri: https://github.com/programyan/strong_interface
|
41
|
+
changelog_uri: https://github.com/programyan/strong_interface/blob/main/CHANGELOG.md
|
39
42
|
post_install_message:
|
40
43
|
rdoc_options: []
|
41
44
|
require_paths:
|