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
- #extend_matcher {|_self| ... } ⇒ 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.
12 13 14 15 16 17 18 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 12 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.
10 11 12 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 10 def arguments_matchers @arguments_matchers end |
#match_to ⇒ Object (readonly)
Returns the value of attribute match_to.
10 11 12 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 10 def match_to @match_to end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
10 11 12 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 10 def method_name @method_name end |
Instance Method Details
#called_on(klass, with: []) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 20 def called_on(klass, with: []) matcher = Ruby::Whitelists::Matchers::Arguments.new( called_on: klass, method_name: method_name, with: with ) arguments_matchers << matcher # Sort matchers by reversed ancestors chain length, so # matcher method would find the closest ancestor in hierarchy arguments_matchers.sort_by! do |obj| -obj.called_on.ancestors.size end end |
#extend_matcher {|_self| ... } ⇒ Object
52 53 54 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 52 def extend_matcher yield self if block_given? end |
#match!(klass:, args:) ⇒ Object
44 45 46 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 44 def match!(klass:, args:) matcher(klass: klass).match!(args: args) end |
#match_to? ⇒ Boolean
48 49 50 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 48 def match_to? !match_to.nil? end |
#matcher(klass:) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/delorean/ruby/whitelists/matchers/method.rb', line 34 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 |