Sha256: 04c03fe7fa5d739fb50d0a8d57732774a65ebd98b2eaa36ac22b3584033ece4e

Contents?: true

Size: 934 Bytes

Versions: 5

Compression:

Stored size: 934 Bytes

Contents

require 'ec2ssh/exceptions'

module Ec2ssh
  class Dsl
    attr_reader :_result

    def initialize
      @_result = Container.new
    end

    def aws_keys(keys)
      @_result.aws_keys = keys
    end

    def regions(*regions)
      @_result.regions = regions
    end

    def host_line(erb)
      @_result.host_line = erb
    end

    def reject(&block)
      @_result.reject = block
    end

    def path(str)
      @_result.path = str
    end

    class Container < Struct.new(*%i[
      aws_keys
      regions
      host_line
      reject
      path
    ])
    end

    module Parser
      def self.parse(dsl_str)
        dsl = Dsl.new
        dsl.instance_eval dsl_str
        dsl._result
      rescue SyntaxError => e
        raise DotfileSyntaxError, e.to_s
      end

      def self.parse_file(path)
        raise DotfileNotFound, path.to_s unless File.exist?(path)
        parse File.read(path)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ec2ssh-3.0.3 lib/ec2ssh/dsl.rb
ec2ssh-3.0.2 lib/ec2ssh/dsl.rb
ec2ssh-3.0.1 lib/ec2ssh/dsl.rb
ec2ssh-3.0.0 lib/ec2ssh/dsl.rb
ec2ssh-3.0.0.beta1 lib/ec2ssh/dsl.rb