class Fixturama::Changes::Chain::Arguments
@private Keep a set of arguments along with the corresponding actions to be done
Attributes
arguments[R]
@return [Array<Object>] the collection of arguments
Public Class Methods
new(options)
click to toggle source
# File lib/fixturama/changes/chain/arguments.rb 47 def initialize(options) 48 @arguments = extract(options, :arguments) 49 @actions = Actions.new(*extract(options, :actions)) 50 end
Public Instance Methods
==(other)
click to toggle source
Compare definitions by sets of arguments @param [Fixturama::Changes::Chain::Arguments] other @return [Boolean]
# File lib/fixturama/changes/chain/arguments.rb 19 def ==(other) 20 other.arguments == arguments 21 end
call()
click to toggle source
Call the corresponding action if actual arguments are matched
# File lib/fixturama/changes/chain/arguments.rb 41 def call 42 @actions.next.call 43 end
match?(*args, **opts)
click to toggle source
If actual arguments are covered by the current ones
# File lib/fixturama/changes/chain/arguments.rb 24 def match?(*args, **opts) 25 return false if arguments.count > args.count + 1 26 27 arguments.first(args.count).zip(args).each do |(expected, actual)| 28 return false unless actual == expected 29 end 30 31 if arguments.count > args.count 32 Hash(arguments.last).transform_keys(&:to_sym).each do |k, v| 33 return false unless opts[k] == v 34 end 35 end 36 37 true 38 end
order()
click to toggle source
Order of comparing this set of arguments with the actual ones @return [Integer]
# File lib/fixturama/changes/chain/arguments.rb 12 def order 13 -arguments.count 14 end
Private Instance Methods
extract(options, key)
click to toggle source
# File lib/fixturama/changes/chain/arguments.rb 52 def extract(options, key) 53 return [] unless options.key?(key) 54 55 source = options[key] 56 source.is_a?(Array) ? source : [source] 57 end