Sha256: 9f5a67afba86f75550ffe3c5c46f0b4f74d3d1e30afc4932dcc489bd8ea4ec6a

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

module Larynx
  class Command
    include Callbacks
    attr_reader :command
    attr_accessor :interrupted

    define_callback :before, :after

    def initialize(command, params=nil, &block)
      @command, @params, @callbacks = command, params, {}
      after(&block) if block_given?
    end

    def to_s
      @command
    end

    def name
      @command
    end

    def interruptable?
      false
    end

    def interrupted?
      @interrupted
    end

    def setup
      fire_callback :before
    end

    def finalize
      fire_callback :after
    end
  end

  class CallCommand < Command
    def name
      "#{@command}#{" #{@params}" if @params}"
    end

    def to_s
      cmd =  "#{@command}"
      cmd << " #{@params}" if @params
      cmd << "\n\n"
    end
  end

  class ApiCommand < Command
    def name
      "#{@command}#{" #{@params}" if @params}"
    end

    def to_s
      cmd =  "api #{@command}"
      cmd << " #{@params}" if @params
      cmd << "\n\n"
    end
  end

  class AppCommand < Command
    def initialize(command, params=nil, options={}, &block)
      super command, params, &block
      @options = options.reverse_merge(:bargein => true)
    end

    def name
      "#{@command}#{" '#{@params}'" if @params}"
    end

    def to_s
      cmd =  "sendmsg\n"
      cmd << "call-command: execute\n"
      cmd << "execute-app-name: #{@command}\n"
      cmd << "execute-app-arg: #{@params}\n" if @params
      cmd << "event-lock: #{@options[:lock]}\n" if @options[:lock]
      cmd << "\n"
    end

    def interruptable?
      @options[:bargein]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
larynx-0.1.6 lib/larynx/command.rb
larynx-0.1.5 lib/larynx/command.rb
larynx-0.1.4 lib/larynx/command.rb
larynx-0.1.3 lib/larynx/command.rb