Class: OodAppkit::Urls::Files

Inherits:
OodAppkit::Url show all
Defined in:
lib/ood_appkit/urls/files.rb

Overview

A class used to handle URLs for the system Files app.

Instance Attribute Summary

Attributes inherited from OodAppkit::Url

#title

Instance Method Summary collapse

Constructor Details

#initialize(fs_url: '', api_url: '/api/v1', template: '{/url*}{/fs}{+path}', **kwargs) ⇒ Files

Returns a new instance of Files.

Parameters:

  • fs_url (#to_s) (defaults to: '')

    the URL used to request a filesystem view in the app

  • api_url (#to_s) (defaults to: '/api/v1')

    the URL used to request the app’s api

  • title (#to_s)

    the title of the URL

  • base_url (#to_s)

    the base URL used to access this app

  • template (#to_s) (defaults to: '{/url*}{/fs}{+path}')

    the template used to generate URLs for this app



8
9
10
11
12
# File 'lib/ood_appkit/urls/files.rb', line 8

def initialize(fs_url: '', api_url: '/api/v1', template: '{/url*}{/fs}{+path}', **kwargs)
  super(template: template, **kwargs)
  @fs_url  = parse_url_segments(fs_url.to_s)
  @api_url = parse_url_segments(api_url.to_s)
end

Instance Method Details

#api(opts = {}) ⇒ Addressable::URI

URL to access this app’s API for a given absolute file path

Parameters:

  • opts (#to_h) (defaults to: {})

    the available options for this method

Options Hash (opts):

  • :path (#to_s, nil) — default: ""

    The absolute path to the file on the filesystem

  • :fs (#to_s, nil) — default: ""

    The filesystem for the path

Returns:

  • (Addressable::URI)

    absolute url to access path in files app api



34
35
36
37
38
39
40
# File 'lib/ood_appkit/urls/files.rb', line 34

def api(opts = {})
  opts = opts.to_h.compact.symbolize_keys

  path = opts.fetch(:path, "").to_s
  fs = opts.fetch(:fs, "fs").to_s
  @template.expand url: @base_url + @api_url, fs: fs, path: path
end

#url(opts = {}) ⇒ Addressable::URI

URL to access this app for a given absolute file path

Parameters:

  • opts (#to_h) (defaults to: {})

    the available options for this method

Options Hash (opts):

  • :path (#to_s, nil) — default: ""

    The absolute path to the file on the filesystem

  • :fs (#to_s, nil) — default: ""

    The filesystem for the path

Returns:

  • (Addressable::URI)

    absolute url to access path in file app



20
21
22
23
24
25
26
# File 'lib/ood_appkit/urls/files.rb', line 20

def url(opts = {})
  opts = opts.to_h.compact.symbolize_keys

  path = opts.fetch(:path, "").to_s
  fs = opts.fetch(:fs, "fs").to_s
  @template.expand url: @base_url + @fs_url, fs: fs, path: path
end