Class: Delorean::Ruby::Whitelists::Matchers::Method
- Inherits:
-
Object
- Object
- Delorean::Ruby::Whitelists::Matchers::Method
- Defined in:
- lib/delorean/ruby/whitelists/matchers/method.rb
Instance Attribute Summary collapse
-
#arguments_matchers ⇒ Object
readonly
Returns the value of attribute arguments_matchers.
-
#match_to ⇒ Object
readonly
Returns the value of attribute match_to.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
- #called_on(klass, with: []) ⇒ Object
-
#initialize(method_name:, match_to: nil) {|_self| ... } ⇒ Method
constructor
A new instance of Method.
- #match!(klass:, args:) ⇒ Object
- #match_to? ⇒ Boolean
- #matcher(klass:) ⇒ Object
Constructor Details
#initialize(method_name:, match_to: nil) {|_self| ... } ⇒ Method
Returns a new instance of Method.
10 11 12 13 14 15 16 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 10 def initialize(method_name:, match_to: nil) @method_name = method_name @match_to = match_to @arguments_matchers = [] yield self if block_given? end |
Instance Attribute Details
#arguments_matchers ⇒ Object (readonly)
Returns the value of attribute arguments_matchers.
8 9 10 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 8 def arguments_matchers @arguments_matchers end |
#match_to ⇒ Object (readonly)
Returns the value of attribute match_to.
8 9 10 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 8 def match_to @match_to end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
8 9 10 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 8 def method_name @method_name end |
Instance Method Details
#called_on(klass, with: []) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 18 def called_on(klass, with: []) matcher = Ruby::Whitelists::Matchers::Arguments.new( called_on: klass, method_name: method_name, with: with ) arguments_matchers << matcher end |
#match!(klass:, args:) ⇒ Object
35 36 37 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 35 def match!(klass:, args:) matcher(klass: klass).match!(args: args) end |
#match_to? ⇒ Boolean
39 40 41 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 39 def match_to? !match_to.nil? end |
#matcher(klass:) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 26 def matcher(klass:) matcher = arguments_matchers.find do |matcher_object| klass <= matcher_object.called_on end raise "no such method #{method_name} for #{klass}" if matcher.nil? matcher end |