lib/blather/stanza/iq/command.rb in blather-0.4.16 vs lib/blather/stanza/iq/command.rb in blather-0.5.0

- old
+ new

@@ -9,12 +9,15 @@ # This is a base class for any command based Iq stanzas. It provides a base set # of methods for working with command stanzas # # @handler :command class Command < Iq + # @private VALID_ACTIONS = [:cancel, :execute, :complete, :next, :prev].freeze + # @private VALID_STATUS = [:executing, :completed, :canceled].freeze + # @private VALID_NOTE_TYPES = [:info, :warn, :error].freeze register :command, :command, 'http://jabber.org/protocol/commands' # Overrides the parent method to ensure a command node is created @@ -42,12 +45,15 @@ self end # Overrides the parent method to ensure the reply has no action # + # @param [Hash] opts options to pass to reply! + # @option opts [Boolean] :remove_children Wether or not to remove child nodes when replying + # # @return [self] - def reply! + def reply!(opts = {}) super self.action = nil self end @@ -213,20 +219,29 @@ a end # Get the command's allowed actions # - # @return [[Symbol]] + # @return [Array<Symbol>] def allowed_actions ([:execute] + actions.children.map { |action| action.name.to_sym }).uniq end + # Get the primary allowed action + # + # @return [Symbol] def primary_allowed_action (actions[:execute] || :execute).to_sym end + # Set the primary allowed action + # + # This must be one of :prev, :next, :complete or :execute + # + # @param [#to_sym] a the primary allowed action def primary_allowed_action=(a) - if a && ![:prev, :next, :complete, :execute].include?(a.to_sym) + a = a.to_sym + if a && ![:prev, :next, :complete, :execute].include?(a) raise ArgumentError, "Invalid Action (#{a}), use: #{[:prev, :next, :complete, :execute]*' '}" end actions[:execute] = a end