Class: Fixturama::Changes::Chain::Arguments
- Inherits:
-
Object
- Object
- Fixturama::Changes::Chain::Arguments
- 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
-
#arguments ⇒ Array<Object>
readonly
The collection of arguments.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare definitions by sets of arguments.
-
#call ⇒ Object
Call the corresponding action if actual arguments are matched.
-
#match?(*args, **opts) ⇒ Boolean
If actual arguments are covered by the current ones.
-
#order ⇒ Integer
Order of comparing this set of arguments with the actual ones.
Instance Attribute Details
#arguments ⇒ Array<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 |
#call ⇒ Object
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 |
#order ⇒ Integer
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 |