Sha256: d7522d5cf467192ecc532f0c35bcdaaf1ab553d55d94aafa9b16bf2b8df27d70

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module OodAppkit
  # A class used to handle URLs for the system Shell app.
  class ShellUrl
    # The title for this URL
    # @return [String] the title of the URL
    attr_reader :title

    # @param title [String] the title of the URL
    # @param base_url [String] the base URL used to access this app
    # @param template [String] the template used to generate URLs for this app
    # @see https://www.rfc-editor.org/rfc/rfc6570.txt RFC describing template format
    def initialize(title: '', base_url: '/', ssh_url: '/ssh', template: '{/url*}/{host}{+path}')
      @title = title
      @template = Addressable::Template.new template

      # Break up into arrays of strings
      @base_url = base_url.split('/').reject(&:empty?)
      @ssh_url  = ssh_url.split('/').reject(&:empty?)
    end

    # URL to access this app for a given host and absolute file path
    # @param host [String] the host the app will make an ssh connection with
    # @param path [#to_s] the absolute path to the directory ssh app opens up in
    # @return [Addressable::URI] the url used to access the app
    def url(host: 'default', path: '')
      @template.expand url: @base_url + @ssh_url, host: host, path: path.to_s
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ood_appkit-0.2.6 lib/ood_appkit/shell_url.rb
ood_appkit-0.2.5 lib/ood_appkit/shell_url.rb