evt-record_invocation 0.0.0.1 → 2.0.1.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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: a3b918a1c86c63e66f810ebfdd356233b59e36806356e860ab34edbe3be45041
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1a0c1fc84a63f80627d8d2c6603557cb533c4fb141d45a4f26a2d72450c53941
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b894a2e7a76590b36502004c1709bb6cb036fdedb3d16c0f1330e191d32d82e54c896f30843c8d66f62a48679aad2253c95e7c8b5dd42f5f1eacd0d6f1cf18b2
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 415ed92cf8f4f3eddfba5f2c833df3f45ec4ad7b9500ec6781cdf85b3b429c9de50d8d2690a5c03b49c6453d69d1af2e2ce8571e46cb751a973dd589751ce30a
         
     | 
| 
         @@ -14,6 +14,40 @@ module RecordInvocation 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  def self.method_name
         
     | 
| 
       15 
15 
     | 
    
         
             
                    :some_method
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  module MixedParameters
         
     | 
| 
      
 19 
     | 
    
         
            +
                    def self.example(...)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      instance = Example.new()
         
     | 
| 
      
 21 
     | 
    
         
            +
                      instance.some_method(...)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    class Example
         
     | 
| 
      
 25 
     | 
    
         
            +
                      def some_method(
         
     | 
| 
      
 26 
     | 
    
         
            +
                        some_parameter,
         
     | 
| 
      
 27 
     | 
    
         
            +
                        some_optional_parameter=nil,
         
     | 
| 
      
 28 
     | 
    
         
            +
                        *some_multiple_assignment_parameter,
         
     | 
| 
      
 29 
     | 
    
         
            +
                        some_keyword_parameter:,
         
     | 
| 
      
 30 
     | 
    
         
            +
                        some_optional_keyword_parameter: nil,
         
     | 
| 
      
 31 
     | 
    
         
            +
                        **some_multiple_assignment_keyword_parameter,
         
     | 
| 
      
 32 
     | 
    
         
            +
                        &some_block
         
     | 
| 
      
 33 
     | 
    
         
            +
                      )
         
     | 
| 
      
 34 
     | 
    
         
            +
                        ::Invocation.build(binding)
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  module NoParameters
         
     | 
| 
      
 40 
     | 
    
         
            +
                    def self.example
         
     | 
| 
      
 41 
     | 
    
         
            +
                      subject = Example.new
         
     | 
| 
      
 42 
     | 
    
         
            +
                      subject.some_method
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    class Example
         
     | 
| 
      
 46 
     | 
    
         
            +
                      def some_method
         
     | 
| 
      
 47 
     | 
    
         
            +
                        ::Invocation.build(binding)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
                  end
         
     | 
| 
       17 
51 
     | 
    
         
             
                end
         
     | 
| 
       18 
52 
     | 
    
         
             
              end
         
     | 
| 
       19 
53 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Invocation
         
     | 
| 
      
 2 
     | 
    
         
            +
              attr_reader :method_name
         
     | 
| 
      
 3 
     | 
    
         
            +
              attr_reader :arguments
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              def initialize(method_name, arguments)
         
     | 
| 
      
 6 
     | 
    
         
            +
                @method_name = method_name
         
     | 
| 
      
 7 
     | 
    
         
            +
                @arguments = arguments
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def self.build(bndg)
         
     | 
| 
      
 11 
     | 
    
         
            +
                instance = bndg.receiver
         
     | 
| 
      
 12 
     | 
    
         
            +
                method_name = bndg.eval("__method__")
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                mthd = instance.method(method_name)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                parameters = mthd.parameters
         
     | 
| 
      
 17 
     | 
    
         
            +
                parameter_names = parameters.map { |p| p[1] }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                argument_values = parameter_names.map { |n| bndg.local_variable_get(n) }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                params = {}
         
     | 
| 
      
 22 
     | 
    
         
            +
                parameter_names.each_with_index do |n, i|
         
     | 
| 
      
 23 
     | 
    
         
            +
                  params[n] = argument_values[i]
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                new(method_name, params)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -7,6 +7,18 @@ module RecordInvocation 
     | 
|
| 
       7 
7 
     | 
    
         
             
                end
         
     | 
| 
       8 
8 
     | 
    
         
             
              end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
              def self.call(object, method, *methods)
         
     | 
| 
      
 11 
     | 
    
         
            +
                methods = [method, *methods]
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                object.singleton_class.class_exec do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  include RecordInvocation
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  methods.each do |method|
         
     | 
| 
      
 17 
     | 
    
         
            +
                    record method
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
       10 
22 
     | 
    
         
             
              def __records
         
     | 
| 
       11 
23 
     | 
    
         
             
                @__records ||= []
         
     | 
| 
       12 
24 
     | 
    
         
             
              end
         
     | 
| 
         @@ -29,8 +41,8 @@ module RecordInvocation 
     | 
|
| 
       29 
41 
     | 
    
         
             
              alias :record_invocation :__record_invocation
         
     | 
| 
       30 
42 
     | 
    
         | 
| 
       31 
43 
     | 
    
         
             
              def __invocation(method_name, **parameters)
         
     | 
| 
       32 
     | 
    
         
            -
                 
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 44 
     | 
    
         
            +
                once = parameters.delete(:once)
         
     | 
