class MatchPlay::PlayActions

Class to help work with actions:

actions include :win_game, :start_game, and :discard_play. See Match#play_match!

Public Class Methods

new(match) click to toggle source
# File app/models/concerns/match_play.rb, line 16
def initialize(match)
  @match = match
end

Public Instance Methods

lookup_method(action) click to toggle source

Lookup the methods to handle a particular action

  • Args :

    • action -> :win_game, :start_game etc.

  • Returns : Hash or nil

    • :exec - method to execute the action

    • :query - method to determine if the action is enabled

# File app/models/concerns/match_play.rb, line 27
def lookup_method(action)
  action = action.to_sym
  play_methods_table[action] if play_methods_table.has_key? action
end
valid_actions() click to toggle source

Generate a hash of valid actions

  • Returns : Hash

Example

{
  start_game: true,
  discard_play: true,
  remove_last_change: true
}
# File app/models/concerns/match_play.rb, line 41
def valid_actions
  result = {}
  play_methods_table.each do |k, v|
    if v[:query].call
      result[k] = true
    end
  end
  result
end