From 07a17b442d7d7a397d076babfaa29fd2620921d7 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Thu, 19 Jan 2017 10:54:32 +0000 Subject: Initial commit --- lib/host.rb | 19 +++++++++++++++++++ lib/hosts.rb | 22 ++++++++++++++++++++++ lib/sshconfig.rb | 13 +++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/host.rb create mode 100644 lib/hosts.rb create mode 100644 lib/sshconfig.rb (limited to 'lib') diff --git a/lib/host.rb b/lib/host.rb new file mode 100644 index 0000000..90c3e2e --- /dev/null +++ b/lib/host.rb @@ -0,0 +1,19 @@ +module SSHConfig + class Host + def initialize(name, &block) + @name = name + @directives = {} + self.instance_eval(&block) + end + + def method_missing(meth, arg) + @directives[meth.capitalize] = arg + end + + def to_s + "Host #{@name}\n" + + @directives.map { |k, v| "\t#{k} #{v}" }.join("\n") + + "\n" + end + end +end diff --git a/lib/hosts.rb b/lib/hosts.rb new file mode 100644 index 0000000..1a0fc27 --- /dev/null +++ b/lib/hosts.rb @@ -0,0 +1,22 @@ +module SSHConfig + class Hosts + attr_reader :hosts + + def initialize(&block) + @hosts = [] + self.instance_eval(&block) + end + + def merge(morehosts) + @hosts += morehosts.hosts + end + + def host(name) + @hosts << Host.new(name, &Proc.new) + end + + def to_s + @hosts.map(&:to_s).join("\n") + end + end +end diff --git a/lib/sshconfig.rb b/lib/sshconfig.rb new file mode 100644 index 0000000..204a127 --- /dev/null +++ b/lib/sshconfig.rb @@ -0,0 +1,13 @@ +require 'host' +require 'hosts' + +module SSHConfig + YES = "yes" + NO = "no" + + $hostlist = Hosts.new{} + + def hosts + $hostlist.merge(Hosts.new(&Proc.new)) + end +end -- cgit v1.2.3