| 
      
 45 
     | 
    
         
            +
                once ||= false
         
     | 
| 
       34 
46 
     | 
    
         | 
| 
       35 
47 
     | 
    
         
             
                invocations = __invocations(method_name, **parameters)
         
     | 
| 
       36 
48 
     | 
    
         | 
| 
         @@ -38,7 +50,7 @@ module RecordInvocation 
     | 
|
| 
       38 
50 
     | 
    
         
             
                  return nil
         
     | 
| 
       39 
51 
     | 
    
         
             
                end
         
     | 
| 
       40 
52 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                if  
     | 
| 
      
 53 
     | 
    
         
            +
                if once && invocations.length > 1
         
     | 
| 
       42 
54 
     | 
    
         
             
                  raise Error, "More than one invocation record matches (Method Name: #{method_name.inspect}, Parameters: #{parameters.inspect})"
         
     | 
| 
       43 
55 
     | 
    
         
             
                end
         
     | 
| 
       44 
56 
     | 
    
         | 
| 
         @@ -47,7 +59,7 @@ module RecordInvocation 
     | 
|
| 
       47 
59 
     | 
    
         
             
              alias :invocation :__invocation
         
     | 
| 
       48 
60 
     | 
    
         | 
| 
       49 
61 
     | 
    
         
             
              def __one_invocation(method_name, **parameters)
         
     | 
| 
       50 
     | 
    
         
            -
                parameters[: 
     | 
| 
      
 62 
     | 
    
         
            +
                parameters[:once] = true
         
     | 
| 
       51 
63 
     | 
    
         
             
                __invocation(method_name, **parameters)
         
     | 
| 
       52 
64 
     | 
    
         
             
              end
         
     | 
| 
       53 
65 
     | 
    
         
             
              alias :one_invocation :__one_invocation
         
     | 
| 
         @@ -84,8 +96,8 @@ module RecordInvocation 
     | 
|
| 
       84 
96 
     | 
    
         
             
                  return !__records.empty?
         
     | 
| 
       85 
97 
     | 
    
         
             
                end
         
     | 
| 
       86 
98 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
                if not parameters.key?(: 
     | 
| 
       88 
     | 
    
         
            -
                  parameters[: 
     | 
| 
      
 99 
     | 
    
         
            +
                if not parameters.key?(:once)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  parameters[:once] = false
         
     | 
| 
       89 
101 
     | 
    
         
             
                end
         
     | 
| 
       90 
102 
     | 
    
         | 
| 
       91 
103 
     | 
    
         
             
                invocation = __invocation(method_name, **parameters)
         
     | 
| 
         @@ -94,7 +106,7 @@ module RecordInvocation 
     | 
|
| 
       94 
106 
     | 
    
         
             
              alias :invoked? :__invoked?
         
     | 
| 
       95 
107 
     | 
    
         | 
| 
       96 
108 
     | 
    
         
             
              def __invoked_once?(method_name, **parameters)
         
     | 
| 
       97 
     | 
    
         
            -
                parameters[: 
     | 
| 
      
 109 
     | 
    
         
            +
                parameters[:once] = true
         
     | 
| 
       98 
110 
     | 
    
         
             
                __invoked?(method_name, **parameters)
         
     | 
| 
       99 
111 
     | 
    
         
             
              end
         
     | 
| 
       100 
112 
     | 
    
         
             
              alias :invoked_once? :__invoked_once?
         
     | 
    
        data/lib/record_invocation.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: evt-record_invocation
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - The Eventide Project
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-07-24 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: evt-invocation
         
     | 
| 
         @@ -48,6 +48,7 @@ files: 
     | 
|
| 
       48 
48 
     | 
    
         
             
            - lib/record_invocation/controls.rb
         
     | 
| 
       49 
49 
     | 
    
         
             
            - lib/record_invocation/controls/invocation.rb
         
     | 
| 
       50 
50 
     | 
    
         
             
            - lib/record_invocation/controls/recorder.rb
         
     | 
| 
      
 51 
     | 
    
         
            +
            - lib/record_invocation/invocation.rb
         
     | 
| 
       51 
52 
     | 
    
         
             
            - lib/record_invocation/record_invocation.rb
         
     | 
| 
       52 
53 
     | 
    
         
             
            homepage: https://github.com/eventide-project/record-invocation
         
     | 
| 
       53 
54 
     | 
    
         
             
            licenses:
         
     | 
| 
         @@ -68,9 +69,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       68 
69 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       69 
70 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       70 
71 
     | 
    
         
             
            requirements: []
         
     | 
| 
       71 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 72 
     | 
    
         
            +
            rubygems_version: 3.5.9
         
     | 
| 
       72 
73 
     | 
    
         
             
            signing_key:
         
     | 
| 
       73 
74 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       74 
     | 
    
         
            -
            summary: Record method invocations, query  
     | 
| 
       75 
     | 
    
         
            -
               
     | 
| 
      
 75 
     | 
    
         
            +
            summary: Record method invocations, query the invocations, and use predicates to verify
         
     | 
| 
      
 76 
     | 
    
         
            +
              a method's invocation
         
     | 
| 
       76 
77 
     | 
    
         
             
            test_files: []
         
     |