Sha256: 5a42e8f2df481a3008fa71415e592fec6ba840056b547a29d6bb274173d91b01

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

module Larynx
  class Command
    include Callbacks
    attr_reader :command

    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
  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

2 entries across 2 versions & 1 rubygems

Version Path
larynx-0.1.1 lib/larynx/command.rb
larynx-0.1.0 lib/larynx/command.rb