Sha256: 14123df4858bb7466e7577b3a82bbcc1a8f6211c8a5ba07b2ab31ac1975ed4e0

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__))

require 'polyglot'
require 'treetop'
require 'command_line'

module SSH ; module Allow
  class Command
    attr_reader :name, :options, :arguments

    def initialize(cmd)
      @cmd = cmd.to_s
      @name = parsed.name.text_value
      @options = parsed.option_list
      @arguments = parsed.argument_list
    end

    def to_s
      @cmd
    end

    def run
      system(@cmd)
    end

    def allowed?(rules)
      match, allow = false, false
      rules.each do |rule|
        match, allow = rule.match?(self)
        break if match
      end
      allow
    end

    private

    def parsed
      @parsed ||= CommandLineParser.new.parse(@cmd)
    end
  end
end ; end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ssh-allow-0.6.0 lib/ssh/allow/command.rb