Class: Fixturama::Changes::Chain::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/fixturama/changes/chain/arguments.rb

Overview

Keep a set of arguments along with the corresponding actions to be done

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsArray<Object> (readonly)



8
9
10
# File 'lib/fixturama/changes/chain/arguments.rb', line 8

def arguments
  @arguments
end

Instance Method Details

#==(other) ⇒ Boolean

Compare definitions by sets of arguments



19
20
21
# File 'lib/fixturama/changes/chain/arguments.rb', line 19

def ==(other)
  other.arguments == arguments
end

#callObject

Call the corresponding action if actual arguments are matched



41
42
43
# File 'lib/fixturama/changes/chain/arguments.rb', line 41

def call
  @actions.next.call
end

#match?(*args, **opts) ⇒ Boolean

If actual arguments are covered by the current ones



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fixturama/changes/chain/arguments.rb', line 24

def match?(*args, **opts)
  return false if arguments.count > args.count + 1

  arguments.first(args.count).zip(args).each do |(expected, actual)|
    return false unless actual == expected
  end

  if arguments.count > args.count
    Hash(arguments.last).transform_keys(&:to_sym).each do |k, v|
      return false unless opts[k] == v
    end
  end

  true
end

#orderInteger

Order of comparing this set of arguments with the actual ones



12
13
14
# File 'lib/fixturama/changes/chain/arguments.rb', line 12

def order
  -arguments.count
end